I’m looking at reitit.frontend.controllers — is there a way to “hang” some data to the match object? Or are the start/stop functions only for side effects?
Looking at the code, it seems not.
I’d look at the identity
function, it takes a match and returns an arbitrary value, so a good place to hook in some extra data before it gets passed to start/stop
Apply-controllers is also just a 50 lines of code and you are calling it from your route change handler, you could just call your own code from the same place, no need to use controllers for this.
@juhoteperi yeah this is what I ended up doing. Literally 2 lines of code 😄
1👍@ikitommi i solved the problem, one coercion wasn’t working well: (schema/constrained (schema/pred decimal?) #(> % 0M))
, i am not sure why. i changed (schema/pred decimal?)
to java.lang.BigDecimal
and it started to behave better.
now i have a different problem: validation and coercion work for the request but not the response and i suspect this is the culprit:
(def reitit-coercion
(reitit.coercion.schema/create
(assoc-in reitit.coercion.schema/default-options
[:matchers :body :formats "application/json"]
(some-fn amount-matcher
date-matcher
schema-tools.coerce/+json-coercions+
schema.coerce/keyword-enum-matcher
schema.coerce/set-matcher))))
i don’t know if this is the correct way to “extend” the default coercion. what i want is to register coercions for BigDecimals and java.time.LocalDate.
the schemas are:
(def Amount (schema/constrained java.math.BigDecimal #(> % 0M)))
(def Date java.time.LocalDate)
and the corresponding matchers:
(defn amount-matcher [schema]
(when (and (instance? schema.core.Constrained schema)
(= (.schema schema) java.math.BigDecimal))
bigdec))
(defn date-matcher [schema]
(when (= schema java.time.LocalDate)
#(java.time.LocalDate/parse %)))
Is there a way to have optional query parameters when coercing with
clojure.spec
? I have the following, but the request fails if parameters are missing:
{:get {:parameters {:query {:limit int?
:offset int?}}
Edit: Nevermind, I solved it by using your `spec-tools.data-spec/opt`