Fork me on GitHub
#reitit
<
2018-11-05
>
Hannu Hartikainen14:11:31

I noticed that if you use spec coercion in frontend you need to use spec records or it’s going to fail in production builds. I didn’t understand why.

Hannu Hartikainen14:11:11

(Production builds using shadow-cljs, probably optimized using Closure Compiler)

Hannu Hartikainen14:11:19

My use case: {:parameters {:path {:foo-id int?}}} (starts working with spec/int?)

socksy14:11:37

Hey, I'm having some trouble with getting immutant web serving the ring swagger endpoint created with (reitit.swagger/create-swagger-handler). If I run the handler, it works fine, producing a clojure/edn map. But I'm getting:

user=> 2018-11-05 15:49:33,697 [XNIO-4 task-6] ERROR io.undertow.request - UT005071: Undertow request failed HttpServerExchange{ GET /swagger.json request {Accept=[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8], Connection=[keep-alive], Accept-Language=[en-GB,en-US;q=0.8,en;q=0.5,de;q=0.3], Accept-Encoding=[gzip, deflate], DNT=[1], User-Agent=[Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0], Upgrade-Insecure-Requests=[1], Host=[localhost:3000]} response {Server=[undertow]}} 

java.lang.IllegalStateException: Can't coerce body of type class clojure.lang.PersistentArrayMap
In my middleware options I've got reitit.ring.coercion/coerce-response-middleware, but clearly this isn't the correct middleware to convert to JSON. Any clues for where I should be looking?

socksy14:11:41

err, probably more relevant is the following middleware I also have enabled:

muuntaja/format-negotiate-middleware
muuntaja/format-response-middleware
muuntaja/format-request-middleware

ikitommi18:11:11

@hannu.hartikainen if you can do a minimalistic repro, I investigate. the data-specs get compiled into Spec Records, but if that happens at runtime, it could be that the names are shortened and the type inferrer fails.

ikitommi18:11:57

shoudn’t happen that way…

ikitommi18:11:12

@socksy could be that the middleware stack is not in right order, here’s a working chain: https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj#L65-L80

ikitommi18:11:18

but if you have order [format-negotiate-middleware format-response-middleware format-request-middleware] it should be right. Muuntaja doesn’t encode the response body if there is already a Content-Type header is set, by some 3rd party middleware.

ikitommi18:11:08

from the upcoming middleware logger, should help to see what mws are doing (or not).

socksy19:11:58

Thanks for the reply, they were indeed that order. I ended up removing everything and taking the middleware from the luminus template, which I can document when I'm back at my computer tomorrow. Middleware logger sounds like a great thing

shaun-mahood22:11:20

I've switched my project over to using interceptors and was wondering if there's anything already made that can help with debugging - re-frame has a couple projects (https://github.com/flexsurfer/re-frisk and https://github.com/Day8/re-frame-10x) that I've used to help investigate my interceptors and it's been really useful.