Fork me on GitHub
#reitit
<
2021-04-05
>
Janne Sauvala21:04:06

Hi 👋:skin-tone-2: can reitit validate parameter values specified by spec or malli? Is it possible to tell that the parameter should be int and also between values x and y? Or is this something that the handler needs to take care of? I know it can coerce the parameter to the type int but how about the later part 🙂

ikitommi13:04:29

hi. sure you can, for example with malli you can say [:int {:min 1, :max 100}].

ikitommi13:04:00

or [:and :int [:fn (fn [x] (>= 1 x 100)]]

ikitommi13:04:55

with spec i recall it’s: (s/int-in 1 100)

Janne Sauvala14:04:51

That worked beautifully! This reduces the amount of boilerplate code I need to write 🙂

Janne Sauvala14:04:38

My mistake was that I tried to use the validation like I saw it in the examples in Malli repo: {:path [:map [:quiz [:and int? [:> 6]]] [:option int?]]}. I think it worked somehow but the output error wasn’t so beautiful:

...
"message": "unknown error",
      "schema": "[:> 6]",
      "type": null,
      "value": 1,
      "in": [
        "quiz"
      ]
...

WonderLastking15:04:52

I also trying to validate form-params, but it seems I cannot make it work. May you have any examples?

ikitommi15:04:40

Have you looked at the tests @U5JD0DZPA?

WonderLastking06:04:39

wow, thanks again ikitommi! No I didn't check them. I will now 🙂

wombawomba23:04:06

Is there a way to make reitit.frontend.history not URL-encode a specific path parameter? I have a route like /foo/*bar, and I want to be able to use it to link to URLs like /foo/bar/baz.