Swagger shields operations displayed by some interfaces

  • 2021-10-11 18:49:54
  • OfStack

Swagger shields some interface displays

First of all, let's talk about why we need to mask, because some interfaces are called for internal services and do not need docking. The words displayed:

1. It is easy to be confused

2. It is easy to expose relevant interface contents

In fact, shielding is relatively simple, mainly annotations:


@ApiIgnore
    @RequestMapping("/wx/back")
    @ApiIgnore
    public String wxBack(HttpServletRequest request){
        return payService.back(ParamUtil.getXmlString(request),"zjcOrderService");
    }

So this interface will not be displayed on Swagger

If this interface is added to the class, the whole class will not be displayed

Swagger Ui only shows part of the interface

Swagger UI displays all interfaces by default, even endpoint, jpa restful and other interfaces will be displayed

It can be configured under 1:


@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage(" Package name "))
                .paths(PathSelectors.any())
                .build();
    }
}

Configure your controller package path, and only the interface below your package will be displayed


Related articles: