Fork me on GitHub
#reitit
<
2020-03-16
>
marrs18:03:46

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

ikitommi20:03:19

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

marrs21:03:04

@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))"

ikitommi21:03:41

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