Fork me on GitHub
#reitit
<
2018-07-14
>
valerauko06:07:26

if i write params like,

valerauko06:07:40

:parameters {:body {:name ::user-spec/name
                                :password string?
                                :client-id ::oauth-spec/client-id

valerauko06:07:45

then all the keys will be required

valerauko06:07:59

however, if i def a spec for it and use that,

valerauko06:07:16

parameters {:body ::oauth-spec/exchange-request}

valerauko06:07:28

then the swagger ui will show it like one big hash-map

valerauko06:07:02

i need to do

:parameters {:body (s/keys :req-un [...]
                           :opt-un [...])}
to have the parameters show up individually

valerauko06:07:31

but i'd prefer to have my specs defined in one place (not in the routes definition directly)

valerauko06:07:46

is there a way to accomplish that?

valerauko07:07:57

my current solution is defing it as a map instead of a spec

(def exchange-spec
  {:body (s/merge
           (s/or :code ::exchange-by-code
                 :pass ::exchange-by-auth)
           (s/keys :req-un [::grant-type]
                   :opt-un [::client-id ::client-secret]))})
but this feels a bit hacky

valerauko07:07:50

actually that doesn't work either hmm

valerauko07:07:03

or are body params by default shown in a block like that?

ikitommi08:07:31

@vale swagger-ui shows the body-params as a one json schema by default.

valerauko08:07:41

all right then

valerauko08:07:46

it was confusing

ikitommi08:07:16

you can make the parameters optional in the data-spec syntax with ds/opt

👍 4
ikitommi08:07:47

I think there is a swgger-ui option to show the body as a html form

ikitommi08:07:10

yes, set :jsonEditor to true anf you should see the form (https://github.com/swagger-api/swagger-ui/blob/2.x/README.md)

ikitommi08:07:32

works only with 2.* swagger-ui

ikitommi08:07:29

e.g. :config {:jsonEditor true} to swagger-ui handler options.

ikitommi08:07:45

screenshot welcome if that works

valerauko08:07:08

(create-swagger-ui-handler {:path "/swagger"
                                  :config {:jsonEditor true}})
should it be like that?

ikitommi08:07:45

yes, it should. Doesn't work?

valerauko08:07:31

yeah it doesn't seem to change anything

valerauko08:07:45

lemme try again

ikitommi08:07:39

:( could you write an issue out of that, I can check when near computer. Could be a regression in the swagger-ui project too.

valerauko08:07:07

sure, gonna do that