gpt4 book ai didi

java - 如何在应用程序 url/swagger 中显示静态 swagger yaml 文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:09 33 4
gpt4 key购买 nike

我创建了 yaml 文件(openapi 3.0.0 格式)作为我们 API 的文档。我想在运行应用程序的 URL 处显示此(静态)swagger-ui yaml 文件。类似于 http://localhost:8080/swagger-ui . yaml 文件的图形表示在哪里显示(与 here 相同)。 Yaml 文件放置在项目的根文件夹中。

我正在使用 maven 构建的 java 11、springboot 2.1.5 上运行应用程序。

我尝试使用

从代码生成 swagger yaml
    <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

但这一个并不完美(缺少默认值、描述......)

我试过了 spring static resources没有成功。问题是 yaml 文件不是 html。

是否有另一种(也许更好)的方式,如何显示 api 文档?

最佳答案

您还需要添加 swagger UI 依赖项。

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

然后您可以使用访问 swagger ui,

http://localhost:9090/swagger-ui.html#/

尝试将其添加到您的方法中,

public void yourMethod(@ApiParam(name = "id", required = true, value = "The id of the site", defaultValue = "3F7B07E2") String id)

关于java - 如何在应用程序 url/swagger 中显示静态 swagger yaml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56425293/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com