Is there any way of specifying multiple packages when configuring Swagger 2?
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.0");
beanConfig.setResourcePackage("com.company1.resources ; org.company2.resources");
beanConfig.setScan(true);
BeanConfig.setResourcePackage
only takes a String. If I separate them with a space, only the first one is considered. If I try with a semicolon, swagger doesn't find any.
I have a Spring Boot application with Jersey 2.
For example in spring (springfox-swagger) you need just to put the same tag on multiple API classes and it will merge them in one group in the swagger UI. @Api(value = "First API", tags = {"first-api"}) public class FirstApi { ... } @Api(tags = {"first-api"}) public class SecondApi { ... }
React Full Stack Web Development With Spring Boot Swagger2 is an open source project used to generate the REST API documents for RESTful web services. It provides a user interface to access our RESTful web services via the web browser.
7-p3), Swagger is disabled automatically in production mode. This means that you can still use it on development machines where it is most important, but not on the live server. It's not possible to easily use Swagger on test or staging systems either while they run in production mode (which they should).
Swagger is the name associated with some of the most well-known, and widely used tools for implementing the OpenAPI specification. The Swagger toolset includes a mix of open source, free, and commercial tools, which can be used at different stages of the API lifecycle.
I have not seen this documented anywhere, but based on the code in the current Swagger core (1.5.10) it looks like you separate multiple packages by a comma (','). Here is the relevant snippet from BeanConfig.java
:
if (resourcePackage != null && !"".equals(resourcePackage)) {
String[] parts = resourcePackage.split(",");
for (String pkg : parts) {
if (!"".equals(pkg)) {
acceptablePackages.add(pkg);
config.addUrls(ClasspathHelper.forPackage(pkg));
}
}
} else {
allowAllPackages = true;
}
Further down it appears the allowAllPackages
flag causes Swagger to generate documentation on all classes in the application's classpath that have JAX-RS annotations. Depending on what dependencies you have, simply not setting a resource package at all might be an option. Probably safer to use the comma-separated list, though.
Edit:
I did find mention of this in the documentation:
setResourcePackage(String)
resourcePackage
Sets which package(s) Swagger should scan to pick up resources. If there's more than one package, it can be a list of comma-separated packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With