Fork me on GitHub
#ring-swagger
<
2021-04-14
>
Sam Gabriel20:04:03

Hello. I'm using reitit.swagger-ui with Clojure Spec. When I use (s/def ::bbox (s/* float?)) as spec for query parameter, Swagger UI lets me enter an array of numbers (e.g. [1, 2, 3, 4]), but the request fails because predicate for sequence "pred": "(clojure.core/fn [%] (clojure.core/or (clojure.core/nil? %) (clojure.core/sequential? %)))" doesn't match the string val that Swagger UI creates for the request, "val": "1,2,3,4". Is there any way to get this to work?

Sam Gabriel23:04:45

In case anyone else has this same question/problem, I found a not-yet-merged PR <https://github.com/metosin/reitit/pull/481> that provided me with enough information to solve this. Using [spec-tools.core :as st], you can set properties in the clojure core spec for the query parameter so that properties in the corresponding query string parameter in swagger.json will be set properly. There are two ways to do this: allow query parameter repetition and match that against a sequence spec, or allow a query parameter csv array and match that against a string. Here are clojure spec definitions for a uuid list parameter using these two approaches, respectively: (s/def ::uuid (st/spec {:spec (s/* string?) :swagger/collectionFormat "multi"})) (s/def ::uuid (st/spec {:spec string? :swagger/type "array" :swagger/items {:type "string"} :swagger/collectionFormat "csv"}))

3
Sam Gabriel23:04:45

In case anyone else has this same question/problem, I found a not-yet-merged PR <https://github.com/metosin/reitit/pull/481> that provided me with enough information to solve this. Using [spec-tools.core :as st], you can set properties in the clojure core spec for the query parameter so that properties in the corresponding query string parameter in swagger.json will be set properly. There are two ways to do this: allow query parameter repetition and match that against a sequence spec, or allow a query parameter csv array and match that against a string. Here are clojure spec definitions for a uuid list parameter using these two approaches, respectively: (s/def ::uuid (st/spec {:spec (s/* string?) :swagger/collectionFormat "multi"})) (s/def ::uuid (st/spec {:spec string? :swagger/type "array" :swagger/items {:type "string"} :swagger/collectionFormat "csv"}))

3