Fork me on GitHub
#reitit
<
2021-01-17
>
dharrigan13:01:20

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 & parameters to the ? query, which ends up in :params and {:query-params, i.e., for

dharrigan13:01:44

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

dharrigan13:01:50

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)

dharrigan13:01:39

I would have expected this

dharrigan13:01:19

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

dharrigan13:01:02

oh wait, I think I get it

dharrigan13:01:58

it's controlled by the spec!

dharrigan13:01:18

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

dharrigan13:01:35

makes sense, and is fantastic!

đź‘Ť 3
ikitommi16:01:11

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

ikitommi16:01:08

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.

đź‘Ť 3
ikitommi16:01:01

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

Max16:01:15

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

Max16:01:04

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

ikitommi16:01:47

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)

ikitommi16:01:51

no, there is not.

ikitommi16:01:30

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

Max19:01:05

Thanks for the info, this is super helpful!

Max19:01:55

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

vmarcinko18:01:00

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?

vmarcinko18:01:04

By default, JSON is produced in compact form

dharrigan18:01:34

Is this for a consumer, or for a human?

vmarcinko18:01:39

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

dharrigan18:01:02

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

dharrigan18:01:39

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

dharrigan18:01:53

http :8080/my/funky/api

vmarcinko18:01:18

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

vmarcinko18:01:32

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

dharrigan18:01:49

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

dharrigan18:01:07

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

dharrigan18:01:19

that's what our dev frontend use

dharrigan18:01:33

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

dharrigan18:01:03

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

vmarcinko18:01:22

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

dharrigan18:01:05

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

dharrigan18:01:20

report back when you get it to work 🙂

dharrigan19:01:20

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

dharrigan20:01:45

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

dharrigan20:01:54

That will prettify the output

đź‘Ť 3