From 7b4127b0f14e942441122d8e7d53b9e76a43922a Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Mon, 28 Aug 2023 10:10:14 +0300 Subject: [PATCH 1/3] fix: examples/http-swagger broken by #628 fixes #634 --- examples/http-swagger/src/example/server.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/http-swagger/src/example/server.clj b/examples/http-swagger/src/example/server.clj index 6b5903d2..9d14ce91 100644 --- a/examples/http-swagger/src/example/server.clj +++ b/examples/http-swagger/src/example/server.clj @@ -77,7 +77,7 @@ {:get {:summary "downloads a file" :swagger {:produces ["image/png"]} :responses {200 {:description "an image" - :content {"image/png" any?}}} + :content {"image/png" {:schema any?}}}} :handler (fn [_] {:status 200 :headers {"Content-Type" "image/png"} From e4c75c73542e8a8de42592e4f645ca3a9ea9a5f3 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Mon, 28 Aug 2023 11:02:31 +0300 Subject: [PATCH 2/3] fix: dissoc unsupported [:responses nnn :content] for swagger otherwise swagger generation crashes when it tries to serialize something like `{:content {"foo/bar" any?}}` also fix examples/ring-malli-swagger --- examples/ring-malli-swagger/src/example/server.clj | 2 +- modules/reitit-malli/src/reitit/coercion/malli.cljc | 1 + modules/reitit-schema/src/reitit/coercion/schema.cljc | 4 +++- modules/reitit-spec/src/reitit/coercion/spec.cljc | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/ring-malli-swagger/src/example/server.clj b/examples/ring-malli-swagger/src/example/server.clj index b2aa10f0..c2dec67f 100644 --- a/examples/ring-malli-swagger/src/example/server.clj +++ b/examples/ring-malli-swagger/src/example/server.clj @@ -61,7 +61,7 @@ {:get {:summary "downloads a file" :swagger {:produces ["image/png"]} :responses {200 {:description "an image" - :content {"image/png" any?}}} + :content {"image/png" {:schema string?}}}} :handler (fn [_] {:status 200 :headers {"Content-Type" "image/png"} diff --git a/modules/reitit-malli/src/reitit/coercion/malli.cljc b/modules/reitit-malli/src/reitit/coercion/malli.cljc index e4f3ab2d..03cf456a 100644 --- a/modules/reitit-malli/src/reitit/coercion/malli.cljc +++ b/modules/reitit-malli/src/reitit/coercion/malli.cljc @@ -259,6 +259,7 @@ (for [[status response] responses] [status (as-> response $ (set/rename-keys $ {:body :schema}) + (dissoc $ :content) (update $ :description (fnil identity "")) (if (:schema $) (update $ :schema swagger/transform {:type :schema}) diff --git a/modules/reitit-schema/src/reitit/coercion/schema.cljc b/modules/reitit-schema/src/reitit/coercion/schema.cljc index e0822ad9..321cd92e 100644 --- a/modules/reitit-schema/src/reitit/coercion/schema.cljc +++ b/modules/reitit-schema/src/reitit/coercion/schema.cljc @@ -60,7 +60,9 @@ (into (empty responses) (for [[k response] responses] - [k (set/rename-keys response {:body :schema})]))}))) + [k (-> response + (dissoc :content) + (set/rename-keys {:body :schema}))]))}))) :openapi (merge (when (seq (dissoc parameters :body :request :multipart)) (openapi/openapi-spec {::openapi/parameters (dissoc parameters :body :request)})) diff --git a/modules/reitit-spec/src/reitit/coercion/spec.cljc b/modules/reitit-spec/src/reitit/coercion/spec.cljc index 98ff9e37..85798f42 100644 --- a/modules/reitit-spec/src/reitit/coercion/spec.cljc +++ b/modules/reitit-spec/src/reitit/coercion/spec.cljc @@ -101,6 +101,7 @@ (empty responses) (for [[k response] responses] [k (as-> response $ + (dissoc $ :content) (set/rename-keys $ {:body :schema}))]))}))) :openapi (merge (when (seq (dissoc parameters :body :request :multipart)) From 55854f6652722d4d2f004409a112a062d66e3134 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Mon, 28 Aug 2023 11:22:42 +0300 Subject: [PATCH 3/3] doc: add openapi response content type to examples/ring-spec-swagger --- examples/ring-spec-swagger/src/example/server.clj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/ring-spec-swagger/src/example/server.clj b/examples/ring-spec-swagger/src/example/server.clj index fe0ba885..7991aaa2 100644 --- a/examples/ring-spec-swagger/src/example/server.clj +++ b/examples/ring-spec-swagger/src/example/server.clj @@ -67,6 +67,8 @@ ["/download" {:get {:summary "downloads a file" :swagger {:produces ["image/png"]} + :responses {200 {:description "an image" + :content {"image/png" {:schema string?}}}} :handler (fn [_] {:status 200 :headers {"Content-Type" "image/png"}