mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
fix: location of openapi :requestBody :description
:description should be under :requestBody, not under :content. Thanks to openapi-schema-validator for noticing this. Also fix examples in openapi-malli-tests to make the resulting schema valid.
This commit is contained in:
parent
c84433352e
commit
037763561e
2 changed files with 33 additions and 31 deletions
|
|
@ -125,23 +125,24 @@
|
|||
(when request
|
||||
;; request allow to different :requestBody per content-type
|
||||
{:requestBody
|
||||
{:content (merge
|
||||
(select-keys request [:description])
|
||||
(when-let [{:keys [schema] :as data} (coercion/get-default request)]
|
||||
(into {}
|
||||
(map (fn [content-type]
|
||||
(let [schema (->schema-object schema {:in :requestBody
|
||||
:type :schema
|
||||
:content-type content-type})]
|
||||
[content-type (->content data schema)])))
|
||||
request-content-types))
|
||||
(into {}
|
||||
(map (fn [[content-type {:keys [schema] :as data}]]
|
||||
(let [schema (->schema-object schema {:in :requestBody
|
||||
:type :schema
|
||||
:content-type content-type})]
|
||||
[content-type (->content data schema)])))
|
||||
(dissoc (:content request) :default)))}})
|
||||
(merge
|
||||
(select-keys request [:description])
|
||||
{:content (merge
|
||||
(when-let [{:keys [schema] :as data} (coercion/get-default request)]
|
||||
(into {}
|
||||
(map (fn [content-type]
|
||||
(let [schema (->schema-object schema {:in :requestBody
|
||||
:type :schema
|
||||
:content-type content-type})]
|
||||
[content-type (->content data schema)])))
|
||||
request-content-types))
|
||||
(into {}
|
||||
(map (fn [[content-type {:keys [schema] :as data}]]
|
||||
(let [schema (->schema-object schema {:in :requestBody
|
||||
:type :schema
|
||||
:content-type content-type})]
|
||||
[content-type (->content data schema)])))
|
||||
(dissoc (:content request) :default)))})})
|
||||
(when multipart
|
||||
{:requestBody
|
||||
{:content
|
||||
|
|
|
|||
|
|
@ -869,19 +869,20 @@
|
|||
(ring/router
|
||||
[["/openapi.json"
|
||||
{:get {:no-doc true
|
||||
:openapi {:info {:title "" :version "0.0.1"}}
|
||||
:handler (openapi/create-openapi-handler)}}]
|
||||
|
||||
["/malli" {:coercion malli/coercion}
|
||||
["/plus" {:post {:summary "plus with body"
|
||||
:request {:description "body description"
|
||||
:content {"application/json" {:schema {:x int?, :y int?}
|
||||
:examples {"1+1" {:x 1, :y 1}
|
||||
"1+2" {:x 1, :y 2}}
|
||||
:examples {"1+1" {:value {:x 1, :y 1}}
|
||||
"1+2" {:value {:x 1, :y 2}}}
|
||||
:openapi {:example {:x 2, :y 2}}}}}
|
||||
:responses {200 {:description "success"
|
||||
:content {"application/json" {:schema {:total int?}
|
||||
:examples {"2" {:total 2}
|
||||
"3" {:total 3}}
|
||||
:examples {"2" {:value {:total 2}}
|
||||
"3" {:value {:total 3}}}
|
||||
:openapi {:example {:total 4}}}}}}
|
||||
:handler (fn [request]
|
||||
(let [{:keys [x y]} (-> request :parameters :body)]
|
||||
|
|
@ -891,28 +892,28 @@
|
|||
:data {:middleware [openapi/openapi-feature
|
||||
rrc/coerce-exceptions-middleware
|
||||
rrc/coerce-request-middleware
|
||||
rrc/coerce-response-middleware]}}))]
|
||||
(is (= {"/malli/plus" {:post {:requestBody {:content {:description "body description",
|
||||
"application/json" {:schema {:type "object",
|
||||
rrc/coerce-response-middleware]}}))
|
||||
spec (:body (app {:request-method :get :uri "/openapi.json"}))]
|
||||
(is (= {"/malli/plus" {:post {:requestBody {:description "body description",
|
||||
:content {"application/json" {:schema {:type "object",
|
||||
:properties {:x {:type "integer"},
|
||||
:y {:type "integer"}},
|
||||
:required [:x :y],
|
||||
:additionalProperties false},
|
||||
:examples {"1+1" {:x 1, :y 1}, "1+2" {:x 1, :y 2}},
|
||||
:examples {"1+1" {:value {:x 1, :y 1}}
|
||||
"1+2" {:value {:x 1, :y 2}}},
|
||||
:example {:x 2, :y 2}}}},
|
||||
:responses {200 {:description "success",
|
||||
:content {"application/json" {:schema {:type "object",
|
||||
:properties {:total {:type "integer"}},
|
||||
:required [:total],
|
||||
:additionalProperties false},
|
||||
:examples {"2" {:total 2}, "3" {:total 3}},
|
||||
:examples {"2" {:value {:total 2}},
|
||||
"3" {:value {:total 3}}},
|
||||
:example {:total 4}}}}},
|
||||
:summary "plus with body"}}}
|
||||
(-> {:request-method :get
|
||||
:uri "/openapi.json"}
|
||||
(app)
|
||||
:body
|
||||
:paths))))
|
||||
(:paths spec)))
|
||||
(is (nil? (validate spec))))
|
||||
(testing "ref schemas"
|
||||
(let [registry (merge (mc/base-schemas)
|
||||
(mc/type-schemas)
|
||||
|
|
|
|||
Loading…
Reference in a new issue