Skip to content

GroupedOpenApi for different URLs #309

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
Marx2 opened this issue Dec 31, 2019 · 2 comments
Closed

GroupedOpenApi for different URLs #309

Marx2 opened this issue Dec 31, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@Marx2
Copy link

Marx2 commented Dec 31, 2019

I want to expose multiple APIs through one endpoint.
Examples using GroupedOpenApi works only if everything is packed into single application, and just join documentation from different jars.
I want to achieve something similar to http://springfox.github.io/springfox/docs/current/#aggregating-multiple-swagger-specifications-in-the-same-swagger-ui (location can be full URL)
I was trying to use OpenApiCustomiser but it force me to set paths or group
Packages to scan or paths to filter can not be both null for the group:ftp
while I have only external url:

	@Bean
	public GroupedOpenApi ftpOpenApi()
	{
		final OpenApiCustomiser customizer = openApi -> {
			final ExternalDocumentation ext = new ExternalDocumentation();
			ext.setUrl("http://localhost:8220/v3/api-docs/");
			openApi.setExternalDocs(ext);
		};
		return GroupedOpenApi.builder().setGroup("ftp").addOpenApiCustomiser(customizer).build();
	}
@bnasslahsen
Copy link
Collaborator

GroupedOpenApi usage, is only for multiple OpenAPI definitions in a single Spring Boot project.

If your purpose is to expose extrernal OpenAPI description only, you can add swagger-config.json (sample attached - containing the urls and group names) to your static ressouces and define the following property:
swagger-config.txt

springdoc.swagger-ui.configUrl=/swagger-config.json

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:
Note that for serving external urls from the same swagger-ui, you need to have CORS enabled.

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

@bnasslahsen
Copy link
Collaborator

Enhanced with #584

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants