Raj*_*ami 20 swagger-ui swagger-2.0 springfox
有没有办法可以从springfox swagger-ui中删除"basic-error-controller"?
图片:
小智 40
您可以限制请求处理程序选择器仅扫描项目的包:
return new Docket( DocumentationType.SWAGGER_2)
.select()
.apis( RequestHandlerSelectors.basePackage( "your package" ) )
...
Run Code Online (Sandbox Code Playgroud)
bla*_*ekp 11
我认为,最优雅的解决方案是仅将@RestController控制器包括在内,唯一需要牢记的是使用该注释对所有REST控制器进行注释:
new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build();
Run Code Online (Sandbox Code Playgroud)
如BasicErrorController仅注释@Controller,将BasicErrorController在定义文件中避免使用。当然,您可以使用自定义注释,而不是@RestController将REST控制器标记为可摇摇欲坠的控制器。
可以使用Predicates.not()完成.
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build();
}
Run Code Online (Sandbox Code Playgroud)例如,如果您的父软件包是com.app.microservice
package com.app.microservice;
Run Code Online (Sandbox Code Playgroud)
然后使用以下代码,它将仅显示包中的控制器,并禁用/排除其他控制器
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.app.microservice"))
.build();
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你也可以使用 springfox-swagger2 注释。springfox.documentation.annotations.ApiIgnore
@ApiIgnore
public class ErrorController {
Run Code Online (Sandbox Code Playgroud)
这将从文档中排除该类。
| 归档时间: |
|
| 查看次数: |
9987 次 |
| 最近记录: |