👋 hello! I’m building a Web API with Reitit (via Kit) and as soon as I specified response schemata in my routes response validation started working, which was great! However I’m now adding schemata for requests and while the response coercion seems to be working correctly, and the requests look correct in the Swagger UI, I don’t seem to have any request validation happening. Can anyone suggestion one or two things to check to enable request validation?
Just adding this in case anyone stumbles on this in future:
it's the default :strip-extra-keys true when configuring coercion.
https://cljdoc.org/d/metosin/reitit/0.7.0-alpha7/doc/coercion/malli#configuring-coercion
Thank you!
Background: I’m a new user of Reitit, via a new project I’ve created via Kit. I’ve been away from Clojure Web dev for a few years and I’d used Compojure back in the day. Reitit seems really cool!
Never mind! Turns out it is working!
I was misled (by myself) because while Reitit does seem to be validating JSON request bodies against my schema, it’s not catching all the cases I was hoping it might. For example: when I send a request with an unsupported Content-Type I figured Reitit would automatically return a 415 Unsupported Media Type response. But it seems it does not. That is mildly surprising.
Here’s something else that I find confusing.
I have a request body schema that is a Malli :map with the option :closed true. I’ve confirmed this works as expected by testing it with malli.core/validate etc.
When I send a request body that has an allowed key but an invalid value, I get back an error as I’d expect:
curl -i --json '{"name": 1}' localhost:8000/api/projects/
HTTP/1.1 400 Bad Request
{"value":{"name":1},"type":"reitit.coercion/request-coercion","coercion":"malli","in":["request","body-params"],"humanized":{"name":["should be a string"]}}
which is excellent!
However, when I send an extra key, I would expect an error response in that case as well, because the map is closed. But no:
curl -i --json '{"name": "Arthur Dent", "cheese": "Japanese Sage-Dombi"}' localhost:8000/api/projects/
HTTP/1.1 201 Created
That should have been rejected because of the additional key cheese — right?
What am I missing?
Thanks![SOLVED]
Hi, when using reitit ring-handler with :inject-match? true, the fragment data is not passed to the match.
I've noticed that if I have :href "/path#test" in the match I will have :fragment "test", but if I manually paste the url in the browser as /path#test the match data is comming with :fragment nil.
Do I need some additional setting/parsing for it?