swagger 无法使用springdoc-openapi-starter-webmvc-ui加载自定义openapi.yaml文件

vsaztqbk  于 12个月前  发布在  Spring
关注(0)|答案(1)|浏览(273)

我使用Sping Boot 3和库springdoc-openapi-starter-webmvc-ui来编写swagger文档。swagger ui在读取现有控制器时工作良好http://localhost:8080/swagger-ui/index.html。我目前的依赖关系如下-

<!-- Swagger dependency-->
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>webjars-locator</artifactId>
            <version>0.45</version>
        </dependency>

但现在我尝试使用一个自定义的yaml文件,其中定义了openapi规范。为此,我在application.properties文件中添加了以下内容

springdoc.api-docs.path=classpath:/swagger-config.yaml

再次运行服务器时,相同的swagger链接给出以下错误Failed to load remote configuration. x1c 0d1x
我尝试了各种其他配置,但似乎没有一个能从swagger-config.yaml文件中找到规格。这里的任何输入都将非常有帮助!!!
请注意,我的swagger-config.yaml是一个有效的文件,它在在线swagger editor中工作得非常好。

7z5jn7bk

7z5jn7bk1#

您需要设置的属性是springdoc.swagger-ui.url而不是springdoc.api-docs.path
springdoc.swagger-ui.url=/swagger-config.yml应该可以。
另外,请注意,YML文件应放在src/main/resources/static目录中。

相关问题