Skip to content

Commit

Permalink
fix: don't generate :definitions nil in swagger
Browse files Browse the repository at this point in the history
It's technically against the swagger spec, and some pedantic consumers
reject it.

Fixes #1134
  • Loading branch information
opqdonut committed Nov 26, 2024
1 parent 711ca00 commit c2e74cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/malli/swagger.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@
parameters (:parameters expanded)
responses (:responses expanded)
definitions (apply merge
(:definitions acc)
(concat
(->> responses vals (map (comp :definitions :schema)))
(->> parameters (map (comp :definitions :schema)))))]
(-> acc (dissoc k) (merge expanded)
(update :definitions merge definitions)
(merge (when-not (empty? definitions) [:definitions definitions]))
dissoc-non-root-definitions))
acc))
x x)
Expand Down
9 changes: 3 additions & 6 deletions test/malli/swagger_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@

(deftest swagger-spec-test
(testing "generates swagger for ::parameters and ::responses w/ basic schema"
(is (= {:definitions nil
:parameters [{:description ""
(is (= {:parameters [{:description ""
:in "body"
:name "body"
:required true
Expand Down Expand Up @@ -439,8 +438,7 @@
{:registry registry})}}})))))

(testing "no schema in responses ignored"
(is (= {:definitions nil
:responses {200 {:description "" :schema {:type "string"}}
(is (= {:responses {200 {:description "" :schema {:type "string"}}
500 {:description "fail"}}}
(swagger/swagger-spec {::swagger/responses
{500 {:description "fail"}
Expand Down Expand Up @@ -518,8 +516,7 @@
::swagger/responses {200 {:schema #'Success}}}))))
(testing "::parameters :query w/ var schema"
;; NB! all refs get inlined!
(is (= {:definitions nil
:parameters [{:description ""
(is (= {:parameters [{:description ""
:in "query"
:name :a
:required true
Expand Down

0 comments on commit c2e74cc

Please sign in to comment.