This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-01-31
Channels
- # aws (1)
- # beginners (70)
- # boot (12)
- # calva (45)
- # cider (45)
- # clara (1)
- # cljdoc (10)
- # cljs-dev (133)
- # clojure (315)
- # clojure-dev (2)
- # clojure-europe (2)
- # clojure-italy (16)
- # clojure-nl (1)
- # clojure-spec (23)
- # clojure-uk (19)
- # clojurescript (48)
- # cursive (11)
- # data-science (5)
- # datomic (18)
- # figwheel-main (3)
- # fulcro (18)
- # graphql (14)
- # jackdaw (1)
- # juxt (1)
- # kaocha (1)
- # off-topic (10)
- # other-languages (3)
- # pathom (2)
- # pedestal (7)
- # re-frame (23)
- # reagent (1)
- # reitit (4)
- # ring-swagger (12)
- # rum (4)
- # shadow-cljs (26)
- # specter (6)
- # speculative (12)
- # tools-deps (44)
- # vim (8)
- # yada (2)
I’m validating a map, if some of the root keys are invalid, the coercion will fail for the rest of the keys and I get lots of errors instead of just one
I’m coercing strings to local dates
(s/def ::local-date
(st/spec
{:spec (s/with-gen #(instance? LocalDate %)
#(s/gen #{(coerce/to-local-date "2019-04-10")}))
:type :local-date
:reason "invalidDate"
:decode/json keyword->local-date
:encode/json local-date->date-time
:decode/string keyword->local-date
:encode/string local-date->date-time
:swagger/type "full-date"
:json-schema/default (now-str)}))
(s/def ::start-date ::local-date)
(s/def ::body (st/spec {:reason "invalidBody"
:spec (s/and (s/keys :req-un [::pick-depot
::start-date]))}))
handler:
(POST "/" [] :body [body ::body] (ok body)
json (notice the typo):
{
"pick-depoxt": "lisbon",
"start-date": "2019-01-31"
}
I would try to run the coercion directly with spec-tools to isolate all c-api things. There is st/decode
(runs both coerce and conform), st/coerce
(best-effort coercion with form walking) and st/conform
coercion via conforming. Sorry, really busy with a client project, hopefully time on Friday to help with all the piled issues. Ping @mping
Here's the c-api code for it https://github.com/metosin/compojure-api/blob/master/src/compojure/api/coercion/spec.clj#L120-L135