From 66e7c9e1c8e559b0fd85b91c9e08a7ec03bdc776 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Wed, 15 Mar 2023 13:19:01 +0200 Subject: [PATCH] test: nicer handling of missing :additionalProperties for spec --- test/cljc/reitit/openapi_test.clj | 55 +++++++++++++++++-------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/test/cljc/reitit/openapi_test.clj b/test/cljc/reitit/openapi_test.clj index a1c944d2..6ae134b2 100644 --- a/test/cljc/reitit/openapi_test.clj +++ b/test/cljc/reitit/openapi_test.clj @@ -408,18 +408,21 @@ (get-in [:paths "/parameters" :post :parameters]) normalize)))) (testing "body parameter" - (is (match? {:schema {:type "object" - :properties {:b {:type "string"}} - #_#_:additionalProperties false ;; not present for spec - :required ["b"]}} + (is (match? {:schema (merge {:type "object" + :properties {:b {:type "string"}} + :required ["b"]} + ;; spec outputs open schemas + (when-not (#{#'spec/coercion} coercion) + {:additionalProperties false}))} (-> spec (get-in [:paths "/parameters" :post :requestBody :content "application/json"]) normalize)))) (testing "body response" - (is (match? {:schema {:type "object" - :properties {:ok {:type "string"}} - #_#_:additionalProperties false ;; not present for spec - :required ["ok"]}} + (is (match? {:schema (merge {:type "object" + :properties {:ok {:type "string"}} + :required ["ok"]} + (when-not (#{#'spec/coercion} coercion) + {:additionalProperties false}))} (-> spec (get-in [:paths "/parameters" :post :responses 200 :content "application/json"]) normalize)))) @@ -458,32 +461,36 @@ app :body)] (testing "body parameter" - (is (match? {:schema {:type "object" - :properties {:b {:type "string"}} - #_#_:additionalProperties false ;; not present for spec - :required ["b"]}} + (is (match? {:schema (merge {:type "object" + :properties {:b {:type "string"}} + :required ["b"]} + (when-not (#{#'spec/coercion} coercion) + {:additionalProperties false}))} (-> spec (get-in [:paths "/parameters" :post :requestBody :content "application/json"]) normalize))) - (is (match? {:schema {:type "object" - :properties {:c {:type "string"}} - #_#_:additionalProperties false ;; not present for spec - :required ["c"]}} + (is (match? {:schema (merge {:type "object" + :properties {:c {:type "string"}} + :required ["c"]} + (when-not (#{#'spec/coercion} coercion) + {:additionalProperties false}))} (-> spec (get-in [:paths "/parameters" :post :requestBody :content "application/edn"]) normalize)))) (testing "body response" - (is (match? {:schema {:type "object" - :properties {:ok {:type "string"}} - #_#_:additionalProperties false ;; not present for spec - :required ["ok"]}} + (is (match? {:schema (merge {:type "object" + :properties {:ok {:type "string"}} + :required ["ok"]} + (when-not (#{#'spec/coercion} coercion) + {:additionalProperties false}))} (-> spec (get-in [:paths "/parameters" :post :responses 200 :content "application/json"]) normalize))) - (is (match? {:schema {:type "object" - :properties {:edn {:type "string"}} - #_#_:additionalProperties false ;; not present for spec - :required ["edn"]}} + (is (match? {:schema (merge {:type "object" + :properties {:edn {:type "string"}} + :required ["edn"]} + (when-not (#{#'spec/coercion} coercion) + {:additionalProperties false}))} (-> spec (get-in [:paths "/parameters" :post :responses 200 :content "application/edn"]) normalize))))