mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +00:00
Allow empty response :body for Swagger
This commit is contained in:
parent
f6c460d05c
commit
3af1bd2083
4 changed files with 30 additions and 13 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"]]
|
||||
|
|
|
|||
|
|
@ -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)))))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue