reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
dharrigan 2021-01-17T13:41:20.007900Z

I'm wondering if there is a bit of irregularity in the encoding of parameters. Everything is grouped under :parmeters, such as {:parameters {:body, {:parameters :path, {:parameters :query, except the &amp; parameters to the ? query, which ends up in :params and {:query-params, i.e., for <http://foo?id=2020&amp;limit=25&amp;page=0>

dharrigan 2021-01-17T13:41:44.008300Z

:parameters {:query {:id "2020"}},
 :params {"id" "2020",
          "limit" "25",
          "page" "0"},

dharrigan 2021-01-17T13:42:50.009700Z

notice that the id appears in both :parmeters :query, and :params, however in :parameters :query, whatever coercion has to be applied, has been applied (but not to params)

dharrigan 2021-01-17T13:43:39.010100Z

I would have expected this

dharrigan 2021-01-17T13:44:19.010800Z

:parameters {:query {:id "2020"
                      :limit 25
                      :page 0}},
 :params {"id" "2020",
          "limit" "25",
          "page" "0"},

dharrigan 2021-01-17T13:47:02.011500Z

oh wait, I think I get it

dharrigan 2021-01-17T13:47:52.011700Z

ahhhh

dharrigan 2021-01-17T13:47:58.011900Z

it's controlled by the spec!

dharrigan 2021-01-17T13:48:18.012400Z

so whatever is spec'ed out and applied to the route, it'll end up in the parameters map

dharrigan 2021-01-17T13:48:19.012600Z

gotcha

dharrigan 2021-01-17T13:48:35.012900Z

makes sense, and is fantastic!

đź‘Ť 1
ikitommi 2021-01-17T16:12:11.016400Z

@paulbutcher would be great if someone had time to re-package the relevant middleware from ring-defauts into reitit-middleware. There are multiple enhancement issues for adding common stuff like cors, security, …). The design question is: how should those be configured? Using route data? Using ring middleware options map? using options map to create a middleware instance?

ikitommi 2021-01-17T16:17:08.021200Z

for reitit 1.0.0 I would like to change all reitit middleware into functions that take no args or options map and return an Middleware instance. Separating the configuration and mounting makes things much easier to understand and allows one to build a single application-scoped configuration.

đź‘Ť 1
ikitommi 2021-01-17T16:19:01.023300Z

@max.r.rothman Swagger 2.0 doesn’t understand things like oneOf or anyOf. OpenAPI 3.0 would handle those better, not sure if there are mapping in spec-tool for multi-methods. PRs welcome for those.

Max 2021-01-17T16:20:15.023500Z

I thought that reitit’s swagger integration doesn’t support openapi 3.0?

Max 2021-01-17T16:21:04.023700Z

So that means there’s no way to model polymorphic structures in swagger 2.0?

ikitommi 2021-01-17T16:21:47.023900Z

it doesn’t, but both Plumatic & Spec have (some level of) openapi-support now, so would be possible to add support for reitit. would have use for that (but no time to implement)

ikitommi 2021-01-17T16:21:51.024100Z

no, there is not.

ikitommi 2021-01-17T16:22:13.024300Z

https://github.com/OAI/OpenAPI-Specification/issues/57

ikitommi 2021-01-17T16:23:30.024600Z

there is a dispatch property for simple cases, but as multi-specs can dispatch on anything, it only works for simple cases.

2021-01-17T18:09:00.026400Z

Hi all. Although this is more of a question for Muutaja I believe, but I guess here are people that have knowledge of both reitit and Muuntaja... Anyway, anyone knows how could one force Reitit (with Muuntaja setup) to pretty format response JSON/EDN?

2021-01-17T18:10:04.026800Z

By default, JSON is produced in compact form

dharrigan 2021-01-17T18:14:34.027100Z

Is this for a consumer, or for a human?

2021-01-17T18:15:39.028500Z

hmm, i mean, JSON will be consumed by frontend, but for development environment, and debugging purposes, it is good to sacrifice speed/compactness for readability

dharrigan 2021-01-17T18:16:02.028900Z

I normally don't care to make it pretty (to save on a few extra bytes). If I want to view it nicely, I just use httpie or pipe the output to jq on the commandline, in the browser, there are numerous plugins to a browser to prettify the output

dharrigan 2021-01-17T18:16:39.029300Z

httpie is very very good for viewing the output, it'll prettify and colourise as well

dharrigan 2021-01-17T18:16:53.029900Z

http :8080/my/funky/api

2021-01-17T18:17:18.030400Z

yeah, just wanted to make sure that any frontend developer don't need to use any extra tools/plugins, just open Network tab in chrome inspector, and see it pretty immediately

2021-01-17T18:17:32.030900Z

ok, i guess the answer is no..no biggie anyway

dharrigan 2021-01-17T18:17:49.031400Z

Perhaps your frontend dev would use postman or summat to explore APIs anyway

dharrigan 2021-01-17T18:18:07.031800Z

or if they are using graphql, it's built in to the development on a different port

dharrigan 2021-01-17T18:18:19.032100Z

that's what our dev frontend use

dharrigan 2021-01-17T18:18:33.032500Z

combination of postman, or graphql stuff running on the client.

dharrigan 2021-01-17T18:19:03.032900Z

I wouldn't spend cycles on the backend just to make the output nicer for the frontend UIs

2021-01-17T18:20:22.033900Z

ok.....maybe will use some custom middleware if I really need this

dharrigan 2021-01-17T18:51:05.035400Z

I guess it's feasible, muuntaja can be supplied with of options that would influence cheshire, perhaps try passing in :pretty true as an option to the configuration map for muuntaja

dharrigan 2021-01-17T18:51:20.035700Z

report back when you get it to work 🙂

Max 2021-01-17T19:07:05.035800Z

Thanks for the info, this is super helpful!

Max 2021-01-17T19:09:55.036700Z

Is there any way to get reitit/spec-tools to generate swagger docs using allOf and discriminator?

dharrigan 2021-01-17T19:16:20.037700Z

In fact it should be as simple as something along the lines of (from top of my head, not tested) :muuntaja (m/create (merge m/default-options {:formats {:encoder-opts {:pretty true}}}))

dharrigan 2021-01-17T20:09:42.037900Z

here you go

dharrigan 2021-01-17T20:09:45.038100Z

:muuntaja (m/create (-&gt; m/default-options
                                   (update-in [:formats "application/json"]
                                              merge {:encoder-opts {:pretty true}})))

dharrigan 2021-01-17T20:09:54.038300Z

That will prettify the output

đź‘Ť 1