springdoc / springdoc-openapi

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

GroupedOpenApi seems to not be working with SwaggerUiConfigParameters.urls together #2739

Closed eekyrus closed 5 days ago

eekyrus commented 5 days ago

Describe the bug

I want to combine internal application's OpenAPI spec with external specs into one single Swagger UI. According to already solved issues: https://github.com/springdoc/springdoc-openapi/issues/309 https://github.com/springdoc/springdoc-openapi/issues/584 it should be possible:

If you want to combine in the same swagger-ui both, REST APIs that are deployed within the same application as the swagger-ui and external REST APIs: This is an enhancement and will be available with the next release: v1.2.22.

To achieve that, you declare your REST APIs that are deployed within the same application as the swagger-ui using GroupedOpenApi. And you external REST APIs with the following syntax:

SwaggerUiConfigProperties.addGroup("group1", "url1");
SwaggerUiConfigProperties.addGroup("group2", "url2");

To Reproduce Steps to reproduce the behavior:

Start application which contains OpenAPI spec: https://github.com/eekyrus/Microservice Start Spring Gateway application which contains both external Swagger url configuration and GroupedOpenApi configuration: https://github.com/eekyrus/GroupedOpenApiBug

Try accessing Swagger via localhost:8080/swagger-ui.html.

Expected behavior

Both groups under Definitions dropdown display Swagger UI. 'Microservice' definition should display external Microservice application OpenAPI spec, while 'internalservice' definition should display internal application's OpenAPI spec (empty in demo application).

Additional context In demo application, removing GroupedOpenApi bean definition and uncommenting PostConstruct code snippet which only defines external swagger urls makes external OpenAPI specs work. It seems that the Spring Gateway application does not receive request to its routing mechanism when GroupedOpenApi configuration is used and does not forward request to Microservice application.

bnasslahsen commented 5 days ago

@eekyrus,

Again, 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 5 days ago

The demo doesn't use GroupedOpenApi.

bnasslahsen commented 4 days ago

@eekyrus,

See the answer here https://github.com/springdoc/springdoc-openapi/issues/2741 why GroupedOpenApi are not used anymore.

eekyrus commented 4 days ago

As I understand, GroupedOpenApi is still used for internal OpenApi spec generation, while Swagger urls property on SwaggerUiConfigProperties is used for external OpenApi spec generation. The issue here is that they cannot be combined. Is this intended behavior?

bnasslahsen commented 4 days ago

@eekyrus,

You maybe do did not read the answer...

We limited the use GroupedOpenApi. so scan for beans within the same application context, to allow dynamic scan. If you have external URL, that you need to aggregate them based on SwaggerUrl.

Which means they can be combined for different purposes.