This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-06
Channels
- # announcements (1)
- # babashka (7)
- # beginners (93)
- # bristol-clojurians (1)
- # cider (7)
- # clj-kondo (42)
- # cljs-dev (9)
- # clojure (67)
- # clojure-europe (4)
- # clojure-france (4)
- # clojure-germany (2)
- # clojure-italy (3)
- # clojure-nl (10)
- # clojure-uk (62)
- # clojurescript (11)
- # clojurex (3)
- # conjure (77)
- # cursive (16)
- # datomic (105)
- # docker (4)
- # editors (3)
- # events (5)
- # fulcro (34)
- # jobs (1)
- # juxt (7)
- # kaocha (7)
- # lambdaisland (3)
- # lein-figwheel (2)
- # leiningen (19)
- # malli (14)
- # meander (6)
- # mid-cities-meetup (6)
- # off-topic (20)
- # pedestal (2)
- # reagent (17)
- # reitit (7)
- # remote-jobs (1)
- # shadow-cljs (17)
- # spacemacs (23)
- # specter (2)
- # tools-deps (34)
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?It’s just an example the reason not in typo, unfortunately.
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.