Springdoc-openapi: get wrong config when upgrade 1.2.34

Created on 19 Apr 2020  路  1Comment  路  Source: springdoc/springdoc-openapi

Describe the bug

  • visit gateway service url /v3/api-docs/swagger-config return a wrong urls when i upgraded springdoc to 1.2.34:
{
    "configUrl": "/v3/api-docs/swagger-config", 
    "oauth2RedirectUrl": "http://localhost:8060/v3/api-docs/swagger-config/webjars/swagger-ui/oauth2-redirect.html", 
    "url": "/v3/api-docs", 
    "validatorUrl": ""
}

Btw, the right urls is :

{
    "configUrl": "/v3/api-docs/swagger-config", 
    "oauth2RedirectUrl": "http://localhost:8060/v3/api-docs/swagger-config/webjars/swagger-ui/oauth2-redirect.html", 
    "urls": [
        {
            "url": "/v3/api-docs/department", 
            "name": "department"
        }, 
        {
            "url": "/v3/api-docs/employee", 
            "name": "employee"
        }, 
        {
            "url": "/v3/api-docs/organization", 
            "name": "organization"
        }
    ], 
    "validatorUrl": ""
}

To Reproduce
Steps to reproduce the behavior:

Expected behavior

# GroupedOpenApi.java L52
    SwaggerUiConfigProperties.addGroup(this.group);

# SwaggerUiConfigProperties.java L149
    private static Set<SwaggerUrl> urls = new HashSet<>();

# SwaggerUiConfigProperties.java L155
    public static void addGroup(String group) {
        SwaggerUrl swaggerUrl = new SwaggerUrl(group);
        urls.add(swaggerUrl);
    }

Screenshots
wrong:
wrong

right:
image

Most helpful comment

Hi @liaow,

Hi

Before, there was a high coupling between GroupedOpenApi and SwaggerUiConfigProperties, which is ugly, using static references and difficult to maintain.
Here is a better configuration for your gateway, while you upgrade to v1.3.4:

@Bean
public List<GroupedOpenApi> apis(SwaggerUiConfigProperties swaggerUiConfigProperties) {
    List<GroupedOpenApi> groups = new ArrayList<>();
    List<RouteDefinition> definitions = locator.getRouteDefinitions().collectList().block();
    definitions.stream().filter(routeDefinition -> routeDefinition.getId().matches(".*-service")).forEach(routeDefinition -> {
        String name = routeDefinition.getId().replaceAll("-service", "");
        swaggerUiConfigProperties.addGroup(name);
        GroupedOpenApi.builder().pathsToMatch("/" + name + "/**").setGroup(name).build();
    });
    return groups;
}

>All comments

Hi @liaow,

Hi

Before, there was a high coupling between GroupedOpenApi and SwaggerUiConfigProperties, which is ugly, using static references and difficult to maintain.
Here is a better configuration for your gateway, while you upgrade to v1.3.4:

@Bean
public List<GroupedOpenApi> apis(SwaggerUiConfigProperties swaggerUiConfigProperties) {
    List<GroupedOpenApi> groups = new ArrayList<>();
    List<RouteDefinition> definitions = locator.getRouteDefinitions().collectList().block();
    definitions.stream().filter(routeDefinition -> routeDefinition.getId().matches(".*-service")).forEach(routeDefinition -> {
        String name = routeDefinition.getId().replaceAll("-service", "");
        swaggerUiConfigProperties.addGroup(name);
        GroupedOpenApi.builder().pathsToMatch("/" + name + "/**").setGroup(name).build();
    });
    return groups;
}

Was this page helpful?
0 / 5 - 0 ratings