【问题标题】:How set default API definition url in openapi?如何在 openapi 中设置默认 API 定义 url?
【发布时间】:2021-08-12 13:47:02
【问题描述】:

我想通过 url /v3/api-docs/ 设置默认方案,但是有空 url 和错误“没有提供 API 定义。”。 我应该使用哪些设置属性?

项目中的当前代码:

application.properties

springdoc.swagger-ui.disable-swagger-default-url=true
springdoc.swagger-ui.use-root-path=true

SwaggerConfig.java

@Configuration
public class SwaggerConfig {

@Bean
public GroupedOpenApi applicationApi() {
    String packagesToScan[] = {"ru.vetrf.ecert.web.application"};
    return GroupedOpenApi.builder()
            .group("application")
            .pathsToMatch("/rest-api/application/**")
            .packagesToScan(packagesToScan)
            .build();
}

@Bean
public OpenAPI eCertOpenAPI() {
    return new OpenAPI()
            .info(new Info().title("ECert API")
                    .description("ECert API")
                    .version("v1.0.0"))
            ;
}

}

pom.xml

        <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.5.9</version>
        </dependency>

【问题讨论】:

  • 你分享的两张截图,你的意思是说,第一张是发生了什么,第二张是你想要的?我对您面临的问题感到有些困惑。
  • 我希望在打开 /swagger-ui/index.html 时默认打开第二个屏幕截图

标签: spring-boot openapi springdoc-openapi-ui


【解决方案1】:

尝试复制相同但您使用的当前属性集对我来说很好。

希望将以下属性添加到您的 application.properties 应该会有所帮助

springdoc.swagger-ui.configUrl=/v3/api-docs/

【讨论】:

    【解决方案2】:

    这个属性好像使用了springdoc.swagger-ui.config_url路径:

    springdoc.swagger-ui.use-root-path=true

    这个属性似乎在说,使用 config_url 路径作为探索字段中的根路径 在 swagger-ui 中。

    我在 spring-doc openapi 的演示存储库中找到了解决方案

    https://github.com/springdoc/springdoc-openapi-demos/blob/master/springdoc-openapi-spring-boot-2-webmvc/src/main/resources/application.yml

    【讨论】:

      【解决方案3】:

      对于所有升级到 swagger-ui 4.1.3,请检查以下内容:

      https://github.com/swagger-api/swagger-ui/releases/tag/v4.1.3

      注意:要重新启用从 URL 读取配置参数的功能,请将新的 queryConfigEnabled 核心参数设置为 true。文档中的更多信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-23
        • 2019-07-23
        • 1970-01-01
        • 2011-08-01
        • 2023-03-07
        • 2014-06-16
        相关资源
        最近更新 更多