Skip to content

GroupedOpenApi cannot work correctly. #2741

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wanghongzhou opened this issue Oct 1, 2024 · 2 comments
Closed

GroupedOpenApi cannot work correctly. #2741

wanghongzhou opened this issue Oct 1, 2024 · 2 comments
Labels
question Further information is requested

Comments

@wanghongzhou
Copy link

wanghongzhou commented Oct 1, 2024

When I use Spring Boot 3.2.10 and Springdoc 2.5.0, I get the desired results. However, when I upgrade to Spring Boot 3.3.4 and Springdoc 2.6, the same code does not produce the expected results. Below is the provided simple code. When running all services, accessing http://localhost:7001/swagger-ui.html gives the desired output, but accessing http://localhost:7002/swagger-ui.html does not yield the correct results

When using Spring Boot 3.2.10 and Springdoc 2.5.0, the gateway returns the correct JSON result at /v3/api-docs/test-service. However, after upgrading, /v3/api-docs/test-service returns the documentation for the gateway itself.

@bnasslahsen
Copy link
Collaborator

@wanghongzhou,

Starting from 2.5.0, this is the proper way to configure it, as you are pointing to an external URL.

	@Bean
	public Set<SwaggerUrl> apis(RouteDefinitionLocator locator, SwaggerUiConfigProperties swaggerUiConfigProperties) {
		Set<SwaggerUrl> urls = new HashSet<>();
		List<RouteDefinition> definitions = locator.getRouteDefinitions().collectList().block();
		definitions.forEach(routeDefinition -> {
			String name = routeDefinition.getId();
			SwaggerUrl swaggerUrl = new SwaggerUrl(name, DEFAULT_API_DOCS_URL + "/" + name, null);
			urls.add(swaggerUrl);

		});
		swaggerUiConfigProperties.setUrls(urls);
		return urls;
	}

GroupedOpenApi, is relevant, within the same application, as a scan will be done

This allows, to dynamically define ApiGroups #2584

@wanghongzhou
Copy link
Author

@bnasslahsen Thanks for your reply! I just tested the code below, and it works great. Thanks again!

@Autowired
public void configureSwaggerUrls(SwaggerUiConfigProperties swaggerUiConfigProperties, RouteDefinitionLocator locator) {
    swaggerUiConfigProperties.setUrls(locator.getRouteDefinitions()
            .map(routeDefinition -> new SwaggerUrl(routeDefinition.getId(), DEFAULT_API_DOCS_URL + "/" + routeDefinition.getId(), routeDefinition.getId()))
            .toStream()
            .collect(Collectors.toSet()));
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants