javalin / javalin-openapi

Annotation processor for compile-time OpenAPI & JsonSchema, with out-of-the-box support for Javalin 5.x, Swagger & ReDoc
https://github.com/javalin/javalin-openapi/wiki
Apache License 2.0
44 stars 17 forks source link

Multiple Swagger UI's cannot co-exist #161

Open sauterl opened 1 year ago

sauterl commented 1 year ago

There is currently two issues with multiple swagger UIs:

a) one has to create a sub-class of the plugin as otherwise javalin wouldn't register it (I will read upon that and mention it over at javalin. I guess there are plugins for which only a single instance should exist). b) this fails as both instances try to add the webjar GET handler.

The former can be counted as a minor inconvenience, the latter, however, is an easy fix which I will provide in due time.

dzikoysk commented 1 year ago

a) This is something I'd like to add to Javalin 6.x as I've already seen such issues with OpenApiPlugin in the past

Btw, I'm just curious, why would you need to serve 2 Swagger UIs? 🤔

sauterl commented 1 year ago

In our application we want to separate the internal and client-side openapi specs since third-party clients do not have to know about most of the internal calls. Yet, having openapi specs internally saves a lot of dev-time 😉 Side note: I purposely linked the openapi specs generated with this plugin.

dzikoysk commented 1 year ago

Ok, because I was wondering if versioned scheme with switch option in Swagger UI is not enough, but it sounds reasonable as well.

rvaidya commented 1 year ago

If you were to serve 2 Swagger UIs, how would you note which one a route is supposed to be documented in when adding the @OpenApi annotations?

This is also something that I'm looking to do - expose a public OpenApi endpoint with UIs for external clients and a separate internal set that requires auth to get to.

sauterl commented 1 year ago

We did so by excluding the routes in the swagger-ui they shouldn't appear. Since one of the two openapi definitions is a subset of the other one, it was fairly trivial to do the exclusion.

Since I'm on mobile, I cannot easily point you towards the relevant code, but your starting point could be our repo

dzikoysk commented 1 year ago

I'll keep this open, because we don't have built-in tools to support 2 standalone Swagger UIs. I'll keep this for Javalin 6.x as it'd require some breaking changes in current configs.