test: nicer handling of missing :additionalProperties for spec

This commit is contained in:
Joel Kaasinen 2023-03-15 13:19:01 +02:00
parent 0c82ce0e4d
commit 66e7c9e1c8

View file

@ -408,18 +408,21 @@
(get-in [:paths "/parameters" :post :parameters]) (get-in [:paths "/parameters" :post :parameters])
normalize)))) normalize))))
(testing "body parameter" (testing "body parameter"
(is (match? {:schema {:type "object" (is (match? {:schema (merge {:type "object"
:properties {:b {:type "string"}} :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 (-> spec
(get-in [:paths "/parameters" :post :requestBody :content "application/json"]) (get-in [:paths "/parameters" :post :requestBody :content "application/json"])
normalize)))) normalize))))
(testing "body response" (testing "body response"
(is (match? {:schema {:type "object" (is (match? {:schema (merge {:type "object"
:properties {:ok {:type "string"}} :properties {:ok {:type "string"}}
#_#_:additionalProperties false ;; not present for spec :required ["ok"]}
:required ["ok"]}} (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))}
(-> spec (-> spec
(get-in [:paths "/parameters" :post :responses 200 :content "application/json"]) (get-in [:paths "/parameters" :post :responses 200 :content "application/json"])
normalize)))) normalize))))
@ -458,32 +461,36 @@
app app
:body)] :body)]
(testing "body parameter" (testing "body parameter"
(is (match? {:schema {:type "object" (is (match? {:schema (merge {:type "object"
:properties {:b {:type "string"}} :properties {:b {:type "string"}}
#_#_:additionalProperties false ;; not present for spec :required ["b"]}
:required ["b"]}} (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))}
(-> spec (-> spec
(get-in [:paths "/parameters" :post :requestBody :content "application/json"]) (get-in [:paths "/parameters" :post :requestBody :content "application/json"])
normalize))) normalize)))
(is (match? {:schema {:type "object" (is (match? {:schema (merge {:type "object"
:properties {:c {:type "string"}} :properties {:c {:type "string"}}
#_#_:additionalProperties false ;; not present for spec :required ["c"]}
:required ["c"]}} (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))}
(-> spec (-> spec
(get-in [:paths "/parameters" :post :requestBody :content "application/edn"]) (get-in [:paths "/parameters" :post :requestBody :content "application/edn"])
normalize)))) normalize))))
(testing "body response" (testing "body response"
(is (match? {:schema {:type "object" (is (match? {:schema (merge {:type "object"
:properties {:ok {:type "string"}} :properties {:ok {:type "string"}}
#_#_:additionalProperties false ;; not present for spec :required ["ok"]}
:required ["ok"]}} (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))}
(-> spec (-> spec
(get-in [:paths "/parameters" :post :responses 200 :content "application/json"]) (get-in [:paths "/parameters" :post :responses 200 :content "application/json"])
normalize))) normalize)))
(is (match? {:schema {:type "object" (is (match? {:schema (merge {:type "object"
:properties {:edn {:type "string"}} :properties {:edn {:type "string"}}
#_#_:additionalProperties false ;; not present for spec :required ["edn"]}
:required ["edn"]}} (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))}
(-> spec (-> spec
(get-in [:paths "/parameters" :post :responses 200 :content "application/edn"]) (get-in [:paths "/parameters" :post :responses 200 :content "application/edn"])
normalize)))) normalize))))