diff --git a/project.clj b/project.clj index d077880d..f0c0150f 100644 --- a/project.clj +++ b/project.clj @@ -35,7 +35,7 @@ [metosin/reitit-sieppari "0.9.2"] [metosin/reitit-pedestal "0.9.2"] [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/muuntaja "0.6.11"] [metosin/jsonista "0.3.13"] @@ -95,7 +95,7 @@ ;; modules dependencies [metosin/schema-tools "0.13.1"] - [metosin/spec-tools "0.10.7"] + [metosin/spec-tools "0.10.8"] [metosin/muuntaja "0.6.11"] [metosin/sieppari "0.0.0-alpha13"] [metosin/jsonista "0.3.13"] diff --git a/test/cljc/reitit/openapi_test.clj b/test/cljc/reitit/openapi_test.clj index 86ddc557..cc5e9dd0 100644 --- a/test/cljc/reitit/openapi_test.clj +++ b/test/cljc/reitit/openapi_test.clj @@ -18,6 +18,7 @@ [reitit.swagger-ui :as swagger-ui] [schema.core :as s] [schema-tools.core] + [clojure.spec.alpha :as sp] [spec-tools.core :as st] [spec-tools.data-spec :as ds])) @@ -1027,3 +1028,36 @@ "reitit.openapi-test.Y" {:type "integer"}}}} 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]))))))