ring-swagger

ring-swagger & compojure-api
petr.mensik 2017-12-05T14:19:30.000316Z

Is there a way how to make body optional? I've tried :body [task (s/maybe {})] and :body [{task :- {} nil}] which doesn't compile, so what is the right way?

ikitommi 2017-12-05T14:23:57.000810Z

@petr.mensik the first one looks right. Are you sure it doens't work?

petr.mensik 2017-12-05T14:25:37.000001Z

yep, body is optional however validation fails if you pass for instance {"name" : "abc"}

petr.mensik 2017-12-05T14:25:49.000156Z

complains that key is not defined in the schema

petr.mensik 2017-12-05T14:26:01.000044Z

and I want to accept either nothing or any kind of map

ikitommi 2017-12-05T14:29:51.000188Z

Ah, it's (s/maybe {s/Any s/Any}) then.

ikitommi 2017-12-05T14:30:26.000061Z

Maps are closed by default on Schema (and open on Spec)

ikitommi 2017-12-05T14:31:26.000370Z

there is a also a helper spec-tools/open-schema which makes the map-schemas open recursively.

petr.mensik 2017-12-05T14:31:57.000040Z

And that applies to any number of key/vals?

ikitommi 2017-12-05T14:32:19.000348Z

yes, "any keys and any values"

petr.mensik 2017-12-05T14:32:36.000784Z

cool, thank you!

ikitommi 2017-12-05T14:33:44.000142Z

In Schema, you can have 0-1 special keys on maps, {:a s/Int, s/Str s/Any} would allow :a and any string-keys.

ikitommi 2017-12-05T14:33:48.000624Z

np.