0

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?

Community
  • 1
  • 1
Klaus
  • 2,168
  • 3
  • 35
  • 59
  • If you don't get an answer here, I'd highly recommend just open an issue on swagger-springmvc's repository. I don't know if they monitor the questions here, but they reply issues there. – Ron Jan 08 '15 at 15:36

2 Answers2

1

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.*");
    }
 }
Klaus
  • 2,168
  • 3
  • 35
  • 59
0

Catched from below link from argument of method includePatterns.It is accepting array.

http://grepcode.com/file/repo1.maven.org/maven2/com.mangofactory/swagger-springmvc/0.8.4/com/mangofactory/swagger/plugin/SwaggerSpringMvcPlugin.java#SwaggerSpringMvcPlugin.includePatterns%28java.lang.String%5B%5D%29

Pass array for including multiple patterns.

Krutik Jayswal
  • 3,115
  • 1
  • 13
  • 36