Reputation: 2396
I am following the instructions provided here: Why does swagger annotations generate api-docs with default path prefix and things work great. I have my Swagger APIs showing up with a custom group name.
Now, I want to add another group and this is where I am stuck. I tried to change the configuration file to:
@Configuration
@EnableSwagger
public class MySwaggerConfig {
private SpringSwaggerConfig springSwaggerConfig;
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}
@Bean
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
.swaggerGroup("my-group1")).includePatterns("/admin/.*");
}
@Bean
public SwaggerSpringMvcPlugin customImplementation() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
.swaggerGroup("my-group2")).includePatterns("/users/.*");
}
}
Unfortunately this doesn't work. None of the groups end up even showing up. I then tried creating two Swagger config files. In this case only one file is being picked up.
Any idea?
Upvotes: 0
Views: 5444
Reputation: 3175
Catched from below link from argument of method includePatterns.It is accepting array.
Pass array for including multiple patterns.
Upvotes: 0
Reputation: 2396
For any future camper, I guess Swagger work as it should. The error I was making was to assume that hitting /api-docs would show me the list of all groups. However as the documentation says, /api-docs Returns the first Resource Listing found in the cache.
In the end, my swagger config looks as follows:
public class MySwaggerConfig {
private SpringSwaggerConfig springSwaggerConfig;
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
this.springSwaggerConfig = springSwaggerConfig;
}
@Bean
public SwaggerSpringMvcPlugin customImplementation1() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
.swaggerGroup("my-group1").includePatterns(".*/admin.*");
}
@Bean
public SwaggerSpringMvcPlugin customImplementation2() {
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig)
.swaggerGroup("my-group2").includePatterns(".*/users.*");
}
}
Upvotes: 1