swagger-uispringdoc

Explicitly define which groups to be rendered on swagger-ui


I am working on a spring boot 3.1.4 (java 17) project with the following dependency:

<dependency>
      <groupId>org.springdoc</groupId>
      <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
      <version>2.2.0</version>
</dependency>

I create through configuration files the OpenAPI definition and 5 GroupedOpenApi beans. I also use some annotations to enrich my OpenAPI with operations and schemas.

I use both Redoc (static html template) and Swagger UI (from the above dependency). Redoc is for public / external use and Swagger UI for internal.

So far so good, especially for Redoc, since I have a separate html template per group.

What I want is to render only the 3 out of 5 GroupedOpenApi defined beans in the Swagger UI dropdown. I can't remove or make conditional the other 2 since they are used from Redoc.

I tried the following:

  1. To disable all of the GroupedOpenApi using the springdoc.api-docs.groups.enabled property but after some investigation this property does not exist anymore -> Raised a documentation issue
  2. To explicitly define the springdoc.swagger-ui.urls[] but it appends instead of overriding
  3. To manually set the urls in AbstractSwaggerUiConfigProperties upon server startup (postConstruct of the application) and with a request filter (before and after the http request to /swagger-ui/index.html) but it still renders all the 5 GroupedOpenApi

Thanks in advance


Solution

  • I solved the issue by creating a simple swagger-config.json which includes only the swagger-ui.urls[] that I want and configured in application.yml the property springdoc.swagger-ui.configUrl to point to my file