diff --git a/modules/reitit-schema/src/reitit/coercion/schema.cljc b/modules/reitit-schema/src/reitit/coercion/schema.cljc index 1f626886..c7bbc7e6 100644 --- a/modules/reitit-schema/src/reitit/coercion/schema.cljc +++ b/modules/reitit-schema/src/reitit/coercion/schema.cljc @@ -61,9 +61,12 @@ {::swagger/responses (into (empty responses) - (for [[k response] responses - :let [response (set/rename-keys response {:body :schema})]] - [k (update response :schema #(coercion/-compile-model this % nil))]))}))) + (for [[k response] responses] + [k (as-> response $ + (set/rename-keys $ {:body :schema}) + (if (:schema $) + (update $ :schema #(coercion/-compile-model this % nil)) + $))]))}))) (throw (ex-info (str "Can't produce Schema apidocs for " spesification) diff --git a/modules/reitit-spec/src/reitit/coercion/spec.cljc b/modules/reitit-spec/src/reitit/coercion/spec.cljc index 18025ae8..db3e6206 100644 --- a/modules/reitit-spec/src/reitit/coercion/spec.cljc +++ b/modules/reitit-spec/src/reitit/coercion/spec.cljc @@ -29,7 +29,11 @@ :default-encoder stt/any->any})) (def no-op-transformer - st/no-op-transformer) + (reify + st/Transformer + (-name [_] ::no-op) + (-encoder [_ _ _]) + (-decoder [_ _ _]))) (defprotocol IntoSpec (into-spec [this name])) @@ -59,7 +63,10 @@ #?(:clj Object :cljs default) (into-spec [this _] - (st/create-spec {:spec this}))) + (st/create-spec {:spec this})) + + nil + (into-spec [this _])) (defn stringify-pred [pred] (str (if (seq? pred) (seq pred) pred))) @@ -93,9 +100,12 @@ {::swagger/responses (into (empty responses) - (for [[k response] responses - :let [response (set/rename-keys response {:body :schema})]] - [k (update response :schema #(coercion/-compile-model this % nil))]))}))) + (for [[k response] responses] + [k (as-> response $ + (set/rename-keys $ {:body :schema}) + (if (:schema $) + (update $ :schema #(coercion/-compile-model this % nil)) + $))]))}))) (throw (ex-info (str "Can't produce Spec apidocs for " spesification) diff --git a/project.clj b/project.clj index 0bdfe394..7233f9e2 100644 --- a/project.clj +++ b/project.clj @@ -19,7 +19,7 @@ [meta-merge "1.0.0"] [ring/ring-core "1.6.3"] - [metosin/spec-tools "0.7.0"] + [metosin/spec-tools "0.7.1"] [metosin/schema-tools "0.10.3"] [metosin/ring-swagger-ui "2.2.10"] [metosin/jsonista "0.2.1"]] diff --git a/test/cljc/reitit/swagger_test.clj b/test/cljc/reitit/swagger_test.clj index c1d0631c..1b4722fa 100644 --- a/test/cljc/reitit/swagger_test.clj +++ b/test/cljc/reitit/swagger_test.clj @@ -23,7 +23,8 @@ {:get {:summary "plus" :parameters {:query {:x int?, :y int?} :path {:z int?}} - :responses {200 {:body {:total int?}}} + :responses {200 {:body {:total int?}} + 500 {:description "fail"}} :handler (fn [{{{:keys [x y]} :query {:keys [z]} :path} :parameters}] {:status 200, :body {:total (+ x y z)}})}}]] @@ -33,7 +34,8 @@ {:get {:summary "plus" :parameters {:query {:x Int, :y Int} :path {:z Int}} - :responses {200 {:body {:total Int}}} + :responses {200 {:body {:total Int}} + 500 {:description "fail"}} :handler (fn [{{{:keys [x y]} :query {:keys [z]} :path} :parameters}] {:status 200, :body {:total (+ x y z)}})}}]]] @@ -87,7 +89,8 @@ :properties {"total" {:format "int32" :type "integer"}} :required ["total"] - :type "object"}}} + :type "object"}} + 500 {:description "fail"}} :summary "plus"}} "/api/spec/plus/{z}" {:get {:parameters [{:description "" :format "int64" @@ -111,7 +114,8 @@ :schema {:properties {"total" {:format "int64" :type "integer"}} :required ["total"] - :type "object"}}} + :type "object"}} + 500 {:description "fail"}} :summary "plus"}}}} spec)))))