reitit
reitit copied to clipboard
Making alterations to a response schema produces an error relating to the request object
Steps to reproduce:
Run the code provided in the gist below [1].
The two endpoints are identical save for the difference between the schemas for response bodies. /success
declares that an object should be returned while /failure
declares that a bool should be returned. Both are valid JSON so I would expect them both to produce a 200 success response, but /failure
fails with a 400 error, and complains about an invalid request body.
Responses are reproduced below:
/* for /success endpoint*/
{
"success": true
}
/* for /failure endpoint */
{
"schema": {
"a": "java.lang.String"
},
"errors": "(not (map? nil))",
"type": "reitit.coercion/request-coercion",
"coercion": "schema",
"value": null,
"in": [
"request",
"body-params"
]
}
[1] https://gist.github.com/marrs/bded1dfa0b97893610b48b181b6fb50a
Hi. I think the merged routers is not right: you should merge both routes and route data. Instead of merging routers, I propose you either:
-
create two separate
ring/ring-router
and combine them withring/routes
(e.g. linear scan over the two handlers) -
merge just the route data (recommended):
(def dummy-routes
[["/dummy" (constantly {:status 200, :body "dummy"})]])
(def api-routes
[["/api" (constantly {:status 200, :body "api"})]])
(def ring-handler
(ring/ring-handler
(ring/router
[dummy-routes api-routes]
{:data ...})
(ring/routes ...)))