Allow empty response :body for Swagger

This commit is contained in:
Tommi Reiman 2018-06-24 19:20:08 +03:00
parent f6c460d05c
commit 3af1bd2083
4 changed files with 30 additions and 13 deletions

View file

@ -61,9 +61,12 @@
{::swagger/responses {::swagger/responses
(into (into
(empty responses) (empty responses)
(for [[k response] responses (for [[k response] responses]
:let [response (set/rename-keys response {:body :schema})]] [k (as-> response $
[k (update response :schema #(coercion/-compile-model this % nil))]))}))) (set/rename-keys $ {:body :schema})
(if (:schema $)
(update $ :schema #(coercion/-compile-model this % nil))
$))]))})))
(throw (throw
(ex-info (ex-info
(str "Can't produce Schema apidocs for " spesification) (str "Can't produce Schema apidocs for " spesification)

View file

@ -29,7 +29,11 @@
:default-encoder stt/any->any})) :default-encoder stt/any->any}))
(def no-op-transformer (def no-op-transformer
st/no-op-transformer) (reify
st/Transformer
(-name [_] ::no-op)
(-encoder [_ _ _])
(-decoder [_ _ _])))
(defprotocol IntoSpec (defprotocol IntoSpec
(into-spec [this name])) (into-spec [this name]))
@ -59,7 +63,10 @@
#?(:clj Object #?(:clj Object
:cljs default) :cljs default)
(into-spec [this _] (into-spec [this _]
(st/create-spec {:spec this}))) (st/create-spec {:spec this}))
nil
(into-spec [this _]))
(defn stringify-pred [pred] (defn stringify-pred [pred]
(str (if (seq? pred) (seq pred) pred))) (str (if (seq? pred) (seq pred) pred)))
@ -93,9 +100,12 @@
{::swagger/responses {::swagger/responses
(into (into
(empty responses) (empty responses)
(for [[k response] responses (for [[k response] responses]
:let [response (set/rename-keys response {:body :schema})]] [k (as-> response $
[k (update response :schema #(coercion/-compile-model this % nil))]))}))) (set/rename-keys $ {:body :schema})
(if (:schema $)
(update $ :schema #(coercion/-compile-model this % nil))
$))]))})))
(throw (throw
(ex-info (ex-info
(str "Can't produce Spec apidocs for " spesification) (str "Can't produce Spec apidocs for " spesification)

View file

@ -19,7 +19,7 @@
[meta-merge "1.0.0"] [meta-merge "1.0.0"]
[ring/ring-core "1.6.3"] [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/schema-tools "0.10.3"]
[metosin/ring-swagger-ui "2.2.10"] [metosin/ring-swagger-ui "2.2.10"]
[metosin/jsonista "0.2.1"]] [metosin/jsonista "0.2.1"]]

View file

@ -23,7 +23,8 @@
{:get {:summary "plus" {:get {:summary "plus"
:parameters {:query {:x int?, :y int?} :parameters {:query {:x int?, :y int?}
:path {:z int?}} :path {:z int?}}
:responses {200 {:body {:total int?}}} :responses {200 {:body {:total int?}}
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)}})}}]]
@ -33,7 +34,8 @@
{:get {:summary "plus" {:get {:summary "plus"
:parameters {:query {:x Int, :y Int} :parameters {:query {:x Int, :y Int}
:path {:z Int}} :path {:z Int}}
:responses {200 {:body {:total Int}}} :responses {200 {:body {:total Int}}
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)}})}}]]]
@ -87,7 +89,8 @@
:properties {"total" {:format "int32" :properties {"total" {:format "int32"
:type "integer"}} :type "integer"}}
:required ["total"] :required ["total"]
:type "object"}}} :type "object"}}
500 {:description "fail"}}
:summary "plus"}} :summary "plus"}}
"/api/spec/plus/{z}" {:get {:parameters [{:description "" "/api/spec/plus/{z}" {:get {:parameters [{:description ""
:format "int64" :format "int64"
@ -111,7 +114,8 @@
:schema {:properties {"total" {:format "int64" :schema {:properties {"total" {:format "int64"
:type "integer"}} :type "integer"}}
:required ["total"] :required ["total"]
:type "object"}}} :type "object"}}
500 {:description "fail"}}
:summary "plus"}}}} :summary "plus"}}}}
spec))))) spec)))))