reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
oly 2020-03-25T11:52:29.001300Z

hi, can anyone tell me how you do optionals {:parameters {:query {:param1 pos-int?}}}

oly 2020-03-25T11:53:39.002500Z

been searching the docs but struggling to find an example, I am using swagger-ui and spec, i have defined all my params but if i submit from swagger with no values they all fail

ikitommi 2020-03-25T11:54:10.003500Z

{:parameters {:query {(ds/opt :param1) pos-int?}}}

oly 2020-03-25T11:54:19.003700Z

I was trying something like (s/or :int pos-int? :blank nil?) but that failed

ikitommi 2020-03-25T11:54:58.004800Z

(require '[spec-tools.data-spec :as ds])
that is.

oly 2020-03-25T11:55:06.005100Z

oh cheers, thanks for that will go look up ds/opt

oly 2020-03-25T11:55:17.005600Z

okay great will give it a try 🙂

ikitommi 2020-03-25T11:55:53.006100Z

or you can just use normal spec:

{:parameters {:query (s/keys :opt-un [::params1])}} 

oly 2020-03-25T11:56:56.006500Z

I was trying something like that, but struggled with namespacing

oly 2020-03-25T11:57:44.007400Z

basically ended up creating :request/type and :response/type to avoid conflicts

oly 2020-03-25T11:58:13.008Z

but then the api picks up the request part of the spec which i don't want

oly 2020-03-25T11:58:31.008500Z

mainly because I am trying to maintain compatibility with an older api

oly 2020-03-25T11:59:23.009200Z

if I used just ::type it would not work because the request and response values differ

oly 2020-03-25T12:02:03.009600Z

looking at it data-specs may solve this any way

oly 2020-03-25T12:31:08.010200Z

anyway the data spec thing worked a treat @ikitommi thanks again 🙂

1