Fork me on GitHub
#reitit
<
2021-12-23
>
Yehonathan Sharvit09:12:01

A question related to how reitit generates swagger HTML page and data. Is it possible to specify a schema for the request body and to support "application/edn" as a parameter content type ?

Yehonathan Sharvit09:12:15

I tried different thing but I couldn't make it work

Yehonathan Sharvit09:12:17

When I enter a EDN piece of data in the swagger UI, the "Execute" button seems to be blocked

Yehonathan Sharvit09:12:32

It seems that having a schema per media type is a feature of Swagger v3.0 From https://swagger.io/docs/specification/describing-request-body/

OpenAPI 3.0 uses the requestBody keyword to distinguish the payload from parameters (such as query string). The requestBody is more flexible in that it lets you consume different media types, such as JSON, XML, form data, plain text, and others, and use different schemas for different media types

Yehonathan Sharvit09:12:44

Unfortunately reitit supports only swagger 2 for now and there is already a Github issue for adding Swagger 3 support https://github.com/metosin/reitit/issues/8

Yehonathan Sharvit09:12:53

I guess I was able to answer my question by myself

Yehonathan Sharvit09:12:07

Thank you for your attention 😜

Yehonathan Sharvit09:12:20

But I still have a question: what if If want only to support "application/edn" content type? Is it supported by reitit?

ikitommi10:12:13

@viebel yes, currently, you’ll need to mount a custom :muuntaja into route data, with just application/edn supported. Can be at top-level or just for some routes. The Swagger UI had a bug related to malforned JSON (e.g. EDN) in the body-form, I think it’s fixed in the latest versions.

ikitommi10:12:55

you can also just annotate any an endpoint with :swagger {:produces #{"application/edn"}} to hint that it only takes edn. doesn’t effect the actual decoding, just an ui-hint.

ikitommi10:12:09

Full support for OpenAPI 3.0 is… on the backlog, not even a big thing, just not implemented.

Yehonathan Sharvit10:12:57

@ikitommi This is what I did but when I press the "Execute button" nothing happens. I use [metosin/ring-swagger-ui "4.0.0"]. Does it contain the Swagger UI bug fix?

ikitommi10:12:43

check out the console, and follow the issues on the swagger-ui repo.

ikitommi10:12:05

I’ve seen that bug too, pretty sure it was fixed into some version.

Yehonathan Sharvit10:12:12

Nothing in the browser console. Have you seen that?

ikitommi10:12:07

sorry, don’t have time to investigate, heading to holidays. hopefully you’ll find a resolution for that.

Yehonathan Sharvit10:12:57

The link I shared is a comment of yours saying that you experienced the bug.

Yehonathan Sharvit10:12:09

No need to investigate.

Yehonathan Sharvit10:12:15

Enjoy your holiday

ikitommi10:12:29

will do, thanks!

Yehonathan Sharvit10:12:51

When I add a : between the keys and the values (making it a valid JSON), the Execute button works

ikitommi10:12:18

We’ll (at Metosin) will re-visit our open source strategy, many libs haven’t got the attention they would deserve in 2021, reitit included. This was not planned, people have just been too busy with client projects and COVID puts a strain on the work/life balance. Will most likely deprecate some old libs and focus on the relevant ones (reitit included). Also, lot’s of new ideas, but need to find time to work on those. PRs always most welcome 🙂

🙏 6
❤️ 7
Yehonathan Sharvit10:12:25

What Metosin brings is already awesome. But the more you consume it, the more the appetite grows.

dharrigan11:12:23

yes, reitit is my go-to, along with malli and so on.