swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.01k stars 8.86k forks source link

Cannot aggregate multiple swagger specifications in the same swagger-ui #7977

Open nunocruz opened 2 years ago

nunocruz commented 2 years ago

OS: macOS Browser: Chrome and firefox Version: 99.0.4844.84 and 98.0.2 Method of installation: java maven Swagger-UI version: 3.0.0 Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

@Configuration
@EnableOpenApi
public class FrameDocumentationProvider {

    private static final String SWAGGER_VERSION = "3.0";

    @Autowired
    private OpenApiProperties openApiProperties;

    @Primary
    @Bean
    public SwaggerResourcesProvider swaggerResourcesProvider(InMemorySwaggerResourcesProvider defaultResourcesProvider) {
        return () -> {
            List<SwaggerResource> resources = new ArrayList<>();
            for (Entry<String, OpenAPIPropertiesModule> moduleEntry : openApiProperties.getModules().entrySet()) {
                SwaggerResource wsResource = new SwaggerResource();
                wsResource.setName(moduleEntry.getKey());
                wsResource.setSwaggerVersion(SWAGGER_VERSION);
                OpenAPIPropertiesModule moduleProperties = moduleEntry.getValue();
                wsResource.setLocation(moduleProperties.getApi());
                resources.add(wsResource);
            }

            return resources;
        };
    }

    private SwaggerResource swaggerResource(String name, String location) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(SWAGGER_VERSION);
        return swaggerResource;
    }

    @Bean
    UiConfiguration uiConfig() {
        return UiConfigurationBuilder.builder()
            .swaggerUiBaseUrl(openApiProperties.getHost())
            .deepLinking(true)
            .displayOperationId(false)
            .defaultModelsExpandDepth(-1)
            .defaultModelExpandDepth(1)
            .defaultModelRendering(ModelRendering.EXAMPLE)
            .displayRequestDuration(false)
            .docExpansion(DocExpansion.NONE)
            .filter(false)
            .maxDisplayedTags(null)
            .operationsSorter(OperationsSorter.ALPHA)
            .showExtensions(false)
            .showCommonExtensions(false)
            .tagsSorter(TagsSorter.ALPHA)
            .supportedSubmitMethods(UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS)
            .validatorUrl(null)
            .build();
    }

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.OAS_30)
            .apiInfo(apiInfo())
            .enableUrlTemplating(true)
            .securitySchemes(securitySchemes())
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(Predicate.not(PathSelectors.regex("/error")))
            .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfo();
    }

    private List<SecurityScheme> securitySchemes() {
        return List.of(new ApiKey(
            "OAuth Authorization Token",
            "Authorization",
            "header"));
    }
}

Describe the bug you're encountering

When return multiple resources to the swagger-ui the inferface only loads the data from the first resource of the list.

To reproduce...

Steps to reproduce the behavior:

  1. Create muiltiple resources and create a primary bean that returns them
  2. load swagger-ui in the browser
  3. only loads endpoints from the first resource

Expected behavior

Loads endpoints from all resources.

olegZavrazhinDecathlon commented 1 year ago

Any updates?