Fork me on GitHub
#reitit
<
2020-03-25
>
oly11:03:29

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

oly11:03:39

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

ikitommi11:03:10

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

oly11:03:19

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

ikitommi11:03:58

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

oly11:03:06

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

oly11:03:17

okay great will give it a try 🙂

ikitommi11:03:53

or you can just use normal spec:

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

oly11:03:56

I was trying something like that, but struggled with namespacing

oly11:03:44

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

oly11:03:13

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

oly11:03:31

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

oly11:03:23

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

oly12:03:03

looking at it data-specs may solve this any way

oly12:03:08

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

4