Hi guys! Does anyone know how to coerce query param into a record? I have the following spec
(s/def ::my-data
(ds/spec
{:name ::my-data
:spec (s/or :my-data/string (s/and spec/string? (comp (partial = 10) count)))
:my-data/struct my-struct?)
:gen my-data/gen
:decode/json #(str->my-data %2)
:ecnode/json #(my-data->str %2)
:decode/string #(str->my-data %2)
:ecnode/string #(my-data->str %2)}))
When I calling coercion (spec-tools.core/coerce ::my-data spec-tools.core/string-transformer)
or (spec-tools.core/coerce ::my-data spec-tools.core/json-transformer)
it works, but if I call throught router – don’t. reitit.coercion.spec/coercion
added at the top of router declaration.
Any ideas?Sorry, I looked at my code to check `(spec-tools.core/spec …)` and found that it already used.
Solution found: extending base reitit.coercion.spec/default-options
with somethis like this
(def custom-transformer
(st/type-transformer
{:name ::custom-transformer
:decoders {:my-data #(str->my-data %2)}
:encoders (:my-data #(my-data->str %2))}))
PS if replace my spec to int?
or something common – coercing works fine.
there's a typo: ecnode
-> encode
It’s just an example the reason not in typo, unfortunately.