ring-swagger

ring-swagger & compojure-api
2019-01-31T12:04:00.060Z

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

2019-01-31T12:04:33.060700Z

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

ikitommi 2019-01-31T12:20:01.061100Z

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

2019-01-31T12:22:43.061400Z

I’m trying to narrow it down

2019-01-31T12:23:56.061900Z

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

2019-02-05T15:51:34.084700Z

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

ikitommi 2019-02-05T17:41:22.084900Z

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

2019-02-05T18:07:08.085600Z

No worries, I appreciate your efforts

2019-02-05T18:07:20.085800Z

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

2019-01-31T12:27:25.062400Z

not sure I’m using decode/stringas intended

2019-01-31T12:28:52.062900Z

@ikitommi ^^