mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
Merge pull request #766 from metosin/spec-and-or
Some checks failed
testsuite / Clojure (Java 11) (push) Has been cancelled
testsuite / Clojure (Java 17) (push) Has been cancelled
testsuite / Clojure (Java 21) (push) Has been cancelled
testsuite / ClojureScript (push) Has been cancelled
testsuite / Lint cljdoc.edn (push) Has been cancelled
testsuite / Check cljdoc analysis (push) Has been cancelled
Some checks failed
testsuite / Clojure (Java 11) (push) Has been cancelled
testsuite / Clojure (Java 17) (push) Has been cancelled
testsuite / Clojure (Java 21) (push) Has been cancelled
testsuite / ClojureScript (push) Has been cancelled
testsuite / Lint cljdoc.edn (push) Has been cancelled
testsuite / Check cljdoc analysis (push) Has been cancelled
Bump spec-tools, test openapi + s/keys + or
This commit is contained in:
commit
9d88d92241
2 changed files with 36 additions and 2 deletions
|
|
@ -35,7 +35,7 @@
|
||||||
[metosin/reitit-sieppari "0.9.2"]
|
[metosin/reitit-sieppari "0.9.2"]
|
||||||
[metosin/reitit-pedestal "0.9.2"]
|
[metosin/reitit-pedestal "0.9.2"]
|
||||||
[metosin/ring-swagger-ui "5.20.0"]
|
[metosin/ring-swagger-ui "5.20.0"]
|
||||||
[metosin/spec-tools "0.10.7"]
|
[metosin/spec-tools "0.10.8"]
|
||||||
[metosin/schema-tools "0.13.1"]
|
[metosin/schema-tools "0.13.1"]
|
||||||
[metosin/muuntaja "0.6.11"]
|
[metosin/muuntaja "0.6.11"]
|
||||||
[metosin/jsonista "0.3.13"]
|
[metosin/jsonista "0.3.13"]
|
||||||
|
|
@ -95,7 +95,7 @@
|
||||||
|
|
||||||
;; modules dependencies
|
;; modules dependencies
|
||||||
[metosin/schema-tools "0.13.1"]
|
[metosin/schema-tools "0.13.1"]
|
||||||
[metosin/spec-tools "0.10.7"]
|
[metosin/spec-tools "0.10.8"]
|
||||||
[metosin/muuntaja "0.6.11"]
|
[metosin/muuntaja "0.6.11"]
|
||||||
[metosin/sieppari "0.0.0-alpha13"]
|
[metosin/sieppari "0.0.0-alpha13"]
|
||||||
[metosin/jsonista "0.3.13"]
|
[metosin/jsonista "0.3.13"]
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
[reitit.swagger-ui :as swagger-ui]
|
[reitit.swagger-ui :as swagger-ui]
|
||||||
[schema.core :as s]
|
[schema.core :as s]
|
||||||
[schema-tools.core]
|
[schema-tools.core]
|
||||||
|
[clojure.spec.alpha :as sp]
|
||||||
[spec-tools.core :as st]
|
[spec-tools.core :as st]
|
||||||
[spec-tools.data-spec :as ds]))
|
[spec-tools.data-spec :as ds]))
|
||||||
|
|
||||||
|
|
@ -1027,3 +1028,36 @@
|
||||||
"reitit.openapi-test.Y" {:type "integer"}}}}
|
"reitit.openapi-test.Y" {:type "integer"}}}}
|
||||||
spec))
|
spec))
|
||||||
(is (nil? (validate spec))))))
|
(is (nil? (validate spec))))))
|
||||||
|
|
||||||
|
(sp/def ::address string?)
|
||||||
|
(sp/def ::zip int?)
|
||||||
|
(sp/def ::city string?)
|
||||||
|
(sp/def ::street string?)
|
||||||
|
(sp/def ::or-and-schema (sp/keys :req-un [(or (and ::address ::zip) (and ::city ::street))]))
|
||||||
|
|
||||||
|
(deftest openapi-spec-tests
|
||||||
|
(testing "s/keys + or maps to :anyOf"
|
||||||
|
(let [app (ring/ring-handler
|
||||||
|
(ring/router
|
||||||
|
[["/openapi.json"
|
||||||
|
{:get {:no-doc true
|
||||||
|
:openapi {:info {:title "" :version "0.0.1"}}
|
||||||
|
:handler (openapi/create-openapi-handler)}}]
|
||||||
|
|
||||||
|
["/spec" {:coercion spec/coercion
|
||||||
|
:post {:summary "or-and-schema"
|
||||||
|
:request {:content {"application/json" {:schema ::or-and-schema}}}
|
||||||
|
:handler identity}}]]
|
||||||
|
{:validate reitit.ring.spec/validate
|
||||||
|
:data {:middleware [openapi/openapi-feature]}}))
|
||||||
|
spec (:body (app {:request-method :get :uri "/openapi.json"}))]
|
||||||
|
(is (nil? (validate spec)))
|
||||||
|
(is (= {:title "reitit.openapi-test/or-and-schema"
|
||||||
|
:type "object"
|
||||||
|
:properties {"address" {:type "string"}
|
||||||
|
"zip" {:type "integer" :format "int64"}
|
||||||
|
"city" {:type "string"}
|
||||||
|
"street" {:type "string"}}
|
||||||
|
:anyOf [{:required ["address" "zip"]}
|
||||||
|
{:required ["city" "street"]}]}
|
||||||
|
(get-in spec [:paths "/spec" :post :requestBody :content "application/json" :schema]))))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue