From f1e3ed88ea69112eb7082ed651147c030eacd89d Mon Sep 17 00:00:00 2001 From: Jonas Claeson Date: Fri, 17 Jan 2025 14:45:17 +0100 Subject: [PATCH 1/4] The deprecation tag should be directly under parameters --- modules/reitit-openapi/src/reitit/openapi.clj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/reitit-openapi/src/reitit/openapi.clj b/modules/reitit-openapi/src/reitit/openapi.clj index 979620eb..ee562d0a 100644 --- a/modules/reitit-openapi/src/reitit/openapi.clj +++ b/modules/reitit-openapi/src/reitit/openapi.clj @@ -110,8 +110,9 @@ (merge {:in (name in) :name k :required (required? k) - :schema schema} - (select-keys schema [:description]))) + :schema (dissoc schema :deprecated)} + (select-keys schema [:description]) + (when (:deprecated schema) {:deprecated true}))) (into []))}) (when body ;; :body uses a single schema to describe every :requestBody From a3901809752dc89cb06f0467da5763f469d07930 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Fri, 25 Apr 2025 14:59:21 +0300 Subject: [PATCH 2/4] test: add description and deprecated to openapi-test --- test/cljc/reitit/openapi_test.clj | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/cljc/reitit/openapi_test.clj b/test/cljc/reitit/openapi_test.clj index 1b61f428..1fc50caf 100644 --- a/test/cljc/reitit/openapi_test.clj +++ b/test/cljc/reitit/openapi_test.clj @@ -47,7 +47,9 @@ ["/plus/:z" {:get {:summary "plus" :tags [:plus :spec] - :parameters {:query {:x int?, :y int?} + :parameters {:query {:x int?, :y (st/spec {:spec int? + :description "this is deprecated" + :openapi/deprecated true})} :path {:z int?}} :openapi {:operationId "spec-plus" :deprecated true @@ -78,7 +80,8 @@ ["/plus/*z" {:get {:summary "plus" :tags [:plus :malli] - :parameters {:query [:map [:x int?] [:y int?]] + :parameters {:query [:map [:x int?] [:y {:json-schema/deprecated true + :description "this is deprecated"} int?]] :path [:map [:z int?]]} :openapi {:responses {400 {:description "kosh" :content {"application/json" {:schema {:type "string"}}}}}} @@ -107,7 +110,8 @@ ["/plus/*z" {:get {:summary "plus" :tags [:plus :schema] - :parameters {:query {:x s/Int, :y s/Int} + :parameters {:query {:x s/Int, :y (schema-tools.core/schema s/Int {:description "this is deprecated" + :openapi/deprecated true})} :path {:z s/Int}} :openapi {:responses {400 {:content {"application/json" {:schema {:type "string"}}} :description "kosh"}}} @@ -163,9 +167,12 @@ :format "int64"}} {:in "query" :name "y" + :description "this is deprecated" + :deprecated true :required true :schema {:type "integer" - :format "int64"}} + :format "int64" + :description "this is deprecated"}} {:in "path" :name "z" :required true @@ -212,7 +219,10 @@ {:in "query" :name :y :required true - :schema {:type "integer"}} + :description "this is deprecated" + :deprecated true + :schema {:type "integer" + :description "this is deprecated"}} {:in "path" :name :z :required true @@ -256,8 +266,11 @@ {:in "query" :name "y" :required true + :description "this is deprecated" + :deprecated true :schema {:type "integer" - :format "int32"}} + :format "int32" + :description "this is deprecated"}} {:in "path" :name "z" :required true From 9534f6df8bc8ccd4f4054c4f0440a93eabada740 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Fri, 25 Apr 2025 15:04:51 +0300 Subject: [PATCH 3/4] feat: avoid duplicated :description for openapi parameters --- modules/reitit-openapi/src/reitit/openapi.clj | 5 ++--- test/cljc/reitit/openapi_test.clj | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/modules/reitit-openapi/src/reitit/openapi.clj b/modules/reitit-openapi/src/reitit/openapi.clj index ee562d0a..aade0b60 100644 --- a/modules/reitit-openapi/src/reitit/openapi.clj +++ b/modules/reitit-openapi/src/reitit/openapi.clj @@ -110,9 +110,8 @@ (merge {:in (name in) :name k :required (required? k) - :schema (dissoc schema :deprecated)} - (select-keys schema [:description]) - (when (:deprecated schema) {:deprecated true}))) + :schema (dissoc schema :description :deprecated)} + (select-keys schema [:description :deprecated]))) (into []))}) (when body ;; :body uses a single schema to describe every :requestBody diff --git a/test/cljc/reitit/openapi_test.clj b/test/cljc/reitit/openapi_test.clj index 1fc50caf..1e875fce 100644 --- a/test/cljc/reitit/openapi_test.clj +++ b/test/cljc/reitit/openapi_test.clj @@ -171,8 +171,7 @@ :deprecated true :required true :schema {:type "integer" - :format "int64" - :description "this is deprecated"}} + :format "int64"}} {:in "path" :name "z" :required true @@ -221,8 +220,7 @@ :required true :description "this is deprecated" :deprecated true - :schema {:type "integer" - :description "this is deprecated"}} + :schema {:type "integer"}} {:in "path" :name :z :required true @@ -269,8 +267,7 @@ :description "this is deprecated" :deprecated true :schema {:type "integer" - :format "int32" - :description "this is deprecated"}} + :format "int32"}} {:in "path" :name "z" :required true From 3c6139950cb8e196678e92fcf4b0584980b5e585 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Fri, 25 Apr 2025 15:07:52 +0300 Subject: [PATCH 4/4] doc: deprecated openapi parameters in docs & example --- doc/ring/openapi.md | 3 +++ examples/openapi/src/example/server.clj | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/doc/ring/openapi.md b/doc/ring/openapi.md index 7515b933..b2288575 100644 --- a/doc/ring/openapi.md +++ b/doc/ring/openapi.md @@ -139,6 +139,7 @@ Malli: [:x {:title "X parameter" :description "Description for X parameter" + :json-schema/deprecated true :json-schema/default 42} int?] [:y int?]]}}}] @@ -151,6 +152,7 @@ Schema: {:post {:parameters {:body {:x (schema-tools.core/schema s/Num {:description "Description for X parameter" + :openapi/deprecated true :openapi/example 13 :openapi/default 42}) :y int?}}}}] @@ -165,6 +167,7 @@ Spec: {:body (spec-tools.data-spec/spec ::foo {:x (schema-tools.core/spec {:spec int? :description "Description for X parameter" + :openapi/deprecated true :openapi/example 13 :openapi/default 42}) :y int?}}}}}] diff --git a/examples/openapi/src/example/server.clj b/examples/openapi/src/example/server.clj index 83e3a6b0..6c4ae3e7 100644 --- a/examples/openapi/src/example/server.clj +++ b/examples/openapi/src/example/server.clj @@ -97,6 +97,10 @@ :json-schema/default 30 :json-schema/example 10} int?] + [:charset {:title "Which charset to use?" + :optional true + :json-schema/deprecated true} + string?] [:email {:title "Email address to search for" :json-schema/format "email"} string?]]}