Skip to content

Add support for MultipleOpenApiSupport when a Bean of type List<GroupedOpenApi> is present #1919

Closed
@rajadilipkolli

Description

@rajadilipkolli

Is your feature request related to a problem? Please describe.

  • I would like to create an aggregate Swagger API in the spring-cloud-gateway service using GroupedOpenAPI. To achieve this, I'm trying to trigger the definitions from RouteDefinitionLocator using below sample code
    @Bean
    List<GroupedOpenApi> groupedOpenApiList(RouteDefinitionLocator locator) {
        return locator.getRouteDefinitions()
                .filter(
                        routeDefinition ->
                                routeDefinition.getId().matches(".*-service"))
                .map(
                        routeDefinition -> {
                            String name =
                                    routeDefinition
                                            .getId()
                                            .replaceAll("-service", "");
                            return GroupedOpenApi.builder()
                                    .pathsToMatch("/" + name + "/**")
                                    .group(name)
                                    .build();
                        })
                .toStream()
                .toList();
    }

I expect MultipleOpenApiSupportConfiguration to trigger during the AutoConfiguration Scanning as spring boot application contains the Bean of type List<GroupedOpenApi>, however this is not triggered because of the failed condition @Conditional(MultipleOpenApiSupportCondition.class) . This is failing as MultipleOpenApiGroupsCondition.class only accepts a single GroupedOpenApi Bean or conditional property

Describe the solution you'd like

  • Solution to make MultipleOpenApiGroupsCondition.java accept List<GroupedOpenApi> to make the conditional annotation become true

Describe alternatives you've considered

  • Declaring the SpringBoot Main class with below package scanning is making is pass but this is wrong approach
    @SpringBootApplication(scanBasePackages = {"org.springdoc.webflux.api", "com.example.api.gateway"})

Additional context

  • Below is the sample code used to demonstrate the idea
    demo.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions