Tuesday, July 17, 2018

Exclude endpoint mapping from Swagger documentation in Springfox



 Exclude endpoint mapping from Swagger documentation in Springfox

By default, Swagger ui shows all the endpoint defined via a controller in SwaggerConfig using Docket.
But there are situations in which you dont want those endpoints to be visible in swagger ui.

To achieve this, we can do this following way:

@Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select().paths(Predicates.not(PathSelectors.regex("/|/error|/swagger.yml"))).apis(RequestHandlerSelectors.basePackage("com.daimler.datalayer.apistreamintegration.controller"))
                .paths(PathSelectors.any())
                .build().apiInfo(apiInfo());


Just provide all regex which you want to exclude.
Here in the example i have excluded all mapping /, /error and /swagger.yml

Cheers!!!

No comments:

Post a Comment