ring-swagger

ring-swagger & compojure-api
ikitommi 2017-10-18T07:21:20.000156Z

one could ask (methods multimethod) to verify that when app is created, all things are bound. But still, configuration via multimethods is imperative, opposed of purely functional transformation of a single (admittedly, huge) configuration map. I think data is the way to go at the lowest level anyway, there could be helpers on top. Let’s draft something and see how they look like

slipset 2017-10-18T07:48:09.000032Z

totally agree on the approach of huge config-map with helpers on top.

slipset 2017-10-18T08:26:40.000282Z

@ikitommi hate to bother you more, but there is one thing I cannot figure out:

slipset 2017-10-18T08:26:47.000210Z

Given the code https://gist.github.com/slipset/016b6f4ebb10fea8e596221ed638302d

slipset 2017-10-18T08:27:18.000074Z

Whenever I POST an invalid date here, I get an error from Muuntaja.

slipset 2017-10-18T08:27:35.000185Z

I'm quite certain that this is on the request coercion.

slipset 2017-10-18T08:28:19.000139Z

I would have expected this to give me a spec error.

slipset 2017-10-18T08:28:38.000361Z

I can reproduce this on outbound as well:

ikitommi 2017-10-18T08:29:00.000372Z

I'll check that out after lunch.

slipset 2017-10-18T08:29:14.000080Z

appreciated.

slipset 2017-10-18T08:29:46.000474Z

Enjoy the mustamakkara πŸ™‚

ikitommi 2017-10-18T11:19:35.000114Z

@slipset if the spec-coercion fails, the result fails to serialize. Root cause is that we are returning the Spec :problems over the wire and the :pred can be anything - here it’s (partial instance? DateTime) which fails to serialize. Wrapping the :pred to str should make the errors correct. Here, it would be:

{:spec "(spec-tools.core/spec {:spec (clojure.spec.alpha/keys :req-un [:compojure.api.coercion.erik/id :compojure.api.coercion.erik/name :compojure.api.coercion.erik/date]), :type :map, :keys #{:date :name :id}, :keys/req #{:date :name :id}})",
 :problems [{:path ["date"],
             :pred "(clojure.core/partial clojure.core/instance? org.joda.time.DateTime)",
             :val "lol",
             :via ["compojure.api.coercion.erik/id-name-date" "compojure.api.coercion.erik/date"],
             :in ["date"],
             :reason "FAIL"}],
 :type "compojure.api.exception/response-validation",
 :coercion "spec",
 :value {:id 1, :name "foo", :date "lol"},
 :in ["response" "body"]}

ikitommi 2017-10-18T11:19:52.000231Z

will push a fix soon.

2πŸŽ‰
slipset 2017-10-18T11:26:58.000263Z

Nice!

slipset 2017-10-18T11:27:12.000285Z

I'm just happy it wasn't my fault πŸ™‚

ikitommi 2017-10-18T17:54:29.000104Z

@slipset japanese πŸ˜‰ fix now in [metosin/compojure-api "2.0.0-alpha9"]. Also, keyword specs are not memoized in coercion, should remove odd behavior if specs are redefined in dev.

slipset 2017-10-18T18:43:37.000115Z

Thanks alot. Will check out tomorrow.