小编典典

避免使用swagger api的默认basic-error-controller

spring-boot

我在Spring Boot项目中使用了 swagger2 。它运作良好,但我需要basic-error- controller从api中排除。目前,我正在使用正则表达式使用以下代码。它正在工作,但是有什么完美的方法可以做到这一点。

代码:

@Bean
public Docket demoApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.any())
            .paths(PathSelectors.regex('(?!/error.*).*'))
            .build()
}

阅读 4713

收藏
2020-05-30

共1个答案

小编典典

在google中搜索后,我从GitHub的一个问题中获得了解决方案,
[问题]如何排除基本错误控制器而不是将其添加到草率的描述中?
。可以使用来完成 Predicates.not()

使用后,代码如下所示 Predicates.not()

@Bean
public Docket demoApi() {
    return new Docket(DocumentationType.SWAGGER_2)//<3>
            .select()//<4>
            .apis(RequestHandlerSelectors.any())//<5>
            .paths(Predicates.not(PathSelectors.regex("/error.*")))//<6>, regex must be in double quotes.
            .build()
}
2020-05-30