This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-01
Channels
- # announcements (1)
- # babashka (73)
- # bangalore-clj (7)
- # beginners (295)
- # calva (128)
- # chlorine-clover (3)
- # cider (9)
- # cljsrn (10)
- # clojure (63)
- # clojure-europe (11)
- # clojurescript (1)
- # clojureverse-ops (3)
- # conjure (3)
- # emacs (7)
- # fulcro (13)
- # graalvm (8)
- # honeysql (16)
- # jobs-discuss (14)
- # malli (21)
- # meander (8)
- # onyx (1)
- # pathom (7)
- # portkey (2)
- # quil (3)
- # re-frame (4)
- # reagent (31)
- # reitit (2)
- # rewrite-clj (40)
- # shadow-cljs (29)
- # sql (20)
- # xtdb (13)
Hi there, I’m trying to add a malli transformer for rest responses to reitit but not having much luck. Have tried a few things but not yet getting anywhere. This is what I’ve arrived at so far:
(def sanatize
{:compile
(fn [schema x]
(println schema x)
identity)})
(def response-transformer-provider
(reify reitit.coercion.malli/TransformationProvider
(-transformer [_ {:keys [strip-extra-keys default-values]}]
(mt/transformer
(mt/transformer
{:default-decoder sanatize
:default-encoder sanatize})
;; {:decoders {:map add-defaults}
;; :encoders {:map add-defaults}})
(mt/default-value-transformer)))))
(defn router []
(reitit.ring/router
[
["/v1" {:middleware [auth/auth-middleware]}
["/x"
["/y" api.y/y-endpoint]]]
{:exception pretty/exception
:data {:muuntaja m/instance
:coercion (reitit.coercion.malli/create
{:transformers {:body {:default reitit.coercion.malli/default-transformer-provider
:formats {"application/json" reitit.coercion.malli/json-transformer-provider}}
:string {:default reitit.coercion.malli/string-transformer-provider}
:response {:default response-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
;; validate request & response
:validate true
;; top-level short-circuit to disable request & response coercion
:enabled true
;; strip-extra-keys (effects only predefined transformers)
:strip-extra-keys true
;; add/set default values
:default-values true
;; malli options
:options nil})
:middleware [
;; query-params & form-params
parameters/parameters-middleware
;; content-negotiation
muuntaja/format-negotiate-middleware
;; encoding response body
muuntaja/format-response-middleware
;; exception handling
exception-middleware
;; decoding request body
muuntaja/format-request-middleware
;; coercing response bodys
coercion/coerce-response-middleware
;; coercing request parameters
coercion/coerce-request-middleware
;; multipart
multipart/multipart-middleware]}}))
I’m expecting a printout of the schema