mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 00:41:12 +00:00
sample of edn-transformer
This commit is contained in:
parent
6d9d7a09b0
commit
c3db7fbc3f
2 changed files with 23 additions and 8 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
(defproject ring-example "0.1.0-SNAPSHOT"
|
(defproject ring-example "0.1.0-SNAPSHOT"
|
||||||
:description "Reitit Ring App with Swagger"
|
:description "Reitit Ring App with Swagger"
|
||||||
:dependencies [[org.clojure/clojure "1.10.0"]
|
:dependencies [[org.clojure/clojure "1.10.0"]
|
||||||
[metosin/jsonista "0.2.6"]
|
|
||||||
[ring/ring-jetty-adapter "1.7.1"]
|
[ring/ring-jetty-adapter "1.7.1"]
|
||||||
[metosin/reitit "0.6.0"]
|
[metosin/reitit "0.6.0"]
|
||||||
[metosin/ring-swagger-ui "5.0.0-alpha.0"]]
|
[metosin/ring-swagger-ui "5.0.0-alpha.0"]]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
(ns example.server
|
(ns example.server
|
||||||
(:require [reitit.ring :as ring]
|
(:require [jsonista.core :as j]
|
||||||
[reitit.coercion.malli]
|
[reitit.ring :as ring]
|
||||||
|
[reitit.coercion.malli :as rcm]
|
||||||
[reitit.openapi :as openapi]
|
[reitit.openapi :as openapi]
|
||||||
[reitit.ring.malli]
|
[reitit.ring.malli]
|
||||||
[reitit.swagger :as swagger]
|
[reitit.swagger :as swagger]
|
||||||
|
|
@ -11,9 +12,9 @@
|
||||||
[reitit.ring.middleware.exception :as exception]
|
[reitit.ring.middleware.exception :as exception]
|
||||||
[reitit.ring.middleware.multipart :as multipart]
|
[reitit.ring.middleware.multipart :as multipart]
|
||||||
[reitit.ring.middleware.parameters :as parameters]
|
[reitit.ring.middleware.parameters :as parameters]
|
||||||
; [reitit.ring.middleware.dev :as dev]
|
; [reitit.ring.middleware.dev :as dev]
|
||||||
; [reitit.ring.spec :as spec]
|
; [reitit.ring.spec :as spec]
|
||||||
; [spec-tools.spell :as spell]
|
; [spec-tools.spell :as spell]
|
||||||
[ring.adapter.jetty :as jetty]
|
[ring.adapter.jetty :as jetty]
|
||||||
[muuntaja.core :as m]
|
[muuntaja.core :as m]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
|
|
@ -64,6 +65,14 @@
|
||||||
["/math"
|
["/math"
|
||||||
{:tags ["math"]}
|
{:tags ["math"]}
|
||||||
|
|
||||||
|
["/edn"
|
||||||
|
{:post {:parameters {:body [:map [:json-string
|
||||||
|
{:decode/string #(j/read-value % j/keyword-keys-object-mapper)}
|
||||||
|
[:map [:id :int]]]]}
|
||||||
|
:handler (fn [request]
|
||||||
|
{:status 200
|
||||||
|
:body (-> request :parameters :body)})}}]
|
||||||
|
|
||||||
["/plus"
|
["/plus"
|
||||||
{:get {:summary "plus with malli query parameters"
|
{:get {:summary "plus with malli query parameters"
|
||||||
:parameters {:query [:map
|
:parameters {:query [:map
|
||||||
|
|
@ -94,8 +103,15 @@
|
||||||
;;: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.malli/create
|
:data {:coercion (rcm/create
|
||||||
{;; set of keys to include in error messages
|
;; override default transformers
|
||||||
|
{:transformers {:body {:default rcm/default-transformer-provider
|
||||||
|
:formats {"application/json" rcm/json-transformer-provider
|
||||||
|
"application/edn" rcm/string-transformer-provider}}
|
||||||
|
:string {:default rcm/string-transformer-provider}
|
||||||
|
:response {:default rcm/default-transformer-provider
|
||||||
|
:formats {"application/json" rcm/json-transformer-provider}}}
|
||||||
|
;; set of keys to include in error messages
|
||||||
:error-keys #{#_:type :coercion :in :schema :value :errors :humanized #_:transformed}
|
:error-keys #{#_:type :coercion :in :schema :value :errors :humanized #_:transformed}
|
||||||
;; schema identity function (default: close all map schemas)
|
;; schema identity function (default: close all map schemas)
|
||||||
:compile mu/closed-schema
|
:compile mu/closed-schema
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue