Swagger: swagger scans the controllers of different modules

1. Wrong way, use  io.renren.modules.*.controller

 public Docket createRestApi() {
        log.info("======================== 当前环境是否开启Swagger:" + SwaggerSwitch + " ========================");
        return new Docket(DocumentationType.SWAGGER_2)
                .securitySchemes(securitySchemes())
                .securityContexts(securityContexts())
                //配置是否启用Swagger,如果是false,在浏览器将无法访问,默认是true
                .enable(SwaggerSwitch)
                //apiInfo: 添加api详情信息,参数为ApiInfo类型的参数,这个参数包含了第二部分的所有信息比如标题、描述、版本之类的,开发中一般都会自定义这些信息
                .apiInfo(apiInfo())
                .select()
                //apis: 添加过滤条件,
                //加了ApiOperation注解的类,才生成接口文档
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类,才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("io.renren.modules.*.controller"))
                .paths(PathSelectors.any())
                .build();
    }

 

 

Second, the correct way: use the parent class that multiple controllers share, that is, to the upper level of the two controllers

 

    public Docket createRestApi() {
        log.info("======================== 当前环境是否开启Swagger:" + SwaggerSwitch + " ========================");
        return new Docket(DocumentationType.SWAGGER_2)
                .securitySchemes(securitySchemes())
                .securityContexts(securityContexts())
                //配置是否启用Swagger,如果是false,在浏览器将无法访问,默认是true
                .enable(SwaggerSwitch)
                //apiInfo: 添加api详情信息,参数为ApiInfo类型的参数,这个参数包含了第二部分的所有信息比如标题、描述、版本之类的,开发中一般都会自定义这些信息
                .apiInfo(apiInfo())
                .select()
                //apis: 添加过滤条件,
                //加了ApiOperation注解的类,才生成接口文档
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类,才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("io.renren.modules"))
                .paths(PathSelectors.any())
                .build();
    }

 

 

Guess you like

Origin blog.csdn.net/weixin_38676276/article/details/109399195