mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
example of malli coercion
This commit is contained in:
parent
44f6c51610
commit
3b53efc439
2 changed files with 11 additions and 10 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
# reitit-ring, clojure.spec, swagger
|
# reitit-ring, malli, swagger
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
@ -20,4 +20,4 @@ http GET :3000/swagger.json
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright © 2017-2018 Metosin Oy
|
Copyright © 2017-2019 Metosin Oy
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns example.server
|
(ns example.server
|
||||||
(:require [reitit.ring :as ring]
|
(:require [reitit.ring :as ring]
|
||||||
[reitit.coercion.spec]
|
[reitit.coercion.malli]
|
||||||
|
[reitit.ring.malli]
|
||||||
[reitit.swagger :as swagger]
|
[reitit.swagger :as swagger]
|
||||||
[reitit.swagger-ui :as swagger-ui]
|
[reitit.swagger-ui :as swagger-ui]
|
||||||
[reitit.ring.coercion :as coercion]
|
[reitit.ring.coercion :as coercion]
|
||||||
|
|
@ -30,8 +31,8 @@
|
||||||
|
|
||||||
["/upload"
|
["/upload"
|
||||||
{:post {:summary "upload a file"
|
{:post {:summary "upload a file"
|
||||||
:parameters {:multipart {:file multipart/temp-file-part}}
|
:parameters {:multipart [:map [:file reitit.ring.malli/temp-file-part]]}
|
||||||
:responses {200 {:body {:name string?, :size int?}}}
|
:responses {200 {:body [:map [:name string?] [:size int?]]}}
|
||||||
:handler (fn [{{{:keys [file]} :multipart} :parameters}]
|
:handler (fn [{{{:keys [file]} :multipart} :parameters}]
|
||||||
{:status 200
|
{:status 200
|
||||||
:body {:name (:filename file)
|
:body {:name (:filename file)
|
||||||
|
|
@ -52,14 +53,14 @@
|
||||||
|
|
||||||
["/plus"
|
["/plus"
|
||||||
{:get {:summary "plus with spec query parameters"
|
{:get {:summary "plus with spec query parameters"
|
||||||
:parameters {:query {:x int?, :y int?}}
|
:parameters {:query [:map [:x int?] [:y int?]]}
|
||||||
:responses {200 {:body {:total int?}}}
|
:responses {200 {:body [:map [: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"
|
:post {:summary "plus with spec body parameters"
|
||||||
:parameters {:body {:x int?, :y int?}}
|
:parameters {:body [:map [:x int?] [:y int?]]}
|
||||||
:responses {200 {:body {:total int?}}}
|
:responses {200 {:body [:map [:total int?]]}}
|
||||||
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
||||||
{:status 200
|
{:status 200
|
||||||
:body {:total (+ x y)}})}}]]]
|
:body {:total (+ x y)}})}}]]]
|
||||||
|
|
@ -68,7 +69,7 @@
|
||||||
;;:validate spec/validate ;; enable spec validation for route data
|
;;:validate spec/validate ;; enable spec validation for route data
|
||||||
;;:reitit.spec/wrap spell/closed ;; strict top-level validation
|
;;:reitit.spec/wrap spell/closed ;; strict top-level validation
|
||||||
:exception pretty/exception
|
:exception pretty/exception
|
||||||
:data {:coercion reitit.coercion.spec/coercion
|
:data {:coercion reitit.coercion.malli/coercion
|
||||||
:muuntaja m/instance
|
:muuntaja m/instance
|
||||||
:middleware [;; swagger feature
|
:middleware [;; swagger feature
|
||||||
swagger/swagger-feature
|
swagger/swagger-feature
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue