Fork me on GitHub
#reitit
<
2020-02-10
>
ikitommi10:02:37

will try to check open prs this week.

parrot 4
g7s09:02:33

Is there a way to define coercion on optional query parameters? For example I have a url of the form and I want the page and per-page to be optional. Right now doing

g7s09:02:22

:parameters {:query {:page ::search/page
                     :per-page ::search/per-page}}

g7s09:02:53

will generate a spec with req-un which will complain if the keys are not provided

g7s09:02:39

btw I am using clojure.spec coercion

g7s09:02:38

So I ended up defining a spec

(s/def ::list-params (s/keys :opt-un [::search/page
                                      ::search/per-page]))
and then I did
:parameters {:query ::list-params}
and it worked fine đŸ™‚

đŸ’¯ 4
ikitommi10:02:35

this would work also:

:parameters {:query {(ds/opt :page) ::search/page
                     (ds/opt :per-page) ::search/per-page}}

ikitommi10:02:30

problem with too simple syntax is that it gets easily complex, when you need to name things, add optional, maybes etc.

ikitommi10:02:33

I fear that spec2 is heading there too.

ikitommi10:02:18

(s/def ::order 
  (s/schema {:purchaser string? 
             :due-date inst?
             :line-items (s/coll-of (s/schema {:item-id pos-int? 
                                               :quantity nat-int?})
                           :kind vector?
                           :min-count 1
                           :gen-max 3)}))

ikitommi10:02:31

inlining should work too:

:parameters {:query (s/keys :opt-un [::search/page ::search/per-page]))}

g7s11:02:27

@ikitommi hey thanks a lot! helpful info

heyarne14:02:09

I opened this PR a while ago and would like to wrap it up: https://github.com/metosin/reitit/pull/350

heyarne14:02:01

Where exactly do I find the relevant docs to edit? (nevermind, I might still be a bit tired for not having seen the doc folder) I've only ever passively used cljdoc.

heyarne14:02:50

Also: When I run lein test I get an exception: Wrong number of args (2) passed to: malli.util/closed-schema - is that something I broke?

wombawomba00:02:26

That test seems to be broken in master

plins20:02:45

Ive looked at the docs but found nothing so I am asking here (and hopefully add something to the docs) is it possible to automatically convert kebab-case specs to camelCase (or whatever) in the swagger docs?