1. 程式人生 > 其它 >常用公共配置類——Swagger配置

常用公共配置類——Swagger配置

@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo())
            .select()
            //加了ApiOperation註解的類,才生成介面文件
            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class
)) //包下的類,才生成介面文件 //.apis(RequestHandlerSelectors.basePackage("io.renren.controller")) .paths(PathSelectors.any()) .build() .securitySchemes(security()); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title(
"人人開源") .description("renren-fast文件") .termsOfServiceUrl("https://www.renren.io") .version("3.0.0") .build(); } private List<ApiKey> security() { return newArrayList( new ApiKey("token", "token", "header") ); } }
一個小小後端的爬行痕跡