reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
marrs 2020-03-16T18:33:46.068Z

Hi folks. Can anyone point me in the direction of defining a schema for a JSON body that has optional properties?

ikitommi 2020-03-16T20:11:19.069700Z

@d.marrs what coercion are you using? Schema, spec, data-spec or malli? All have different ways in doing that

marrs 2020-03-16T21:34:04.071200Z

@ikitommi schema. I've defined the params like so:

:parameters {
                  :body {
                    :a s/Str
                    :b s/Str
                    :c s/Str
                    :d s/Str
                    :e s/Bool
                  }}
I get a 400 error: `
"(not (map? nil))"

ikitommi 2020-03-16T21:59:41.074500Z

if you want to allow nil body, you should wrap the body in s/maybe. For optional props, use s/optional-key, e.g. (s/maybe {:a s/Str, (s/optional-key :b) s/Str})