mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 00:11:11 +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"]}}
|
||||
|
||||
["/plus"
|
||||
{:get {:summary "plus with spec"
|
||||
{:get {:summary "plus with spec query parameters"
|
||||
:parameters {:query {:x int?, :y int?}}
|
||||
:responses {200 {:body {:total int?}}}
|
||||
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
||||
{: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"
|
||||
{:coercion schema/coercion
|
||||
:swagger {:tags ["schema"]}}
|
||||
|
||||
["/plus"
|
||||
{:get {:summary "plus with schema"
|
||||
{:get {:summary "plus with schema query parameters"
|
||||
:parameters {:query {:x Int, :y Int}}
|
||||
:responses {200 {:body {:total Int}}}
|
||||
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
||||
{: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
|
||||
muuntaja.middleware/wrap-format
|
||||
|
|
@ -57,7 +69,10 @@
|
|||
"application/transit+json"}
|
||||
:consumes #{"application/json"
|
||||
"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
|
||||
(swagger-ui/create-swagger-ui-handler
|
||||
{:path "/", :url "/api/swagger.json"})
|
||||
|
|
|
|||
Loading…
Reference in a new issue