From 2e8e9265d92579b901393e27ce90660cca00365f Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Tue, 16 May 2023 17:18:51 +0300 Subject: [PATCH 1/3] test: document current openapi3 description behaviour malli works weirdly, others don't --- test/cljc/reitit/openapi_test.clj | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/cljc/reitit/openapi_test.clj b/test/cljc/reitit/openapi_test.clj index bef17f7c..d4999ee8 100644 --- a/test/cljc/reitit/openapi_test.clj +++ b/test/cljc/reitit/openapi_test.clj @@ -365,7 +365,7 @@ (deftest all-parameter-types-test (doseq [[coercion ->schema] - [[#'malli/coercion (fn [nom] [:map [nom :string]])] + [[#'malli/coercion (fn [nom] [:map {:description (str "description " nom)} [nom :string]])] [#'schema/coercion (fn [nom] {nom s/Str})] [#'spec/coercion (fn [nom] {nom string?})]]] (testing coercion @@ -395,18 +395,30 @@ (is (match? [{:in "query" :name "q" :required true + :description (if (= #'malli/coercion coercion) + "description :q" + "") :schema {:type "string"}} {:in "header" :name "h" :required true + :description (if (= #'malli/coercion coercion) + "description :h" + "") :schema {:type "string"}} {:in "cookie" :name "c" :required true + :description (if (= #'malli/coercion coercion) + "description :c" + "") :schema {:type "string"}} {:in "path" :name "p" :required true + :description (if (= #'malli/coercion coercion) + "description :p" + "") :schema {:type "string"}}] (-> spec (get-in [:paths "/parameters" :post :parameters]) From b56c15b64c7432186853db211e2e042f79081dc0 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Tue, 16 May 2023 18:03:40 +0300 Subject: [PATCH 2/3] fix: openapi malli parameter descriptions ... should come from the parameter type, not from the parent :map --- modules/reitit-malli/src/reitit/coercion/malli.cljc | 4 ++-- test/cljc/reitit/openapi_test.clj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/reitit-malli/src/reitit/coercion/malli.cljc b/modules/reitit-malli/src/reitit/coercion/malli.cljc index 99226230..cb9ca777 100644 --- a/modules/reitit-malli/src/reitit/coercion/malli.cljc +++ b/modules/reitit-malli/src/reitit/coercion/malli.cljc @@ -145,14 +145,14 @@ (when (seq parameters) {:parameters (->> (for [[in schema] parameters - :let [{:keys [properties required] :as root} (->schema-object schema {:in in :type :parameter}) + :let [{:keys [properties required]} (->schema-object schema {:in in :type :parameter}) required? (partial contains? (set required))] [k schema] properties] (merge {:in (name in) :name k :required (required? k) :schema schema} - (select-keys root [:description]))) + (select-keys schema [:description]))) (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 d4999ee8..504fc18d 100644 --- a/test/cljc/reitit/openapi_test.clj +++ b/test/cljc/reitit/openapi_test.clj @@ -365,7 +365,7 @@ (deftest all-parameter-types-test (doseq [[coercion ->schema] - [[#'malli/coercion (fn [nom] [:map {:description (str "description " nom)} [nom :string]])] + [[#'malli/coercion (fn [nom] [:map [nom [:string {:description (str "description " nom)}]]])] [#'schema/coercion (fn [nom] {nom s/Str})] [#'spec/coercion (fn [nom] {nom string?})]]] (testing coercion From c443adbfca50604da8930551edc336e7f68f7c92 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Wed, 17 May 2023 08:25:44 +0300 Subject: [PATCH 3/3] test: openapi parameter descriptions via spec --- test/cljc/reitit/openapi_test.clj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/cljc/reitit/openapi_test.clj b/test/cljc/reitit/openapi_test.clj index 504fc18d..165cc91d 100644 --- a/test/cljc/reitit/openapi_test.clj +++ b/test/cljc/reitit/openapi_test.clj @@ -367,7 +367,8 @@ (doseq [[coercion ->schema] [[#'malli/coercion (fn [nom] [:map [nom [:string {:description (str "description " nom)}]]])] [#'schema/coercion (fn [nom] {nom s/Str})] - [#'spec/coercion (fn [nom] {nom string?})]]] + [#'spec/coercion (fn [nom] {nom (st/spec {:spec string? + :description (str "description " nom)})})]]] (testing coercion (let [app (ring/ring-handler (ring/router @@ -395,28 +396,28 @@ (is (match? [{:in "query" :name "q" :required true - :description (if (= #'malli/coercion coercion) + :description (if (not= #'schema/coercion coercion) "description :q" "") :schema {:type "string"}} {:in "header" :name "h" :required true - :description (if (= #'malli/coercion coercion) + :description (if (not= #'schema/coercion coercion) "description :h" "") :schema {:type "string"}} {:in "cookie" :name "c" :required true - :description (if (= #'malli/coercion coercion) + :description (if (not= #'schema/coercion coercion) "description :c" "") :schema {:type "string"}} {:in "path" :name "p" :required true - :description (if (= #'malli/coercion coercion) + :description (if (not= #'schema/coercion coercion) "description :p" "") :schema {:type "string"}}]