【问题标题】:How to hide endpoints based on Profiles in Spring Boot and Spring doc?如何在 Spring Boot 和 Spring doc 中隐藏基于 Profiles 的端点?
【发布时间】:2020-10-08 09:29:51
【问题描述】:

我正在研究Spring Boot v2.2.2.RELEASE and SpringDoc UI and Open API Specification OAS3,我在这里发现了非常相关的问题:https://github.com/springdoc/springdoc-openapi/issues/201

我有 4 个配置文件,分别是 Dev、Stage、UAT 和 Prod,并说我有 Student API、Employee API 和 Department API。

我想要 UAT 和 Prod 配置文件,我想要隐藏部门 API。我们怎么能不呢?

【问题讨论】:

  • 杰夫库克,你的问题似乎没有得到回答:)

标签: springdoc springdoc-openapi-ui springdoc-ui


【解决方案1】:

您可以使用组:在组中声明您的每个 API。

并且,为组定义添加@Profile 注释和@Bean 注释:这将帮助您根据弹簧配置文件显示OpenAPI 规范

@Bean
@Profile("!prod")
public GroupedOpenApi actuatorApi() {
    return GroupedOpenApi.builder().group("Actuator")
            .pathsToMatch("/actuator/**")
            .pathsToExclude("/actuator/health/*")
            .build();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-07
    • 2015-04-02
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    相关资源
    最近更新 更多