mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Update swagger test
This commit is contained in:
parent
5cd1cfa5e2
commit
ddf56624b7
1 changed files with 151 additions and 119 deletions
|
|
@ -9,7 +9,8 @@
|
||||||
[reitit.coercion.schema :as schema]
|
[reitit.coercion.schema :as schema]
|
||||||
[schema.core :refer [Int]]
|
[schema.core :refer [Int]]
|
||||||
[muuntaja.core :as m]
|
[muuntaja.core :as m]
|
||||||
[spec-tools.data-spec :as ds]))
|
[spec-tools.data-spec :as ds]
|
||||||
|
[schema.core :as s]))
|
||||||
|
|
||||||
(def app
|
(def app
|
||||||
(ring/ring-handler
|
(ring/ring-handler
|
||||||
|
|
@ -79,40 +80,147 @@
|
||||||
500 {:description "fail"}}
|
500 {:description "fail"}}
|
||||||
:handler (fn [{{{:keys [x y]} :query
|
:handler (fn [{{{:keys [x y]} :query
|
||||||
{:keys [z]} :path} :parameters}]
|
{:keys [z]} :path} :parameters}]
|
||||||
{:status 200, :body {:total (+ x y z)}})}}]]]
|
{:status 200, :body {:total (+ x y z)}})}
|
||||||
|
:post {:summary "plus with body"
|
||||||
|
:parameters {:body (s/maybe [s/Int])
|
||||||
|
:path {:z s/Int}}
|
||||||
|
:swagger {:responses {400 {:schema {:type "string"}
|
||||||
|
:description "kosh"}}}
|
||||||
|
:responses {200 {:body {:total s/Int}}
|
||||||
|
500 {:description "fail"}}
|
||||||
|
:handler (fn [{{{:keys [z]} :path
|
||||||
|
xs :body} :parameters}]
|
||||||
|
{:status 200, :body {:total (+ (reduce + xs) z)}})}}]]]
|
||||||
|
|
||||||
{:data {:middleware [swagger/swagger-feature
|
{:data {:middleware [swagger/swagger-feature
|
||||||
rrc/coerce-exceptions-middleware
|
rrc/coerce-exceptions-middleware
|
||||||
rrc/coerce-request-middleware
|
rrc/coerce-request-middleware
|
||||||
rrc/coerce-response-middleware]}})))
|
rrc/coerce-response-middleware]}})))
|
||||||
|
|
||||||
|
(require '[fipp.edn])
|
||||||
(deftest swagger-test
|
(deftest swagger-test
|
||||||
(testing "endpoints work"
|
(testing "endpoints work"
|
||||||
(testing "spec"
|
(testing "spec"
|
||||||
(is (= {:body {:total 6}, :status 200}
|
(is (= {:body {:total 6}, :status 200}
|
||||||
(app
|
(app {:request-method :get
|
||||||
{:request-method :get
|
:uri "/api/spec/plus/3"
|
||||||
:uri "/api/spec/plus/3"
|
:query-params {:x "2", :y "1"}})))
|
||||||
:query-params {:x "2", :y "1"}})))
|
|
||||||
(is (= {:body {:total 7}, :status 200}
|
(is (= {:body {:total 7}, :status 200}
|
||||||
(app
|
(app {:request-method :post
|
||||||
{:request-method :post
|
:uri "/api/spec/plus/3"
|
||||||
:uri "/api/spec/plus/3"
|
:body-params [1 3]}))))
|
||||||
:body-params [1 3]}))))
|
|
||||||
(testing "schema"
|
(testing "schema"
|
||||||
(is (= {:body {:total 6}, :status 200}
|
(is (= {:body {:total 6}, :status 200}
|
||||||
(app
|
(app {:request-method :get
|
||||||
{:request-method :get
|
:uri "/api/schema/plus/3"
|
||||||
:uri "/api/schema/plus/3"
|
:query-params {:x "2", :y "1"}})))))
|
||||||
:query-params {:x "2", :y "1"}})))))
|
|
||||||
(testing "swagger-spec"
|
(testing "swagger-spec"
|
||||||
(let [spec (:body (app
|
(let [spec (:body (app {:request-method :get
|
||||||
{:request-method :get
|
:uri "/api/swagger.json"}))
|
||||||
:uri "/api/swagger.json"}))
|
|
||||||
expected {:x-id #{::math}
|
expected {:x-id #{::math}
|
||||||
:swagger "2.0"
|
:swagger "2.0"
|
||||||
:info {:title "my-api"}
|
:info {:title "my-api"}
|
||||||
:paths {"/api/schema/plus/{z}" {:get {:parameters [{:description ""
|
:paths {"/api/spec/plus/{z}" {:get {:parameters [{:in "query"
|
||||||
|
:name "x"
|
||||||
|
:description ""
|
||||||
|
:required true
|
||||||
|
:type "integer"
|
||||||
|
:format "int64"}
|
||||||
|
{:in "query"
|
||||||
|
:name "y"
|
||||||
|
:description ""
|
||||||
|
:required true
|
||||||
|
:type "integer"
|
||||||
|
:format "int64"}
|
||||||
|
{:in "path"
|
||||||
|
:name "z"
|
||||||
|
:description ""
|
||||||
|
:required true
|
||||||
|
:type "integer"
|
||||||
|
:format "int64"}]
|
||||||
|
:responses {200 {:description ""
|
||||||
|
:schema {:type "object"
|
||||||
|
:properties {"total" {:format "int64"
|
||||||
|
:type "integer"}}
|
||||||
|
:required ["total"]}}
|
||||||
|
400 {:schema {:type "string"}
|
||||||
|
:description "kosh"}
|
||||||
|
500 {:description "fail"}}
|
||||||
|
:summary "plus"}
|
||||||
|
:post {:parameters [{:in "body",
|
||||||
|
:name "",
|
||||||
|
:description "",
|
||||||
|
:required false,
|
||||||
|
:schema {:type "array",
|
||||||
|
:items {:type "integer",
|
||||||
|
:format "int64"}
|
||||||
|
:x-nullable true}}
|
||||||
|
{:in "path"
|
||||||
|
:name "z"
|
||||||
|
:description ""
|
||||||
|
:type "integer"
|
||||||
|
:required true
|
||||||
|
:format "int64"}]
|
||||||
|
:responses {200 {:schema {:properties {"total" {:format "int64"
|
||||||
|
:type "integer"}}
|
||||||
|
:required ["total"]
|
||||||
|
:type "object"}
|
||||||
|
:description ""}
|
||||||
|
400 {:schema {:type "string"}
|
||||||
|
:description "kosh"}
|
||||||
|
500 {:description "fail"}}
|
||||||
|
:summary "plus with body"}}
|
||||||
|
"/api/malli/plus/{z}" {:get {:parameters [{:in "query"
|
||||||
|
:name :x
|
||||||
|
:description ""
|
||||||
|
:required true
|
||||||
|
:type "integer"
|
||||||
|
:format "int64"}
|
||||||
|
{:in "query"
|
||||||
|
:name :y
|
||||||
|
:description ""
|
||||||
|
:required true
|
||||||
|
:type "integer"
|
||||||
|
:format "int64"}
|
||||||
|
{:in "path"
|
||||||
|
:name :z
|
||||||
|
:description ""
|
||||||
|
:required true
|
||||||
|
:type "integer"
|
||||||
|
:format "int64"}]
|
||||||
|
:responses {200 {:schema {:type "object"
|
||||||
|
:properties {:total {:format "int64"
|
||||||
|
:type "integer"}}
|
||||||
|
:required [:total]}
|
||||||
|
:description ""}
|
||||||
|
400 {:schema {:type "string"}
|
||||||
|
:description "kosh"}
|
||||||
|
500 {:description "fail"}}
|
||||||
|
:summary "plus"}
|
||||||
|
:post {:parameters [{:in "body",
|
||||||
|
:name "body",
|
||||||
|
:description "",
|
||||||
|
:required false,
|
||||||
|
:schema {:type "array",
|
||||||
|
:items {:type "integer",
|
||||||
|
:format "int64"}
|
||||||
|
:x-nullable true}}
|
||||||
|
{:in "path"
|
||||||
|
:name :z
|
||||||
|
:description ""
|
||||||
|
:type "integer"
|
||||||
|
:required true
|
||||||
|
:format "int64"}]
|
||||||
|
:responses {200 {:description ""
|
||||||
|
:schema {:properties {:total {:format "int64"
|
||||||
|
:type "integer"}}
|
||||||
|
:required [:total]
|
||||||
|
:type "object"}}
|
||||||
|
400 {:schema {:type "string"}
|
||||||
|
:description "kosh"}
|
||||||
|
500 {:description "fail"}}
|
||||||
|
:summary "plus with body"}}
|
||||||
|
"/api/schema/plus/{z}" {:get {:parameters [{:description ""
|
||||||
:format "int32"
|
:format "int32"
|
||||||
:in "query"
|
:in "query"
|
||||||
:name "x"
|
:name "x"
|
||||||
|
|
@ -139,107 +247,31 @@
|
||||||
400 {:schema {:type "string"}
|
400 {:schema {:type "string"}
|
||||||
:description "kosh"}
|
:description "kosh"}
|
||||||
500 {:description "fail"}}
|
500 {:description "fail"}}
|
||||||
:summary "plus"}}
|
:summary "plus"}
|
||||||
"/api/malli/plus/{z}" {:get {:parameters [{:description ""
|
:post {:parameters [{:in "body",
|
||||||
:format "int64"
|
:name "body",
|
||||||
:in "query"
|
:description "",
|
||||||
:name :x
|
:required false,
|
||||||
:required true
|
:schema {:type "array",
|
||||||
:type "integer"}
|
:items {:type "integer",
|
||||||
{:description ""
|
:format "int32"}
|
||||||
:format "int64"
|
:x-nullable true}}
|
||||||
:in "query"
|
{:in "path"
|
||||||
:name :y
|
:name "z"
|
||||||
:required true
|
:description ""
|
||||||
:type "integer"}
|
:type "integer"
|
||||||
{:in "path"
|
:required true
|
||||||
:name :z
|
:format "int32"}]
|
||||||
:description ""
|
:responses {200 {:description ""
|
||||||
:type "integer"
|
:schema {:properties {"total" {:format "int32"
|
||||||
:required true
|
:type "integer"}}
|
||||||
:format "int64"}]
|
:additionalProperties false
|
||||||
:responses {200 {:description ""
|
:required ["total"]
|
||||||
:schema {:properties {:total {:format "int64"
|
:type "object"}}
|
||||||
:type "integer"}}
|
400 {:schema {:type "string"}
|
||||||
:required [:total]
|
:description "kosh"}
|
||||||
:type "object"}}
|
500 {:description "fail"}}
|
||||||
400 {:schema {:type "string"}
|
:summary "plus with body"}}}}]
|
||||||
:description "kosh"}
|
|
||||||
500 {:description "fail"}}
|
|
||||||
:summary "plus"}
|
|
||||||
:post {:parameters [{:in "body",
|
|
||||||
:name "",
|
|
||||||
:description "",
|
|
||||||
:required false,
|
|
||||||
:schema {:type "array",
|
|
||||||
:items {:type "integer",
|
|
||||||
:format "int64"}
|
|
||||||
:x-nullable true}}
|
|
||||||
{:in "path"
|
|
||||||
:name :z
|
|
||||||
:description ""
|
|
||||||
:type "integer"
|
|
||||||
:required true
|
|
||||||
:format "int64"}]
|
|
||||||
:responses {200 {:description ""
|
|
||||||
:schema {:properties {:total {:format "int64"
|
|
||||||
:type "integer"}}
|
|
||||||
:required [:total]
|
|
||||||
:type "object"}}
|
|
||||||
400 {:schema {:type "string"}
|
|
||||||
:description "kosh"}
|
|
||||||
500 {:description "fail"}}
|
|
||||||
:summary "plus with body"}}
|
|
||||||
"/api/spec/plus/{z}" {:get {:parameters [{:description ""
|
|
||||||
:format "int64"
|
|
||||||
:in "query"
|
|
||||||
:name "x"
|
|
||||||
:required true
|
|
||||||
:type "integer"}
|
|
||||||
{:description ""
|
|
||||||
:format "int64"
|
|
||||||
:in "query"
|
|
||||||
:name "y"
|
|
||||||
:required true
|
|
||||||
:type "integer"}
|
|
||||||
{:in "path"
|
|
||||||
:name "z"
|
|
||||||
:description ""
|
|
||||||
:type "integer"
|
|
||||||
:required true
|
|
||||||
:format "int64"}]
|
|
||||||
:responses {200 {:description ""
|
|
||||||
:schema {:properties {"total" {:format "int64"
|
|
||||||
:type "integer"}}
|
|
||||||
:required ["total"]
|
|
||||||
:type "object"}}
|
|
||||||
400 {:schema {:type "string"}
|
|
||||||
:description "kosh"}
|
|
||||||
500 {:description "fail"}}
|
|
||||||
:summary "plus"}
|
|
||||||
:post {:parameters [{:in "body",
|
|
||||||
:name "",
|
|
||||||
:description "",
|
|
||||||
:required false,
|
|
||||||
:schema {:type "array",
|
|
||||||
:items {:type "integer",
|
|
||||||
:format "int64"}
|
|
||||||
:x-nullable true}}
|
|
||||||
{:in "path"
|
|
||||||
:name "z"
|
|
||||||
:description ""
|
|
||||||
:type "integer"
|
|
||||||
:required true
|
|
||||||
:format "int64"}]
|
|
||||||
:responses {200 {:description ""
|
|
||||||
:schema {:properties {"total" {:format "int64"
|
|
||||||
:type "integer"}}
|
|
||||||
:required ["total"]
|
|
||||||
:type "object"}}
|
|
||||||
400 {:schema {:type "string"}
|
|
||||||
:description "kosh"}
|
|
||||||
500 {:description "fail"}}
|
|
||||||
:summary "plus with body"}}}}]
|
|
||||||
(is (= expected spec))
|
(is (= expected spec))
|
||||||
|
|
||||||
(testing "ring-async swagger-spec"
|
(testing "ring-async swagger-spec"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue