Happy to shove my code up onto a branch, if anyone has a second to look.
I see that reitit's multipart
mw ns has some coercion and swagger things happening internally, but none of that implies it doesn't work without extra dependencies: https://github.com/metosin/reitit/blob/0ecc2fb9a7c5d93f2bb7582fbdedf75e8dc8e484/modules/reitit-middleware/src/reitit/ring/middleware/multipart.clj#L35
Adjacent question: Does anyone know if there's any difference between middleware supplied to reitit.ring/ring-handler
and middleware supplied to reitit.ring/router
? (I'm only supplying middleware to ring-handler
at the moment.)
:woman-facepalming:
Out of desperation, I carved all my middleware out of ring-handler
and shoved it into router
. Suddenly multipart is working. 😕
I'd love to know why. I can't see any difference between the two from my reading of the code and the docs, but I must be missing something obvious for such a drastic behaviour change.
So, with all the middleware in the router rather than the handler, things seem to be working even if I remove coercion and format negotiation (`muuntaja/format-negotiate-middleware` and coercion/coerce-request-middleware
). Though from looking at them, I'm guessing I probably want to keep them around regardless.
Now I have a slightly weird situation created by the fact that I "fake" HTTP verbs for PUT and DELETE using a hidden _method
field in my forms. The initial request comes in as a POST, and reitit barfs before it can get to the middleware which injects the appropriate verb based on _method
.
This situation almost feels like a catch-22 ^ ... Even if I could get the fn that transforms _method
into an HTTP verb, it would ideally happen _after_ :form-params
are extracted from the raw request, which is definitely long after the spec fails with a 405: Method not allowed
Okay, it's not quite the catch-22 I imagined, but it's close. If I add parameters-middleware
and multipart-middleware
back to ring-handler
(I have to leave them in the router
as well or that breaks) I can manage to catch a DELETE
sent across in a _method
hidden field. But because the multipart middleware is checking for :multipart
in the route parameters (https://github.com/metosin/reitit/blob/0ecc2fb9a7c5d93f2bb7582fbdedf75e8dc8e484/modules/reitit-middleware/src/reitit/ring/middleware/multipart.clj#L34) ... which of course isn't there because at this point the route is still a POST
(which doesn't even exist) ... it doesn't process the rest of the multipart middleware. The contents of the multipart form are then not pulled into :multipart-params
and the workaround in the docs then can't see the _method
hidden field: https://github.com/metosin/reitit/blob/master/doc/ring/RESTful_form_methods.md ... this is the workaround I'm using.
A functional, albeit kind of hideous, solution to this problem is to rely on the old-fashioned, no-spec, no-safety multipart params middleware straight out of ring ( ring.middleware.multipart-params/wrap-multipart-params
) for the RESTful/HTTP verb form method stuff in the ring-handler
. Then carry on with the normal reitit multipart middleware in the router
. Kind of awful, but it works and it's still infinitely better than trying to puzzle out where in the chain of middleware calling other middleware I was doing it the Ring way.
Let me know if I should be submitting a PR to fix this doc: https://github.com/metosin/reitit/blob/master/doc/ring/RESTful_form_methods.md ... I think everyone will run into this issue if they try to use the reitit middleware chain with Rails-style multipart forms.
Good morning! I'd like to coerce an HTTP query parameter into an OffsetDateTime
instance. However, I fail to find a working example. Any tips? (I wish to use Prismatic Schema.)
Hello! I was wondering if there is some library or tooling in place already which can generate reitit routes and the content negotiation specs given an OpenAPI 3 definition? I’m working on something for my project but wanted to know if someone has been at it already? 😄
I know of https://github.com/juxt/apex but seems to be in alpha an does quite a lot of things, was looking for something more minimal hopefully
@rahul080327 would love to see such a tool. I think the biggest thing is the JSON Schema -> schema|spec|malli converter. Otherwise, quite simple mapping. Or add a JSON Schema coercion impl to reitit
also, swapping the swagger2 -> openapi3 would be good. Don't have time, contributions to both most welcome
Great to know json Schema coercion exists already! I’ll see if I can pull out a generic enough lib from my tinkering, I really like reitit and would love a spec first impl. Thanks @ikitommi 🙏:skin-tone-3:
Its slowly shaping up! 😄
chose to go with malli, much simpler generation 😄
👍
by adding, I meant creating - doesn't exist yet, but doable :)
Got it!