Fork me on GitHub
#ring-swagger
<
2019-01-31
>
mping12:01:00

anybody using compojure-api? I’m having issues with spec validation

mping12:01:33

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

ikitommi12:01:01

@mping can you throw in an example spec + data?

mping12:01:43

I’m trying to narrow it down

mping12:01:56

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"
}                                                      

mping15:02:34

hey @ikitommi do you have any pointers on this? Something I could investigate

ikitommi17:02:22

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

mping18:02:08

No worries, I appreciate your efforts

mping18:02:20

I'll dive and see if I can spot anything shady

mping12:01:25

not sure I’m using decode/stringas intended