私は Spring Boot アプリケーションに取り組んでおり、ドキュメントには Swagger を使用しています。
アプリケーションに Spring Boot Actuator を追加しましたが、アクチュエーター (/health /metrics ..) によって作成される新しいサービスを Swagger ドキュメントに追加したいと考えています。
Actuator と Swagger の構成方法がわかりません。
私は Spring Boot アプリケーションに取り組んでおり、ドキュメントには Swagger を使用しています。
アプリケーションに Spring Boot Actuator を追加しましたが、アクチュエーター (/health /metrics ..) によって作成される新しいサービスを Swagger ドキュメントに追加したいと考えています。
Actuator と Swagger の構成方法がわかりません。
ドキュメントに追加するパスを Swagger で構成できます。
@Bean
public Docket appApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
...
}
利用可能なすべてのエンドポイントが表示されます。
.paths(PathSelectors.any("/mypath/**"))
で公開されているエンドポイントのみに制限しますmypath.
代替案:
a)正規表現でNOT を使用してパスを除外しますか?
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("^((?!/error).)*")) // exclude Basic Error Controller
.build();
}
b) またはPredicate をチェーンして否定します。
PathSelectors.any()
.and(PathSelectors.regex("/error").negate())
.and(PathSelectors.regex("/manage.*").negate());