Merge pull request #404 from piotr-yuxuan/master

[0.5.1] Ass default :responses for Swagger-UI
This commit is contained in:
Tommi Reiman 2020-05-26 21:33:18 +03:00 committed by GitHub
commit 4e9537cecf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View file

@ -82,12 +82,14 @@
:x-id ids})) :x-id ids}))
accept-route (fn [route] accept-route (fn [route]
(-> route second :swagger :id (or ::default) (trie/into-set) (set/intersection ids) seq)) (-> route second :swagger :id (or ::default) (trie/into-set) (set/intersection ids) seq))
base-swagger-spec {:responses ^:displace {:default {:description ""}}}
transform-endpoint (fn [[method {{:keys [coercion no-doc swagger] :as data} :data transform-endpoint (fn [[method {{:keys [coercion no-doc swagger] :as data} :data
middleware :middleware middleware :middleware
interceptors :interceptors}]] interceptors :interceptors}]]
(if (and data (not no-doc)) (if (and data (not no-doc))
[method [method
(meta-merge (meta-merge
base-swagger-spec
(apply meta-merge (keep (comp :swagger :data) middleware)) (apply meta-merge (keep (comp :swagger :data) middleware))
(apply meta-merge (keep (comp :swagger :data) interceptors)) (apply meta-merge (keep (comp :swagger :data) interceptors))
(if coercion (if coercion

View file

@ -25,7 +25,9 @@
["/spec" {:coercion spec/coercion} ["/spec" {:coercion spec/coercion}
["/plus/:z" ["/plus/:z"
{:get {:summary "plus" {:patch {:summary "patch"
:handler (constantly {:status 200})}
:get {:summary "plus"
:parameters {:query {:x int?, :y int?} :parameters {:query {:x int?, :y int?}
:path {:z int?}} :path {:z int?}}
:swagger {:responses {400 {:schema {:type "string"} :swagger {:responses {400 {:schema {:type "string"}
@ -120,7 +122,10 @@
expected {:x-id #{::math} expected {:x-id #{::math}
:swagger "2.0" :swagger "2.0"
:info {:title "my-api"} :info {:title "my-api"}
:paths {"/api/spec/plus/{z}" {:get {:parameters [{:in "query" :paths {"/api/spec/plus/{z}" {:patch {:parameters []
:summary "patch"
:responses {:default {:description ""}}}
:get {:parameters [{:in "query"
:name "x" :name "x"
:description "" :description ""
:required true :required true
@ -312,7 +317,7 @@
(is (= ["/common/ping" "/one/ping" "/two/ping" "/two/deep/ping"] (is (= ["/common/ping" "/one/ping" "/two/ping" "/two/deep/ping"]
(spec-paths app "/one-two/swagger.json"))))) (spec-paths app "/one-two/swagger.json")))))
(deftest swagger-ui-congif-test (deftest swagger-ui-config-test
(let [app (swagger-ui/create-swagger-ui-handler (let [app (swagger-ui/create-swagger-ui-handler
{:path "/" {:path "/"
:config {:jsonEditor true}})] :config {:jsonEditor true}})]