mirror of
https://github.com/metosin/reitit.git
synced 2026-01-17 19:59:01 +00:00
feat: warning when swagger encounters per-content-type coercions
This commit is contained in:
parent
ae55b6628c
commit
8c87fef7b6
2 changed files with 43 additions and 9 deletions
|
|
@ -167,6 +167,12 @@
|
||||||
;; api-docs
|
;; api-docs
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
(defn -warn-unsupported-coercions [{:keys [parameters responses] :as data}]
|
||||||
|
(when (:request parameters)
|
||||||
|
(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")))
|
||||||
|
|
||||||
(defn get-apidocs [coercion specification data]
|
(defn get-apidocs [coercion specification data]
|
||||||
(let [swagger-parameter {:query :query
|
(let [swagger-parameter {:query :query
|
||||||
:body :body
|
:body :body
|
||||||
|
|
@ -176,15 +182,17 @@
|
||||||
:multipart :formData}]
|
:multipart :formData}]
|
||||||
(case specification
|
(case specification
|
||||||
:openapi (-get-apidocs coercion specification data)
|
:openapi (-get-apidocs coercion specification data)
|
||||||
:swagger (->> (update
|
:swagger (do
|
||||||
data
|
(-warn-unsupported-coercions data)
|
||||||
:parameters
|
(->> (update
|
||||||
(fn [parameters]
|
data
|
||||||
(->> parameters
|
:parameters
|
||||||
(map (fn [[k v]] [(swagger-parameter k) v]))
|
(fn [parameters]
|
||||||
(filter first)
|
(->> parameters
|
||||||
(into {}))))
|
(map (fn [[k v]] [(swagger-parameter k) v]))
|
||||||
(-get-apidocs coercion specification)))))
|
(filter first)
|
||||||
|
(into {}))))
|
||||||
|
(-get-apidocs coercion specification))))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -384,3 +384,29 @@
|
||||||
spec (:body (app {:request-method :get, :uri "/swagger.json"}))]
|
spec (:body (app {:request-method :get, :uri "/swagger.json"}))]
|
||||||
(is (= ["query" "body" "formData" "header" "path"]
|
(is (= ["query" "body" "formData" "header" "path"]
|
||||||
(map :in (get-in spec [:paths "/parameters" :post :parameters]))))))
|
(map :in (get-in spec [:paths "/parameters" :post :parameters]))))))
|
||||||
|
|
||||||
|
(deftest multiple-content-types-test
|
||||||
|
(testing ":request coercion"
|
||||||
|
(let [app (ring/ring-handler
|
||||||
|
(ring/router
|
||||||
|
[["/parameters"
|
||||||
|
{:post {:coercion spec/coercion
|
||||||
|
:parameters {:request {:content {"application/json" {:x string?}}}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/swagger.json"
|
||||||
|
{:get {:no-doc true
|
||||||
|
:handler (swagger/create-swagger-handler)}}]]))
|
||||||
|
output (with-out-str (app {:request-method :get, :uri "/swagger.json"}))]
|
||||||
|
(is (.contains output "WARN"))))
|
||||||
|
(testing "multiple response content types"
|
||||||
|
(let [app (ring/ring-handler
|
||||||
|
(ring/router
|
||||||
|
[["/parameters"
|
||||||
|
{:post {:coercion spec/coercion
|
||||||
|
:responses {200 {:content {"application/json" {:r string?}}}}
|
||||||
|
:handler identity}}]
|
||||||
|
["/swagger.json"
|
||||||
|
{:get {:no-doc true
|
||||||
|
:handler (swagger/create-swagger-handler)}}]]))
|
||||||
|
output (with-out-str (app {:request-method :get, :uri "/swagger.json"}))]
|
||||||
|
(is (.contains output "WARN")))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue