Skip to content

Endpoints get merged in Swagger UI when they differ only by query parameters #859

@jiallombardo

Description

@jiallombardo

Steps to reproduce:

  1. Define endpoints in controller in the following way:
@Operation(method = "GET", summary = "Api call that's secured, requires IP parameter", security = {@SecurityRequirement(name = "bearer-token")}, operationId = "op1")
    @GetMapping(value = "/v1/api", params = "ip")
    @PreAuthorize("@authorizationService.isAuthorized(#accessToken,#ip)")
public Mono<Payload> getData(@Parameter(description = IP) @RequestParam(IP_PARAMETER) String ip) {
//logic doesn't matter
}
    @Operation(method = "GET", summary = "This API call is not secured, and it requires IP parameter to not be included", security = {@SecurityRequirement(name = "bearer-token")}, operationId = "op2")
    @GetMapping(value = "/v1/api", params = "!ip")
    public Mono<Payload> getData(@Parameter(description = FORM_FACTOR) @RequestParam(required = false)  FormFactor formFactor) {
//logic doesn't matter
}

Note that the two endpoints differ only by parameter usage (the first one requires "ip" to be in the query, whereas the second one requires it to be absent from the query). The two endpoint are separate, since they invoke very different logic, one is secured via @PreAuth and the other is not, and the API user, when viewing docs, should be able to see the distinct difference between them.
The operationId was added in an attempt to force the openAPI engine to distinguish these two endpoints, but it didn't work.

  1. Use the following OpenAPI configuration:
@Configuration
public class OpenAPIConfiguration {

    /**
     * Basic openAPI bootstrap bean definition.
     * Run the app and go to host:port/swagger-ui.html to see the generated API docs.
     */
    @Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .components(new Components().addSecuritySchemes("bearer-token", new SecurityScheme()
                        .type(SecurityScheme.Type.HTTP)
                        .scheme("bearer")
                        .bearerFormat("JWT")));
    }
}
  1. Open swagger-ui.html

Expected result -- the two endpoint will be displayed separately on the UI
Actual result -- only one endpoint (the first one) gets displayed on the UI

Springdoc version used: 1.4.4
Spring-boot version used: 2.1.6

Please advise, if something could be done to circumnavigate this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions