diff --git a/README.md b/README.md index a123dba7..bfc54cb2 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ A Ring routing app with input & output coercion using [data-specs](https://githu (ring/router ["/api" ["/math" {:get {:parameters {:query {:x int?, :y int?}} - :responses {200 {:schema {:total pos-int?}}} + :responses {200 {:body {:total pos-int?}}} :handler (fn [{{{:keys [x y]} :query} :parameters}] {:status 200 :body {:total (+ x y)}})}}]] diff --git a/doc/ring/coercion.md b/doc/ring/coercion.md index 9c9f45c2..8e8fa6ec 100644 --- a/doc/ring/coercion.md +++ b/doc/ring/coercion.md @@ -39,7 +39,7 @@ Handler can access the coerced parameters can be read under `:parameters` key in :parameters {:query {:x s/Int} :body {:y s/Int} :path {:z s/Int}} - :responses {200 {:schema {:total PositiveInt}}} + :responses {200 {:body {:total PositiveInt}}} :handler (fn [{:keys [parameters]}] (let [total (+ (-> parameters :query :x) (-> parameters :body :y) diff --git a/examples/ring-example/src/example/dspec.clj b/examples/ring-example/src/example/dspec.clj index b463bc80..0c8ffa03 100644 --- a/examples/ring-example/src/example/dspec.clj +++ b/examples/ring-example/src/example/dspec.clj @@ -4,7 +4,7 @@ (def routes ["/dspec" {:coercion reitit.coercion.spec/coercion} ["/plus" {:name ::plus - :responses {200 {:schema {:total int?}}} + :responses {200 {:body {:total int?}}} :get {:summary "plus with query-params" :parameters {:query {:x int?, :y int?}} :handler (fn [{{{:keys [x y]} :query} :parameters}] diff --git a/examples/ring-example/src/example/schema.clj b/examples/ring-example/src/example/schema.clj index 977a7b0c..13ac4125 100644 --- a/examples/ring-example/src/example/schema.clj +++ b/examples/ring-example/src/example/schema.clj @@ -5,7 +5,7 @@ (def routes ["/schema" {:coercion reitit.coercion.schema/coercion} ["/plus" {:name ::plus - :responses {200 {:schema {:total s/Int}}} + :responses {200 {:body {:total s/Int}}} :get {:summary "plus with query-params" :parameters {:query {:x s/Int, :y s/Int}} :handler (fn [{{{:keys [x y]} :query} :parameters}] diff --git a/examples/ring-example/src/example/spec.clj b/examples/ring-example/src/example/spec.clj index d8cfb3af..61a43020 100644 --- a/examples/ring-example/src/example/spec.clj +++ b/examples/ring-example/src/example/spec.clj @@ -11,7 +11,7 @@ (def routes ["/spec" {:coercion reitit.coercion.spec/coercion} ["/plus" {:name ::plus - :responses {200 {:schema (s/keys :req-un [::total])}} + :responses {200 {:body (s/keys :req-un [::total])}} :get {:summary "plus with query-params" :parameters {:query (s/keys :req-un [::x ::y])} :handler (fn [{{{:keys [x y]} :query} :parameters}] diff --git a/modules/reitit-core/src/reitit/coercion.cljc b/modules/reitit-core/src/reitit/coercion.cljc index 42461f84..4560db84 100644 --- a/modules/reitit-core/src/reitit/coercion.cljc +++ b/modules/reitit-core/src/reitit/coercion.cljc @@ -89,10 +89,10 @@ (request-coercion-failed! result coercion value in request) result)))))) -(defn response-coercer [coercion model {:keys [extract-response-format] - :or {extract-response-format (constantly nil)}}] +(defn response-coercer [coercion body {:keys [extract-response-format] + :or {extract-response-format (constantly nil)}}] (if coercion - (let [coercer (-response-coercer coercion model)] + (let [coercer (-response-coercer coercion body)] (fn [request response] (let [format (extract-response-format request response) value (:body response) @@ -126,8 +126,8 @@ (into {}))) (defn response-coercers [coercion responses opts] - (->> (for [[status {:keys [schema]}] responses :when schema] - [status (response-coercer coercion schema opts)]) + (->> (for [[status {:keys [body]}] responses :when body] + [status (response-coercer coercion body opts)]) (into {}))) (defn- coercers-not-compiled! [match] diff --git a/modules/reitit-core/src/reitit/spec.cljc b/modules/reitit-core/src/reitit/spec.cljc index 88fe97af..d3361f0d 100644 --- a/modules/reitit-core/src/reitit/spec.cljc +++ b/modules/reitit-core/src/reitit/spec.cljc @@ -92,10 +92,10 @@ (s/def :reitit.core.coercion/status (s/or :number number? :default #{:default})) -(s/def :reitit.core.coercion/schema any?) +(s/def :reitit.core.coercion/body any?) (s/def :reitit.core.coercion/description string?) (s/def :reitit.core.coercion/response - (s/keys :opt-un [:reitit.core.coercion/schema + (s/keys :opt-un [:reitit.core.coercion/body :reitit.core.coercion/description])) (s/def :reitit.core.coercion/responses (s/map-of :reitit.core.coercion/status :reitit.core.coercion/response)) diff --git a/perf-test/clj/reitit/coercion_perf_test.clj b/perf-test/clj/reitit/coercion_perf_test.clj index 71e97a4f..e91e660e 100644 --- a/perf-test/clj/reitit/coercion_perf_test.clj +++ b/perf-test/clj/reitit/coercion_perf_test.clj @@ -94,7 +94,7 @@ (suite (str (if coercion (protocol/get-name coercion)))) (let [routes ["/api" ["/ping" {:parameters {:body {:x int?, :y int?}} - :responses {200 {:schema {:total pos-int?}}} + :responses {200 {:body {:total pos-int?}}} :get {:handler (fn [request] (let [{:keys [x y]} (-> request :parameters :body)] {:status 200 @@ -152,7 +152,7 @@ (ring/router ["/api" ["/ping" {:parameters {:body {:x int?, :y int?}} - :responses {200 {:schema {:total pos-int?}}} + :responses {200 {:body {:total pos-int?}}} :get {:handler (fn [{{{:keys [x y]} :body} :parameters}] {:status 200 :body {:total (+ x y)}})}}]] @@ -199,7 +199,7 @@ (let [m (m/create (jsonista-format/with-json-format m/default-options)) app (ring/ring-handler (ring/router - ["/plus" {:post {:responses {200 {:schema {:result Long}}} + ["/plus" {:post {:responses {200 {:body {:result Long}}} :parameters {:body {:x Long, :y Long}} :handler (fn [request] (let [body (-> request :parameters :body)] @@ -224,7 +224,7 @@ (title "schema") (let [app (ring/ring-handler (ring/router - ["/plus" {:post {:responses {200 {:schema {:result Long}}} + ["/plus" {:post {:responses {200 {:body {:result Long}}} :parameters {:body {:x Long, :y Long}} :handler (fn [request] (let [body (-> request :parameters :body)] @@ -248,7 +248,7 @@ (title "data-spec") (let [app (ring/ring-handler (ring/router - ["/plus" {:post {:responses {200 {:schema {:result int?}}} + ["/plus" {:post {:responses {200 {:body {:result int?}}} :parameters {:body {:x int?, :y int?}} :handler (fn [request] (let [body (-> request :parameters :body)] @@ -277,7 +277,7 @@ (title "spec") (let [app (ring/ring-handler (ring/router - ["/plus" {:post {:responses {200 {:schema ::response}} + ["/plus" {:post {:responses {200 {:body ::response}} :parameters {:body ::request} :handler (fn [request] (let [body (-> request :parameters :body)] diff --git a/test/cljc/reitit/ring_coercion_test.cljc b/test/cljc/reitit/ring_coercion_test.cljc index 1909f786..a3e708ea 100644 --- a/test/cljc/reitit/ring_coercion_test.cljc +++ b/test/cljc/reitit/ring_coercion_test.cljc @@ -47,7 +47,7 @@ :form {:c int?} :header {:d int?} :path {:e int?}} - :responses {200 {:schema {:total pos-int?}}} + :responses {200 {:body {:total pos-int?}}} :handler handler}}]] {:data {:middleware middleware :coercion spec/coercion}})))] @@ -102,7 +102,7 @@ :form {:c s/Int} :header {:d s/Int} :path {:e s/Int}} - :responses {200 {:schema {:total (s/constrained s/Int pos? 'positive)}}} + :responses {200 {:body {:total (s/constrained s/Int pos? 'positive)}}} :handler handler}}]] {:data {:middleware middleware :coercion schema/coercion}})))] @@ -139,9 +139,9 @@ (app valid-request)))) (testing "invalid request" - (let [{:keys [status body]} (app invalid-request)] + (let [{:keys [status]} (app invalid-request)] (is (= 400 status)))) (testing "invalid response" - (let [{:keys [status body]} (app invalid-request2)] + (let [{:keys [status]} (app invalid-request2)] (is (= 500 status)))))))))) diff --git a/test/cljc/reitit/ring_spec_test.cljc b/test/cljc/reitit/ring_spec_test.cljc index b965420b..2c930728 100644 --- a/test/cljc/reitit/ring_spec_test.cljc +++ b/test/cljc/reitit/ring_spec_test.cljc @@ -89,7 +89,7 @@ :form {:c string?} :header {:d string?} :path {:e string?}} - :responses {200 {:schema {:total pos-int?}}} + :responses {200 {:body {:total pos-int?}}} :handler identity}}]] {:data {:middleware [rrc/coerce-exceptions-middleware rrc/coerce-request-middleware diff --git a/test/cljc/reitit/spec_test.cljc b/test/cljc/reitit/spec_test.cljc index 3fb68d6a..62012cd2 100644 --- a/test/cljc/reitit/spec_test.cljc +++ b/test/cljc/reitit/spec_test.cljc @@ -116,15 +116,15 @@ (is (s/valid? ::rs/responses - {:responses {200 {:description "ok", :schema string?} + {:responses {200 {:description "ok", :body string?} 400 {:description "fail"} - 500 {:schema string?} + 500 {:body string?} :default {}}})) (is (not (s/valid? ::rs/responses - {:responses {"200" {:description "ok", :schema string?}}}))) + {:responses {"200" {:description "ok", :body string?}}}))) (is (not (s/valid? ::rs/responses - {:responses {200 {:description :ok, :schema string?}}})))) + {:responses {200 {:description :ok, :body string?}}}))))