Fork me on GitHub

So I’m using Reitit with Schema on the backend, and I noticed that Reitit seems to treat query params as an ‘open’ schema (i.e. it permits all keys not specified in the schema). This is a bit surprising to me because by default schemas are closed (to make a schema open, you need to add an entry like Keyword Any). Now, I’d really like the query parameters to be closed unless otherwise specified, so that any unexpected keys cause an error. How can I make this happen?


Okay, after digging around a bit in the Reitit code, I found that this behavior seems to be defined in Following that backwards it seems like supports an optional :parameter-coercion key that can be used to override this behavior..


So if I could get something like {:parameter-coercion (assoc reitit.coercion/default-parameter-coercion :query (reitit.coercion->ParameterCoercion :query-params :string true false))} passed to this function then that should do the trick.


…and it seems like if I put this into the opts key in the :compile in reitit.ring.coercion/coerce-request-middleware then it should get passed down to reitit.coercion/request-coercer. The main question remaining then, is how do I control what gets passed to the :compile method? don’t seem to explain this..


Alright, I figured it out 🙂 The following sentence in the docs made me realize I was supposed to put the custom :parameter/coercion config in the config sent to reitit.ring/router: > :compile expects a function of `route-data router-opts => ?IntoMiddleware`


Maybe the docs could be modified somehow to make this more clear? It’d also be helpful if there was an example illustrating the different ways to use middleware. Or maybe the docstring for the middleware should specify which parameters it supports?

👍 3

Tommi would probably say “please make a PR” 😉