Skip to content

Commit

Permalink
fix: remove unsupported coercions when generating swagger
Browse files Browse the repository at this point in the history
If we don't remove them, :responses :content gets passed out verbatim
in the swagger.json, breaking stuff.

In particular, fixes the swagger.json in
examples/reitit-malli-swagger. Reported broken in #669.
  • Loading branch information
opqdonut committed Apr 19, 2024
1 parent fbec1e2 commit 4420c8a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions modules/reitit-swagger/src/reitit/swagger.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,25 @@
(defn- swagger-path [path opts]
(-> path (trie/normalize opts) (str/replace #"\{\*" "{")))

(defn -warn-unsupported-coercions [{:keys [request responses] :as _data}]
(defn -remove-unsupported-coercions [{:keys [request responses] :as data}]
(when request
(println "WARNING [reitit.coercion]: swagger apidocs don't support :request coercion"))
(when (some :content (vals responses))
(println "WARNING [reitit.coercion]: swagger apidocs don't support :responses :content coercion")))
(println "WARNING [reitit.coercion]: swagger apidocs don't support :responses :content coercion"))
(-> data
(dissoc :request)
(update :responses update-vals #(dissoc % :content))))

(defn -get-swagger-apidocs [coercion data]
(let [swagger-parameter {:query :query
:body :body
:form :formData
:header :header
:path :path
:multipart :formData}]
(-warn-unsupported-coercions data)
:multipart :formData}
cleaned (-remove-unsupported-coercions data)]
(->> (update
data
cleaned
:parameters
(fn [parameters]
(->> parameters
Expand Down

0 comments on commit 4420c8a

Please sign in to comment.