mirror of
https://github.com/metosin/reitit.git
synced 2026-02-21 17:49:09 +00:00
Merge pull request #592 from metosin/openapi-fixes
misc. fixes for openapi3 support
This commit is contained in:
commit
8bf4b5c6a6
3 changed files with 203 additions and 197 deletions
|
|
@ -53,7 +53,7 @@
|
|||
["/openapi.json"
|
||||
{:get {:no-doc true
|
||||
:openapi {:info {:title "my-api"
|
||||
:description "openap-docs with reitit-http"
|
||||
:description "openapi3-docs with reitit-http"
|
||||
:version "0.0.1"}
|
||||
;; used in /secure APIs below
|
||||
:components {:securitySchemes {"auth" {:type :apiKey
|
||||
|
|
|
|||
|
|
@ -107,13 +107,12 @@
|
|||
(if (:schema $)
|
||||
(update $ :schema #(coercion/-compile-model this % nil))
|
||||
$))]))})))
|
||||
:openapi (openapi/openapi-spec
|
||||
(merge
|
||||
:openapi (merge
|
||||
(when (seq (dissoc parameters :body :request))
|
||||
{::openapi/parameters
|
||||
(openapi/openapi-spec {::openapi/parameters
|
||||
(into (empty parameters)
|
||||
(for [[k v] (dissoc parameters :body :request)]
|
||||
[k (coercion/-compile-model this v nil)]))})
|
||||
[k (coercion/-compile-model this v nil)]))}))
|
||||
(when (:body parameters)
|
||||
{:requestBody (openapi/openapi-spec
|
||||
{::openapi/content (zipmap content-types (repeat (coercion/-compile-model this (:body parameters) nil)))})})
|
||||
|
|
@ -140,7 +139,7 @@
|
|||
(when response
|
||||
(into {}
|
||||
(for [[format model] (:content response)]
|
||||
[format (coercion/-compile-model this model nil)]))))})))]))})))
|
||||
[format (coercion/-compile-model this model nil)]))))})))]))}))
|
||||
(throw
|
||||
(ex-info
|
||||
(str "Can't produce Spec apidocs for " specification)
|
||||
|
|
|
|||
|
|
@ -408,20 +408,23 @@
|
|||
(get-in [:paths "/parameters" :post :parameters])
|
||||
normalize))))
|
||||
(testing "body parameter"
|
||||
(is (match? {:schema {:type "object"
|
||||
(is (match? (merge {:type "object"
|
||||
:properties {:b {:type "string"}}
|
||||
#_#_:additionalProperties false ;; not present for spec
|
||||
:required ["b"]}}
|
||||
:required ["b"]}
|
||||
;; spec outputs open schemas
|
||||
(when-not (#{#'spec/coercion} coercion)
|
||||
{:additionalProperties false}))
|
||||
(-> spec
|
||||
(get-in [:paths "/parameters" :post :requestBody :content "application/json"])
|
||||
(get-in [:paths "/parameters" :post :requestBody :content "application/json" :schema])
|
||||
normalize))))
|
||||
(testing "body response"
|
||||
(is (match? {:schema {:type "object"
|
||||
(is (match? (merge {:type "object"
|
||||
:properties {:ok {:type "string"}}
|
||||
#_#_:additionalProperties false ;; not present for spec
|
||||
:required ["ok"]}}
|
||||
:required ["ok"]}
|
||||
(when-not (#{#'spec/coercion} coercion)
|
||||
{:additionalProperties false}))
|
||||
(-> spec
|
||||
(get-in [:paths "/parameters" :post :responses 200 :content "application/json"])
|
||||
(get-in [:paths "/parameters" :post :responses 200 :content "application/json" :schema])
|
||||
normalize))))
|
||||
(testing "spec is valid"
|
||||
(is (nil? (validate spec))))))))
|
||||
|
|
@ -458,34 +461,38 @@
|
|||
app
|
||||
:body)]
|
||||
(testing "body parameter"
|
||||
(is (match? {:schema {:type "object"
|
||||
(is (match? (merge {:type "object"
|
||||
:properties {:b {:type "string"}}
|
||||
#_#_:additionalProperties false ;; not present for spec
|
||||
:required ["b"]}}
|
||||
:required ["b"]}
|
||||
(when-not (#{#'spec/coercion} coercion)
|
||||
{:additionalProperties false}))
|
||||
(-> spec
|
||||
(get-in [:paths "/parameters" :post :requestBody :content "application/json"])
|
||||
(get-in [:paths "/parameters" :post :requestBody :content "application/json" :schema])
|
||||
normalize)))
|
||||
(is (match? {:schema {:type "object"
|
||||
(is (match? (merge {:type "object"
|
||||
:properties {:c {:type "string"}}
|
||||
#_#_:additionalProperties false ;; not present for spec
|
||||
:required ["c"]}}
|
||||
:required ["c"]}
|
||||
(when-not (#{#'spec/coercion} coercion)
|
||||
{:additionalProperties false}))
|
||||
(-> spec
|
||||
(get-in [:paths "/parameters" :post :requestBody :content "application/edn"])
|
||||
(get-in [:paths "/parameters" :post :requestBody :content "application/edn" :schema])
|
||||
normalize))))
|
||||
(testing "body response"
|
||||
(is (match? {:schema {:type "object"
|
||||
(is (match? (merge {:type "object"
|
||||
:properties {:ok {:type "string"}}
|
||||
#_#_:additionalProperties false ;; not present for spec
|
||||
:required ["ok"]}}
|
||||
:required ["ok"]}
|
||||
(when-not (#{#'spec/coercion} coercion)
|
||||
{:additionalProperties false}))
|
||||
(-> spec
|
||||
(get-in [:paths "/parameters" :post :responses 200 :content "application/json"])
|
||||
(get-in [:paths "/parameters" :post :responses 200 :content "application/json" :schema])
|
||||
normalize)))
|
||||
(is (match? {:schema {:type "object"
|
||||
(is (match? (merge {:type "object"
|
||||
:properties {:edn {:type "string"}}
|
||||
#_#_:additionalProperties false ;; not present for spec
|
||||
:required ["edn"]}}
|
||||
:required ["edn"]}
|
||||
(when-not (#{#'spec/coercion} coercion)
|
||||
{:additionalProperties false}))
|
||||
(-> spec
|
||||
(get-in [:paths "/parameters" :post :responses 200 :content "application/edn"])
|
||||
(get-in [:paths "/parameters" :post :responses 200 :content "application/edn" :schema])
|
||||
normalize))))
|
||||
(testing "validation"
|
||||
(let [query {:request-method :post
|
||||
|
|
|
|||
Loading…
Reference in a new issue