weavejester / compojure

A concise routing library for Ring/Clojure
Eclipse Public License 1.0
4.08k stars 259 forks source link

Can't get Swagger UI to provide input for unassigned/dynamic query parameters #204

Closed aneilbaboo closed 2 years ago

aneilbaboo commented 2 years ago

I have the following schema for which I want to receive dynamic query parameters. Does anyone know how to do this?

E.g., /api/find?x=1&y=2&z=3 and receive a map in fields {:x 1, :y 2, :3}

(ns myns (:require [schema.core :as scm]))

(def myapp
   (api ...
       (GET "/find" [& fields]
                  :return scm/Any
           (ok fields))

This works:

 curl 'localhost:8080/api/runs/find?a=1&b=2'
{"a":"1","b":"2"}%     

But the Swagger UI does not provide a way to input query parameters: image

I've tried many variants of the route, providing

:query [fields scm/Any]

And other things.

If I use a schema that starts with schema.core/maybe...

(scm/defschema QueryArgs (scm/maybe (scm/cond-pre scm/Num scm/Str scm/Bool scm/Keyword scm/Uuid)))

and provide this to :query...

  (GET "/find" [& fields]
         :return scm/Any
         :query [fields QueryArgs]
      (ok))

Swagger at least shows a box that allows me to assign several values inside another parameter, but it's not the one I want: image

It produces a URL like this:

curl -X GET --header 'Accept: application/json' 'http://localhost:8080/api/runs/find?schemas=a%3D1&schemas=b%3D2'

But I want

curl -X GET --header 'Accept: application/json' 'http://localhost:8080/api/runs/find?a=1&b=2'

Please help!

weavejester commented 2 years ago

I think you have the wrong project. You want Compojure-API.

aneilbaboo commented 2 years ago

Sorry!