test: simplify openapi_test.clj a bit more

This commit is contained in:
Joel Kaasinen 2023-03-15 16:01:57 +02:00
parent bcd12d9f31
commit d0ff64df57

View file

@ -408,23 +408,23 @@
(get-in [:paths "/parameters" :post :parameters]) (get-in [:paths "/parameters" :post :parameters])
normalize)))) normalize))))
(testing "body parameter" (testing "body parameter"
(is (match? {:schema (merge {:type "object" (is (match? (merge {:type "object"
:properties {:b {:type "string"}} :properties {:b {:type "string"}}
:required ["b"]} :required ["b"]}
;; spec outputs open schemas ;; spec outputs open schemas
(when-not (#{#'spec/coercion} coercion) (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))} {:additionalProperties false}))
(-> spec (-> spec
(get-in [:paths "/parameters" :post :requestBody :content "application/json"]) (get-in [:paths "/parameters" :post :requestBody :content "application/json" :schema])
normalize)))) normalize))))
(testing "body response" (testing "body response"
(is (match? {:schema (merge {:type "object" (is (match? (merge {:type "object"
:properties {:ok {:type "string"}} :properties {:ok {:type "string"}}
:required ["ok"]} :required ["ok"]}
(when-not (#{#'spec/coercion} coercion) (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))} {:additionalProperties false}))
(-> spec (-> spec
(get-in [:paths "/parameters" :post :responses 200 :content "application/json"]) (get-in [:paths "/parameters" :post :responses 200 :content "application/json" :schema])
normalize)))) normalize))))
(testing "spec is valid" (testing "spec is valid"
(is (nil? (validate spec)))))))) (is (nil? (validate spec))))))))
@ -461,38 +461,38 @@
app app
:body)] :body)]
(testing "body parameter" (testing "body parameter"
(is (match? {:schema (merge {:type "object" (is (match? (merge {:type "object"
:properties {:b {:type "string"}} :properties {:b {:type "string"}}
:required ["b"]} :required ["b"]}
(when-not (#{#'spec/coercion} coercion) (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))} {:additionalProperties false}))
(-> spec (-> spec
(get-in [:paths "/parameters" :post :requestBody :content "application/json"]) (get-in [:paths "/parameters" :post :requestBody :content "application/json" :schema])
normalize))) normalize)))
(is (match? {:schema (merge {:type "object" (is (match? (merge {:type "object"
:properties {:c {:type "string"}} :properties {:c {:type "string"}}
:required ["c"]} :required ["c"]}
(when-not (#{#'spec/coercion} coercion) (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))} {:additionalProperties false}))
(-> spec (-> spec
(get-in [:paths "/parameters" :post :requestBody :content "application/edn"]) (get-in [:paths "/parameters" :post :requestBody :content "application/edn" :schema])
normalize)))) normalize))))
(testing "body response" (testing "body response"
(is (match? {:schema (merge {:type "object" (is (match? (merge {:type "object"
:properties {:ok {:type "string"}} :properties {:ok {:type "string"}}
:required ["ok"]} :required ["ok"]}
(when-not (#{#'spec/coercion} coercion) (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))} {:additionalProperties false}))
(-> spec (-> spec
(get-in [:paths "/parameters" :post :responses 200 :content "application/json"]) (get-in [:paths "/parameters" :post :responses 200 :content "application/json" :schema])
normalize))) normalize)))
(is (match? {:schema (merge {:type "object" (is (match? (merge {:type "object"
:properties {:edn {:type "string"}} :properties {:edn {:type "string"}}
:required ["edn"]} :required ["edn"]}
(when-not (#{#'spec/coercion} coercion) (when-not (#{#'spec/coercion} coercion)
{:additionalProperties false}))} {:additionalProperties false}))
(-> spec (-> spec
(get-in [:paths "/parameters" :post :responses 200 :content "application/edn"]) (get-in [:paths "/parameters" :post :responses 200 :content "application/edn" :schema])
normalize)))) normalize))))
(testing "validation" (testing "validation"
(let [query {:request-method :post (let [query {:request-method :post