From 60b4231e0db4cfabf08acf9cea758a0bd60d63dc Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Wed, 30 Aug 2023 09:21:55 +0300 Subject: [PATCH] fix: don't add extra `:schema nil` to swagger :parameters --- src/malli/swagger.cljc | 4 +++- test/malli/swagger_test.cljc | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/malli/swagger.cljc b/src/malli/swagger.cljc index dd53d4666..62a41bee4 100644 --- a/src/malli/swagger.cljc +++ b/src/malli/swagger.cljc @@ -130,7 +130,9 @@ (cond-> x parameters (update :parameters #(mapv (fn [p] - (update p :schema dissoc :definitions)) + (if (contains? p :schema) + (update p :schema dissoc :definitions) + p)) %)) responses (update :responses #(reduce-kv (fn [rs k v] diff --git a/test/malli/swagger_test.cljc b/test/malli/swagger_test.cljc index ae072787a..6d8312b55 100644 --- a/test/malli/swagger_test.cljc +++ b/test/malli/swagger_test.cljc @@ -285,12 +285,29 @@ :name "body" :required true :schema {:properties {:foo {:type "string"}} - :required [:foo], :type "object"}}] + :required [:foo] :type "object"}} + {:description "" + :in "query" + :name :a + :required true + :type "string"} + {:description "" + :in "query" + :name :b + :required true + :type "string"} + {:description "" + :in "header" + :name :c + :required true + :type "string"}] :responses {200 {:description "" :schema {:properties {:bar {:type "string"}} :required [:bar], :type "object"}}}} (swagger/swagger-spec {::swagger/parameters - {:body [:map [:foo :string]]} + {:body [:map [:foo :string]] + :query [:map [:a :string] [:b :string]] + :header [:map [:c :string]]} ::swagger/responses {200 {:schema [:map [:bar :keyword]]}}})))) (testing "generates swagger for ::parameters w/ basic schema + registry"