springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.29k stars 499 forks source link

Disabling of 'Try it out' button does not work for external swagger urls #2728

Closed eekyrus closed 1 month ago

eekyrus commented 1 month ago

Describe the bug

In Spring Gateway application we import OpenAPI specs from multiple downstream services. Our configuration is like this: We add multiple groups to SwaggerUiConfigParameters and then have Spring Gateway routes defined for external OpenAPI spec locations. Setting springdoc.swagger-ui.supportedSubmitMethods to empty array in Gateway application does not disable 'Try it out' button. However springdoc.swagger-ui.try-it-out-enabled seems to work fine for enabling Try out by default.

To Reproduce 1) Create Spring Gateway application with springdoc-openapi-starter-webflux-ui:2.6.0 dependency. 2) In Spring's configuration class have for Springdoc

@PostConstruct
public void apis() {
    swaggerUiConfigParameters.addGroup("firstservice", "First Service");
}

and for Gateway

@Bean
public RouteLocator routes(RouteLocatorBuilder builder) {
    return builder
        .routes()
        .route("First service Open Api", ps -> ps
            .path("/v3/api-docs/firstservice")
            .filters(gatewayFilterSpec -> gatewayFilterSpec.rewritePath("^.*$", "/v3/api-docs")
            )
            .uri("http://localhost:8082")
        )
        .build();
}

3) Have one other applications that have Open API specs available at /v3/api-docs running at host localhost:8082

Expected behavior

'Try it out' button disabled in Swagger-UI

bnasslahsen commented 1 month ago

@eekyrus

Not reproducible. Feel free to provide a Minimal, Reproducible Example - with HelloController that reproduces the problem.

This ticket will be closed, but can be reopened if your provide the reproducible sample.

eekyrus commented 1 month ago

@bnasslahsen

I added reproducible examples in github repos. Is it ok? First start Microservice application: https://github.com/eekyrus/Microservice Then start Spring Gateway application: https://github.com/eekyrus/TryItOutButtonBugApplication

Try accessing Swagger UI on Gateway app via localhost:8080/swagger-ui.html. It should display Microservice's swagger with Try it out button hidden. Swagger works, but button is still enabled.

eekyrus commented 1 month ago

I might be using the Springdoc api incorrectly here, I am not sure. My goal is to display external SwaggerUrls in Gateway application AND apply some modifications to external OpenAPI specs used, e.g. disabling Try it out buttons, removing Servers dropdown etc. Seems the various Springdoc customizers will not work for this. But I expected at least Swagger properties to work.

Could you suggest an approach for my use case? Maybe download external OpenAPI specs as json and modify them in Gateway application manually?

bnasslahsen commented 1 month ago

@eekyrus,

Your samples do not show any bugs! Remember, contributions to this repository should follow its contributing guidelines, security policy, and code of conduct.

For how to use the gateway with services, see the following demos samples:

eekyrus commented 1 month ago

Well it shows Try it out button being displayed when accessing localhost:8080/swagger-ui.html, even though springdoc.swagger-ui.supportedSubmitMethods= is present in application.properties. Not sure what else is missing?

bnasslahsen commented 1 month ago

it's a duplicate of https://github.com/springdoc/springdoc-openapi/issues/2740, which is fixed in the main branch