Fork me on GitHub

I’m using Ring, and I’m looking to declare my routes and handlers separately (as in, I would like to have a routes structure with no handlers do something like (add-handlers route handlers)). Is there a straightforward way to do this?


Guess I’ll just go with making sure each endpoint has a :name and doing a postwalk to add the appropriate handlers 🙂


Follow-up question, if I have a map of routes, is there any utility in reitit that I can use to flatten it? I don’t want to create a router, I just want to iterate over the routes


Seems like (reitit.impl/resolve-routes my-routes (reitit.core/default-router-options) does the trick 🙂

Matheus Moreira19:06:47

hello, people! can someone help me figure out why an error happens?

    "schema": {
        "action": "(conditional patrulleros.onering.http/fn--30490 {:type (eq :spaces-money-transfer), :amount (constrained java.math.BigDecimal patrulleros.onering.http/fn--30487), :reference-text Str, :source-space-id Uuid, :target-space-id Uuid})",
        "trigger": "(conditional patrulleros.onering.http/fn--30493 {:type (eq :calendar), :start-date Inst, (optional-key :end-date) Inst, (optional-key :frequency) (enum \"biweekly\" \"weekly\" \"daily\" \"monthly\")})"
    "errors": {
        "action": "(not (patrulleros.onering.http/fn--30490 a-clojure.lang.PersistentHashMap))",
        "trigger": "(not (patrulleros.onering.http/fn--30493 a-clojure.lang.PersistentHashMap))"
    "type": "reitit.coercion/request-coercion",
    "coercion": "schema",
    "value": {
        "action": {
            "amount": 10,
            "type": "spaces-money-transfer",
            "source-space-id": "937bcca6-d482-4b93-9fa1-540773eb9ede",
            "reference-text": "reftext",
            "target-space-id": "52dbc61b-1409-46f6-bad9-5136eeab913f"
        "trigger": {
            "end-date": "2020-12-15",
            "frequency": "monthly",
            "type": "calendar",
            "start-date": "2020-06-15"
    "in": [

Matheus Moreira19:06:11

if i understood correctly, the error says that action and trigger are not maps but they are sent in the request as a json value where both properties are json objects.

Matheus Moreira19:06:53

i use schema for validation and coercion.

Matheus Moreira19:06:06

request: curl -X PUT --data-binary @rule.json -H "user-id: 1368d863-c5e6-40e4-9c74-9e7e1aedcb61" -H "Content-Type: application/json" -H "Accept: application/json"


You could run the schema coercion from repl to see why the s/conditional fails.


what is the guard function in those conditional?


the code is in reitit.coercion.schema.

Matheus Moreira15:06:34

@U055NJ5CC 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.

Matheus Moreira15:06:01

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
  (assoc-in reitit.coercion.schema/default-options
   [:matchers :body :formats "application/json"]
    (some-fn amount-matcher

Matheus Moreira15:06:58

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.

Matheus Moreira15:06:21

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))

(defn date-matcher [schema]
  (when (= schema java.time.LocalDate)
    #(java.time.LocalDate/parse %)))