mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 16:31: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,8 +125,9 @@
|
||||||
(when request
|
(when request
|
||||||
;; request allow to different :requestBody per content-type
|
;; request allow to different :requestBody per content-type
|
||||||
{:requestBody
|
{:requestBody
|
||||||
{:content (merge
|
(merge
|
||||||
(select-keys request [:description])
|
(select-keys request [:description])
|
||||||
|
{:content (merge
|
||||||
(when-let [{:keys [schema] :as data} (coercion/get-default request)]
|
(when-let [{:keys [schema] :as data} (coercion/get-default request)]
|
||||||
(into {}
|
(into {}
|
||||||
(map (fn [content-type]
|
(map (fn [content-type]
|
||||||
|
|
@ -141,7 +142,7 @@
|
||||||
:type :schema
|
:type :schema
|
||||||
:content-type content-type})]
|
:content-type content-type})]
|
||||||
[content-type (->content data schema)])))
|
[content-type (->content data schema)])))
|
||||||
(dissoc (:content request) :default)))}})
|
(dissoc (:content request) :default)))})})
|
||||||
(when multipart
|
(when multipart
|
||||||
{:requestBody
|
{:requestBody
|
||||||
{:content
|
{:content
|
||||||
|
|
|
||||||
|
|
@ -869,19 +869,20 @@
|
||||||
(ring/router
|
(ring/router
|
||||||
[["/openapi.json"
|
[["/openapi.json"
|
||||||
{:get {:no-doc true
|
{:get {:no-doc true
|
||||||
|
:openapi {:info {:title "" :version "0.0.1"}}
|
||||||
:handler (openapi/create-openapi-handler)}}]
|
:handler (openapi/create-openapi-handler)}}]
|
||||||
|
|
||||||
["/malli" {:coercion malli/coercion}
|
["/malli" {:coercion malli/coercion}
|
||||||
["/plus" {:post {:summary "plus with body"
|
["/plus" {:post {:summary "plus with body"
|
||||||
:request {:description "body description"
|
:request {:description "body description"
|
||||||
:content {"application/json" {:schema {:x int?, :y int?}
|
:content {"application/json" {:schema {:x int?, :y int?}
|
||||||
:examples {"1+1" {:x 1, :y 1}
|
:examples {"1+1" {:value {:x 1, :y 1}}
|
||||||
"1+2" {:x 1, :y 2}}
|
"1+2" {:value {:x 1, :y 2}}}
|
||||||
:openapi {:example {:x 2, :y 2}}}}}
|
:openapi {:example {:x 2, :y 2}}}}}
|
||||||
:responses {200 {:description "success"
|
:responses {200 {:description "success"
|
||||||
:content {"application/json" {:schema {:total int?}
|
:content {"application/json" {:schema {:total int?}
|
||||||
:examples {"2" {:total 2}
|
:examples {"2" {:value {:total 2}}
|
||||||
"3" {:total 3}}
|
"3" {:value {:total 3}}}
|
||||||
:openapi {:example {:total 4}}}}}}
|
:openapi {:example {:total 4}}}}}}
|
||||||
:handler (fn [request]
|
:handler (fn [request]
|
||||||
(let [{:keys [x y]} (-> request :parameters :body)]
|
(let [{:keys [x y]} (-> request :parameters :body)]
|
||||||
|
|
@ -891,28 +892,28 @@
|
||||||
:data {:middleware [openapi/openapi-feature
|
:data {:middleware [openapi/openapi-feature
|
||||||
rrc/coerce-exceptions-middleware
|
rrc/coerce-exceptions-middleware
|
||||||
rrc/coerce-request-middleware
|
rrc/coerce-request-middleware
|
||||||
rrc/coerce-response-middleware]}}))]
|
rrc/coerce-response-middleware]}}))
|
||||||
(is (= {"/malli/plus" {:post {:requestBody {:content {:description "body description",
|
spec (:body (app {:request-method :get :uri "/openapi.json"}))]
|
||||||
"application/json" {:schema {:type "object",
|
(is (= {"/malli/plus" {:post {:requestBody {:description "body description",
|
||||||
|
:content {"application/json" {:schema {:type "object",
|
||||||
:properties {:x {:type "integer"},
|
:properties {:x {:type "integer"},
|
||||||
:y {:type "integer"}},
|
:y {:type "integer"}},
|
||||||
:required [:x :y],
|
:required [:x :y],
|
||||||
:additionalProperties false},
|
: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}}}},
|
:example {:x 2, :y 2}}}},
|
||||||
:responses {200 {:description "success",
|
:responses {200 {:description "success",
|
||||||
:content {"application/json" {:schema {:type "object",
|
:content {"application/json" {:schema {:type "object",
|
||||||
:properties {:total {:type "integer"}},
|
:properties {:total {:type "integer"}},
|
||||||
:required [:total],
|
:required [:total],
|
||||||
:additionalProperties false},
|
:additionalProperties false},
|
||||||
:examples {"2" {:total 2}, "3" {:total 3}},
|
:examples {"2" {:value {:total 2}},
|
||||||
|
"3" {:value {:total 3}}},
|
||||||
:example {:total 4}}}}},
|
:example {:total 4}}}}},
|
||||||
:summary "plus with body"}}}
|
:summary "plus with body"}}}
|
||||||
(-> {:request-method :get
|
(:paths spec)))
|
||||||
:uri "/openapi.json"}
|
(is (nil? (validate spec))))
|
||||||
(app)
|
|
||||||
:body
|
|
||||||
:paths))))
|
|
||||||
(testing "ref schemas"
|
(testing "ref schemas"
|
||||||
(let [registry (merge (mc/base-schemas)
|
(let [registry (merge (mc/base-schemas)
|
||||||
(mc/type-schemas)
|
(mc/type-schemas)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue