Merge pull request #624 from metosin/openapi-descriptions-malli

fix: openapi malli parameter descriptions
This commit is contained in:
Joel Kaasinen 2023-05-17 12:24:28 +03:00 committed by GitHub
commit 6b378ffbf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View file

@ -145,14 +145,14 @@
(when (seq parameters) (when (seq parameters)
{:parameters {:parameters
(->> (for [[in schema] 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))] required? (partial contains? (set required))]
[k schema] properties] [k schema] properties]
(merge {:in (name in) (merge {:in (name in)
:name k :name k
:required (required? k) :required (required? k)
:schema schema} :schema schema}
(select-keys root [:description]))) (select-keys schema [:description])))
(into []))}) (into []))})
(when body (when body
;; body uses a single schema to describe every :requestBody ;; body uses a single schema to describe every :requestBody

View file

@ -365,9 +365,10 @@
(deftest all-parameter-types-test (deftest all-parameter-types-test
(doseq [[coercion ->schema] (doseq [[coercion ->schema]
[[#'malli/coercion (fn [nom] [:map [nom :string]])] [[#'malli/coercion (fn [nom] [:map [nom [:string {:description (str "description " nom)}]]])]
[#'schema/coercion (fn [nom] {nom s/Str})] [#'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 (testing coercion
(let [app (ring/ring-handler (let [app (ring/ring-handler
(ring/router (ring/router
@ -395,18 +396,30 @@
(is (match? [{:in "query" (is (match? [{:in "query"
:name "q" :name "q"
:required true :required true
:description (if (not= #'schema/coercion coercion)
"description :q"
"")
:schema {:type "string"}} :schema {:type "string"}}
{:in "header" {:in "header"
:name "h" :name "h"
:required true :required true
:description (if (not= #'schema/coercion coercion)
"description :h"
"")
:schema {:type "string"}} :schema {:type "string"}}
{:in "cookie" {:in "cookie"
:name "c" :name "c"
:required true :required true
:description (if (not= #'schema/coercion coercion)
"description :c"
"")
:schema {:type "string"}} :schema {:type "string"}}
{:in "path" {:in "path"
:name "p" :name "p"
:required true :required true
:description (if (not= #'schema/coercion coercion)
"description :p"
"")
:schema {:type "string"}}] :schema {:type "string"}}]
(-> spec (-> spec
(get-in [:paths "/parameters" :post :parameters]) (get-in [:paths "/parameters" :post :parameters])