mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
update example how to resolve body format with Muuntaja
This commit is contained in:
parent
a416060354
commit
33a8f0626e
1 changed files with 20 additions and 5 deletions
|
|
@ -27,24 +27,36 @@
|
||||||
:swagger {:tags ["spec"]}}
|
:swagger {:tags ["spec"]}}
|
||||||
|
|
||||||
["/plus"
|
["/plus"
|
||||||
{:get {:summary "plus with spec"
|
{:get {:summary "plus with spec query parameters"
|
||||||
:parameters {:query {:x int?, :y int?}}
|
:parameters {:query {:x int?, :y int?}}
|
||||||
:responses {200 {:body {:total int?}}}
|
:responses {200 {:body {:total int?}}}
|
||||||
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
||||||
{:status 200
|
{:status 200
|
||||||
:body {:total (+ x y)}})}}]]
|
:body {:total (+ x y)}})}
|
||||||
|
:post {:summary "plus with spec body parameters"
|
||||||
|
:parameters {:body {:x int?, :y int?}}
|
||||||
|
:responses {200 {:body {:total int?}}}
|
||||||
|
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
||||||
|
{:status 200
|
||||||
|
:body {:total (+ x y)}})}}]]
|
||||||
|
|
||||||
["/schema"
|
["/schema"
|
||||||
{:coercion schema/coercion
|
{:coercion schema/coercion
|
||||||
:swagger {:tags ["schema"]}}
|
:swagger {:tags ["schema"]}}
|
||||||
|
|
||||||
["/plus"
|
["/plus"
|
||||||
{:get {:summary "plus with schema"
|
{:get {:summary "plus with schema query parameters"
|
||||||
:parameters {:query {:x Int, :y Int}}
|
:parameters {:query {:x Int, :y Int}}
|
||||||
:responses {200 {:body {:total Int}}}
|
:responses {200 {:body {:total Int}}}
|
||||||
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
||||||
{:status 200
|
{:status 200
|
||||||
:body {:total (+ x y)}})}}]]]
|
:body {:total (+ x y)}})}
|
||||||
|
:post {:summary "plus with schema body parameters"
|
||||||
|
:parameters {:body {:x Int, :y Int}}
|
||||||
|
:responses {200 {:body {:total Int}}}
|
||||||
|
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
||||||
|
{:status 200
|
||||||
|
:body {:total (+ x y)}})}}]]]
|
||||||
|
|
||||||
{:data {:middleware [ring.middleware.params/wrap-params
|
{:data {:middleware [ring.middleware.params/wrap-params
|
||||||
muuntaja.middleware/wrap-format
|
muuntaja.middleware/wrap-format
|
||||||
|
|
@ -57,7 +69,10 @@
|
||||||
"application/transit+json"}
|
"application/transit+json"}
|
||||||
:consumes #{"application/json"
|
:consumes #{"application/json"
|
||||||
"application/edn"
|
"application/edn"
|
||||||
"application/transit+json"}}}})
|
"application/transit+json"}}}
|
||||||
|
;; TODO: these should work by default!
|
||||||
|
:extract-request-format (comp :format :muuntaja/request)
|
||||||
|
:extract-response-format (comp :format :muuntaja/response)})
|
||||||
(ring/routes
|
(ring/routes
|
||||||
(swagger-ui/create-swagger-ui-handler
|
(swagger-ui/create-swagger-ui-handler
|
||||||
{:path "/", :url "/api/swagger.json"})
|
{:path "/", :url "/api/swagger.json"})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue