This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-31
Channels
- # announcements (1)
- # aws (4)
- # babashka (40)
- # beginners (89)
- # calva (13)
- # cider (3)
- # clj-kondo (36)
- # cljdoc (16)
- # clojure (74)
- # clojure-boston (1)
- # clojure-dev (7)
- # clojure-europe (30)
- # clojure-new-zealand (1)
- # clojure-nl (17)
- # clojure-uk (5)
- # clojurescript (16)
- # core-async (9)
- # cursive (16)
- # datahike (3)
- # datalog (6)
- # datascript (7)
- # datomic (15)
- # emacs (38)
- # events (2)
- # figwheel-main (3)
- # fulcro (6)
- # google-cloud (18)
- # graalvm (6)
- # gratitude (1)
- # honeysql (1)
- # introduce-yourself (1)
- # jobs (1)
- # leiningen (5)
- # lsp (6)
- # malli (11)
- # meander (2)
- # off-topic (4)
- # re-frame (6)
- # reitit (8)
- # releases (2)
- # remote-jobs (3)
- # reveal (4)
- # shadow-cljs (200)
- # sql (8)
- # tools-deps (16)
Hi, I’ve converted to using Malli now for my REST JSON schema definition and so far it’s looking great. Quick question. I have a few enums in my schema, and I want to accept case insensitive input for some of these. So I have something like
(:foo [:enum {:decode/string 'str/upper-case} "BAR" "ZZZ"]
However, when I try this (with let’s say :foo "bar"
, I get a validation error. Is malli validating the value before decoding, and if so how do I allow either lower or upper case for input values?
Hmm. I think I’m properly providing coercion, but maybe I’ve misconfigured it or something. Under (ring/router _ {options}
, I have
:coercion (reitit.coercion.malli/create
{;; 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
;; strip-extra-keys (effects only predefined transformers)
:strip-extra-keys true
;; add/set default values
:default-values true
;; malli options
:options nil})
..but I don’t think the coercion is being applied.e.g. when I print the data in my ring handler, the enum fields I defined in malli are coming up as #object[clojure.lang.AFunction$1 0xe1da5b0 "clojure.lang.AFunction$1@e1da5b0"]
and so on - looks like the coercion isn’t being applied. I have just tried to explicitly set the coercion in the route in question as well (i.e. like this:
:post {:name ::create-foo
:coercion reitit.coercion.malli/coercion
:handler h/create-foo!
:parameters {:body requests/foo}
:summary "Create a new foo."}}]
But same result.I think it may be that my enums are not being transformed. I can see how to add a transformation to a direct malli/decode call (e.g. (m/encode int? 42 mt/string-transformer)
, as per documentation at https://github.com/metosin/malli#value-transformation, but I’m not sure how to define such a transformation as part of my ring spec. I think I’m getting there but I’m not there yet!
I sorted this out. As with so many problems that baffle us, the root cause of the problem was somewhere other than where I was focussing.
Does metosin/reitit-sieppari {:mvn/version "0.5.15"} only support clj? It seems so, though i don't clearly see why it can't be cljc ... https://github.com/metosin/reitit/blob/master/modules/reitit-sieppari/src/reitit/interceptor/sieppari.clj likely there is a reason.