Skip to content

API Groups are no longer selectable in Swagger UI when using Spring MVC #1344

@adrian-haenni

Description

@adrian-haenni

Describe the bug
When upgrading in a Spring MVC configuration from version 1.5.10 to 1.5.12, the Swagger UI does not show the "Select a definition" drop down for GroupedOpenApi Beans anymore. I also noticed that the generated api-docs/swagger-config JSON is missing entries for the URLs of GroupedOpenApi's. When I enter the path of an API group directly into the "Explore" textfield, then it will be shown correctly. However, I expect that the "Select a definition" drop down should be shown instead of "Explore" textfield.

To Reproduce
I have the following configurations:

SwaggerOpenApiConfig.java

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"org.springdoc"})
@PropertySource("classpath:springdoc.properties")
@Import({org.springdoc.core.SpringDocConfiguration.class,
        org.springdoc.webmvc.core.SpringDocWebMvcConfiguration.class,
        org.springdoc.webmvc.core.MultipleOpenApiSupportConfiguration.class,
        org.springdoc.webmvc.ui.SwaggerConfig.class,
        org.springdoc.core.SwaggerUiConfigProperties.class,
        org.springdoc.core.SwaggerUiOAuthProperties.class,
        org.springdoc.core.SpringDocConfigProperties.class,
        org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration.class})
public class SwaggerOpenApiConfig {

    @Autowired
    OpenApiCustomiser openApiSortCustomiser;

    // FULL API

    @Bean
    public OpenAPI integrationAPI() {
        return new OpenAPI()
                .info(new Info().title("Integration API")
                        .description("The full REST interface for integration tasks")
                        .version("v1.0.0"))
                .components(new Components()
                        .addSecuritySchemes("api_auth",
                                new SecurityScheme()
                                        .type(SecurityScheme.Type.HTTP)
                                        .name("api_auth")
                                        .scheme("basic")
                                        .in(SecurityScheme.In.HEADER)
                                        .name("Authorization")))
                .addSecurityItem(new SecurityRequirement().addList("api_auth", Arrays.asList("read", "write")));
    }

    // API GROUPS

    @Bean
    public GroupedOpenApi groupFullOpenApi() {
        String[] packagesToScan = {"com.some.integration"};
        return GroupedOpenApi.builder()
                .packagesToScan(packagesToScan)
                .group("")
                .addOpenApiCustomiser(openApiSortCustomiser)
                .build();
    }

    @Bean
    public GroupedOpenApi groupAvailabilityOpenApi() {
        String[] packagesToScan = {"com.some.integration.availabilitychecker"};
        return GroupedOpenApi.builder()
                .packagesToScan(packagesToScan)
                .group("availability-checker")
                .addOpenApiCustomiser(openApiSortCustomiser)
                .build();
    }

    @Bean
    public OpenApiCustomiser sortTagsAlphabetically() {
        return openApi -> openApi.setTags(openApi.getTags()
                .stream()
                .sorted(Comparator.comparing(tag -> StringUtils.stripAccents(tag.getName())))
                .collect(Collectors.toList()));
    }

springdoc.properties

springdoc.swagger-ui.disable-swagger-default-url=true
springdoc.api-docs.groups.enabled=true

Expected behavior
I expect that the "Select a definition" drop down should be shown instead of "Explore" textfield.

Screenshots
Before Upgrade:
Screenshot from 2021-11-22 15-10-39
After Upgrade:
Screenshot from 2021-11-22 15-08-47

Additional context
I noticed that if i define the groups in springdoc.properties it works for the 1.5.12 version, e.g. with

springdoc.group-configs[1].group=availability-checker
springdoc.group-configs[1].packages-to-scan=com.some.integration.availabilitychecker

However, it is still an issue if it does not work with java config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions