Filtering for API parts in swagger

Some of the options I can think of

  1. You can add Authentication to different endpoints using SpringSecurity and make the endpoints not accessible at all(But will be visible in Swagger UI).

  2. The drop down you are mentioning on the top can be configured something like this

    @Bean
    public Docket orderApi() {
        // This will group the endpoints strting with /order.   
        // And it will be visible as a separate group in the drop down(In Swagger UI) 
        // with the name 'order' as specified in the groupName(..)
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("order")
                .apiInfo(metadata())
                .select()
                .paths(PathSelectors.ant("/order/**"))
                .build();
    }
    
    @Bean
    public Docket orderValidationApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("product")
                .apiInfo(metadata())
                .select()
                .paths(PathSelectors.ant("/product/**"))
                .build();
    }
    
  3. You can completely exclude the endpoint from being visible in Swagger UI with someting like this in your Docker configuration

       return new Docket( DocumentationType.SWAGGER_2 )
            .select()
                .apis( RequestHandlerSelectors.any() )
                .paths(PathSelectors.regex("(?!/error).+")).paths(PathSelectors.regex("(?!/product).+"))
                .build()
            .apiInfo( metadata() );  
    

    This will make all the endpoints which are not /error and /product available. you can filter out endpoints like this.


You can also Provide package name

@Bean
public Docket api() {

    return new Docket( DocumentationType.SWAGGER_2 )
            .select()
            .apis(RequestHandlerSelectors.basePackage("com.hello.world.controller.user"))
            .paths( PathSelectors.any() )
            .build()
            .apiInfo( metadata() );
}

or you can use custom Annotation for your API classes or API methods as below:

@Bean
public Docket api() {

    return new Docket( DocumentationType.SWAGGER_2 )
            .select()
            .apis(RequestHandlerSelectors.withClassAnnotation(MyCustomClassAnnotation.class))
            .paths( PathSelectors.any() )
            .build()
            .apiInfo( metadata() );
}



@Bean
public Docket api() {

    return new Docket( DocumentationType.SWAGGER_2 )
            .select()
            .apis(RequestHandlerSelectors.withMethodAnnotation(MyCustomMethodAnnotation.class))
            .paths( PathSelectors.any() )
            .build()
            .apiInfo( metadata() );
}