question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple OpenAPI definitions in one Spring Boot project

See original GitHub issue

I am trying to describe two different versions (v1 and v2) with Open API. Basically Swagger UI I should display v1 from http://localhost:8080/v3/api-docs and v2 from http://localhost:8080/v3/api-docs/v2.

With the springfox Swagger Config I could do this through Dockets. Then I had the selection where I could switch the different endpoint definitions.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
springdoccommented, Dec 22, 2019

This feature will be available on the next release: v1.2.19 of springdoc-openapi.

You can define your own groups of API based on the combination of: API paths and packages to scan. Each group should have a unique groupName. The OpenAPI description of this group, will be available by default on:

To enable this feature, the following springdoc property needs to be added to your application.yml:

springdoc.api-docs.groups.enabled=true

For the support of multiple OpenAPI definitions, a bean of type GroupedOpenApi needs to be defined.

For the following Group definition(based on package path), the OpenAPI description url will be : /v3/api-docs/stores

@Bean
public GroupedOpenApi storeOpenApi() {
	String paths[] = {"/store/**"};
	return GroupedOpenApi.builder().setGroup("stores").pathsToMatch(paths)
			.build();
}

For the following Group definition (based on package name), the OpenAPI description url will be: /v3/api-docs/users

@Bean
public GroupedOpenApi userOpenApi() {
	String packagesToscan[] = {"test.org.springdoc.api.app68.api.user"};
	return GroupedOpenApi.builder().setGroup("users").packagesToScan(packagesToscan)
			.build();
}

For the following Group definition(based on path), the OpenAPI description url will be: /v3/api-docs/pets

@Bean
public GroupedOpenApi petOpenApi() {
	String paths[] = {"/pet/**"};
	return GroupedOpenApi.builder().setGroup("pets").pathsToMatch(paths)
			.build();
}

For the following Group definition (based on package name and path), the OpenAPI description url will be: /v3/api-docs/groups

@Bean
public GroupedOpenApi groupOpenApi() {
	String paths[] = {"/v1/**"};
	String packagesToscan[] = {"test.org.springdoc.api.app68.api.user", "test.org.springdoc.api.app68.api.store"};
	return GroupedOpenApi.builder().setGroup("groups").pathsToMatch(paths).packagesToScan(packagesToscan)
			.build();
}

For more details about the usage, you can have a look at the following sample Test:

9reactions
hemjucommented, Dec 4, 2019

@springdoc please don’t close the issue right away, because even if you don’t allow multiple OpenAI definitions, there is still the question on how to document different versions. Like Springfox Swagger Config allowed with Docket. So can you please tell me if that is possible or not. And if it is possible on how to achieve that. Because I went through the documentation and I only found one way to document all different versions (in our case v1, v2 and internal).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Springdoc with multiple api-docs - Stack Overflow
I want to group three API docs in one swagger-ui. I use Springdoc. Each of the three API-docs has its own url. (They...
Read more >
OpenAPI 3 Library for spring-boot
OpenAPI 3 Library for spring boot projects. Is based on swagger-ui, to display the OpenAPI description.Generates automatically the OpenAPI ...
Read more >
Creating OpenAPI definitions for APIs using springdoc - Medium
First thing's first; for this example I am using a Java based API back end server code, maven for dependency management in a...
Read more >
Doing More With Springdoc-OpenAPI - DZone
In my last recent article we tried out a Spring Boot Open API 3-enabled REST project and explored some of its capabilities namely:....
Read more >
'Code First' API Documentation with Springdoc and Spring Boot
We define it in the application.yml of our Spring Boot project: springdoc: api-docs: path: /reflectoring-openapi. Springdoc will now add the endpoint ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found