javalin / javalin

A simple and modern Java and Kotlin web framework

Home Page:https://javalin.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Configure multiple OpenAPI files for the Swagger UI plugin in Javalin

marcelbaumann opened this issue · comments

I have a modular monolith application in Java. Each domain can provide a REST API to publish its services.
Being modular, the openAPI specification is generated per module using the Javalin openapi annotation processor and the file is stored in build/classes/java/main/openapi-plugin/openapi-default.json for each module. This is done through a multi-module gradle build file.

How should I configure the SwaggerUI plugin to aggregate all description files and publish them in Swagger?

As far as I know, you can have only one Swagger instance per application (this is not a problem for me).
Should I either use a configuration option (but I do not know which one) or use redoc tools to merge the configuration files in one specification and copy it to the right place (but it makes my gradle build more complex and needs a rename of the generated files).

I assume that for the copy task, I have to copy the openapi-default.json files for each module, rename them on the fly, copy them in the openapi-plugin directory of the application module and finally update the index file. Would that work?

The good practice how to do it could be added to the Javalin documentation, e.g. under openapi example.

Thanks in advance. I can test the suggested approach and provide feedback if desired.
(I could not find a hint in the documentation. I hope I did not miss something).

I found an issue 893 discussing a different problem.

Spring provides a configuration option for that aggregating multiple swagger specifications in the same swagger ui

Sincerely

There is .index file in openapi-plugin directory. You can list multiple files/versions there.

If you generate openapi files it can be like ...

@OpenApi(
        path = "/standalone",
        methods = HttpMethod.DELETE,
        versions = "v2",
        headers = { @OpenApiParam(name = "V2") }
)

so you will get 2 definitions default and v2 in you Swagger UI

The .index file is the solution for multiple files from multiple bounded domains. Great!

So I just extended the Gradle build file to copy all openapi after renaming the file to openapi- in the expected folder.

I update the .index file manually. Cool so I do not need to merge the specification files.

Thanks

Sorry, I missed that issue, because I lately muted this repository 😅 (I hate you @dependabot).

OpenAPI plugin is not a part of this repository - you can find it here:

So feel free to ask there in the future :)