Fork me on GitHub
#ring-swagger
<
2017-12-05
>
petr.mensik14:12:30

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?

ikitommi14:12:57

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

petr.mensik14:12:37

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

petr.mensik14:12:49

complains that key is not defined in the schema

petr.mensik14:12:01

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

ikitommi14:12:51

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

ikitommi14:12:26

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

ikitommi14:12:26

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

petr.mensik14:12:57

And that applies to any number of key/vals?

ikitommi14:12:19

yes, "any keys and any values"

petr.mensik14:12:36

cool, thank you!

ikitommi14:12:44

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.