Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended OpenApiPlugin, to support multiple options #1117

Merged
merged 3 commits into from Nov 18, 2020

Conversation

sauterl
Copy link
Contributor

@sauterl sauterl commented Nov 18, 2020

This is a small addition to the OpenApiPlugin, enabling devs to have multiple concurrent OpenApi specifications, as originally in #1108

The addition has a rather simple approach: If OpenApiOptions differ in their path, they are added to be served concurrently, so now the OpenApiPlugin constructor accepts a variable amount of options:

val app = Javalin.create {
        val fullOpenApiOptions = OpenApiOptions(Info().version("1.0").description("My Application"))
                .path("/swagger-docs")
                .swagger(SwaggerOptions("/swagger").title("My Swagger Documentation"))
                .reDoc(ReDocOptions("/redoc", RedocOptionsObject(
                        hideDownloadButton = true,
                        theme = RedocOptionsTheme(
                                spacingUnit = 10,
                                isTypographyOptimizeSpeed = true
                        )
                )).title("My ReDoc Documentation"))
                .defaultDocumentation { documentation -> documentation.json<InternalServerErrorResponse>("500") }
        val itemsOnly = OpenApiOptions(Info().version("1.0").description("My Application"))
                .path("/swagger-docs-items")
                .swagger(SwaggerOptions("/swagger-items").title("My Swagger Documentation -- ITEMS only"))
                .defaultDocumentation { documentation -> documentation.json<InternalServerErrorResponse>("500") }
                .ignorePath("/users*").ignorePath("/users/*")
        it.registerPlugin(OpenApiPlugin(fullOpenApiOptions, itemsOnly))
    }

@tipsy
Copy link
Member

tipsy commented Nov 18, 2020

Nice, thank you @sauterl ! Could you fix the indentation changes?

@sauterl
Copy link
Contributor Author

sauterl commented Nov 18, 2020

Thanks for the quick reply @tipsy

My apologies, the indentation should be fixed by now. If there are any questions / changes to be made, please let me know.

@tipsy
Copy link
Member

tipsy commented Nov 18, 2020

Looks fine to me. I believe there's another issue for this that was submitte some time ago. Let me see if I can find it.

@tipsy
Copy link
Member

tipsy commented Nov 18, 2020

This one @sauterl: #893

I guess your PR solves this use-case by using ignorePath ?

…MultiSwagger.kt

Co-authored-by: David <davidaase@hotmail.com>
@sauterl
Copy link
Contributor Author

sauterl commented Nov 18, 2020

Thanks @tipsy for finding the other issue, I have to admit that, due to the terminology of swagger docs and OpenApi Specifications (and everything in between), I did not see the #893 . However, as far as I can tell this would fix their issue as well.
Which adds upon the use cases this fix serves:

  • Having multiple versions of the API online and different specs (or swagger docs or OAS) for them
  • Having an "internal" and "external" API, each with their dedicated specs (as it is for our case).

Thanks again for the quick replies

@tipsy
Copy link
Member

tipsy commented Nov 18, 2020

Thanks again for the quick replies

You're very welcome, thank you too for your quick PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants