Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample of edn-transformer #614

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/ring-malli-swagger/project.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
(defproject ring-example "0.1.0-SNAPSHOT"
:description "Reitit Ring App with Swagger"
:dependencies [[org.clojure/clojure "1.10.0"]
[metosin/jsonista "0.2.6"]
[ring/ring-jetty-adapter "1.7.1"]
[metosin/reitit "0.6.0"]
[metosin/ring-swagger-ui "5.0.0-alpha.0"]]
Expand Down
30 changes: 23 additions & 7 deletions examples/ring-malli-swagger/src/example/server.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns example.server
(:require [reitit.ring :as ring]
[reitit.coercion.malli]
(:require [jsonista.core :as j]
[reitit.ring :as ring]
[reitit.coercion.malli :as rcm]
[reitit.openapi :as openapi]
[reitit.ring.malli]
[reitit.swagger :as swagger]
Expand All @@ -11,9 +12,9 @@
[reitit.ring.middleware.exception :as exception]
[reitit.ring.middleware.multipart :as multipart]
[reitit.ring.middleware.parameters :as parameters]
; [reitit.ring.middleware.dev :as dev]
; [reitit.ring.spec :as spec]
; [spec-tools.spell :as spell]
; [reitit.ring.middleware.dev :as dev]
; [reitit.ring.spec :as spec]
; [spec-tools.spell :as spell]
[ring.adapter.jetty :as jetty]
[muuntaja.core :as m]
[clojure.java.io :as io]
Expand Down Expand Up @@ -64,6 +65,14 @@
["/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"
{:get {:summary "plus with malli query parameters"
:parameters {:query [:map
Expand Down Expand Up @@ -94,8 +103,15 @@
;;:validate spec/validate ;; enable spec validation for route data
;;:reitit.spec/wrap spell/closed ;; strict top-level validation
:exception pretty/exception
:data {:coercion (reitit.coercion.malli/create
{;; set of keys to include in error messages
:data {:coercion (rcm/create
;; 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}
;; schema identity function (default: close all map schemas)
:compile mu/closed-schema
Expand Down