javalin-openapi icon indicating copy to clipboard operation
javalin-openapi copied to clipboard

Multiple Swagger UI's cannot co-exist

Open sauterl opened this issue 2 years ago • 6 comments

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.

sauterl avatar Feb 20 '23 16:02 sauterl

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

dzikoysk avatar Feb 20 '23 16:02 dzikoysk

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.

sauterl avatar Feb 20 '23 16:02 sauterl

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

dzikoysk avatar Feb 20 '23 19:02 dzikoysk

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.

rvaidya avatar Apr 20 '23 16:04 rvaidya

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

sauterl avatar Apr 20 '23 16:04 sauterl

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.

dzikoysk avatar Apr 26 '23 15:04 dzikoysk