reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
Steven Deobald 2021-01-29T00:00:39.022Z

Happy to shove my code up onto a branch, if anyone has a second to look.

Steven Deobald 2021-01-29T00:01:55.022700Z

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

Steven Deobald 2021-01-29T02:12:26.024Z

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.)

Steven Deobald 2021-01-29T02:14:29.024200Z

:woman-facepalming:

Steven Deobald 2021-01-29T02:15:54.024900Z

Out of desperation, I carved all my middleware out of ring-handler and shoved it into router. Suddenly multipart is working. 😕

Steven Deobald 2021-01-29T02:16:35.025600Z

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.

Steven Deobald 2021-01-29T02:41:48.027200Z

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.

Steven Deobald 2021-01-29T02:43:32.029Z

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.

Steven Deobald 2021-01-29T03:23:25.030800Z

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

Steven Deobald 2021-01-29T04:00:26.034600Z

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.

Steven Deobald 2021-01-29T04:10:30.037700Z

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.

Steven Deobald 2021-01-29T05:16:10.038700Z

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.

Lauri Lehmijoki 2021-01-29T05:53:39.040900Z

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.)

lispyclouds 2021-01-29T17:39:09.045Z

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? 😄

lispyclouds 2021-01-29T17:41:23.047100Z

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

ikitommi 2021-01-29T17:43:52.050800Z

@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

ikitommi 2021-01-29T17:44:54.052300Z

also, swapping the swagger2 -> openapi3 would be good. Don't have time, contributions to both most welcome

lispyclouds 2021-01-29T17:46:35.054700Z

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:

lispyclouds 2021-01-30T10:56:20.056500Z

Its slowly shaping up! 😄

lispyclouds 2021-01-30T10:56:58.056900Z

chose to go with malli, much simpler generation 😄

ikitommi 2021-02-02T14:07:25.070400Z

👍

ikitommi 2021-01-29T17:48:12.055800Z

by adding, I meant creating - doesn't exist yet, but doable :)

lispyclouds 2021-01-29T17:48:24.056200Z

Got it!