anybody using compojure-api? I’m having issues with spec validation
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
@mping can you throw in an example spec + data?
I’m trying to narrow it down
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"
}
hey @ikitommi do you have any pointers on this? Something I could investigate
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
No worries, I appreciate your efforts
I'll dive and see if I can spot anything shady
not sure I’m using decode/string
as intended
@ikitommi ^^