java - Swagger 生成静态 html 文档而不使用手动 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>
我添加了两个单独的 /api/docs 到它:
@Component
@Primary
@EnableAutoConfiguration
public class DocumentationController implements SwaggerResourcesProvider {
@Override
public List get() {
List resources = new ArrayList<>();
resources.add(swaggerResource("dictionary", "/dictionary/v2/api-docs", "2.0"));
resources.add(swaggerResource("gateway", "/v2/api-docs", "2.0"));
return resources;
}
private SwaggerResource swaggerResource(String name, String location, String version) {
SwaggerResource swaggerResource = new SwaggerResource();
swaggerResource.setName(name);
swaggerResource.setLocation(location);
swaggerResource.setSwaggerVersion(version);
return swaggerResource;
}
}
我可以访问它
http://localhost:8081/swagger-ui.html?urls.primaryName=gateway
或者:
http://localhost:8081/swagger-ui.html?urls.primaryName=dictionary
现在我想使用这个站点或从它生成静态 html 文档
http://localhost:8081/v2/api-docs
我该怎么做?我阅读了有关代码生成的信息,但我读到它有一些我没有并且不想手动编写的 yaml 规范。
编辑:
如果我从以下内容保存 json 文件:http://localhost:8081/v2/api-docs
它是有效的 json 输入文件 swagger-codegen 吗?这个 api-docsdictionary
也包含定义吗?我想dictionary
在阅读 API 时减少对 API 的访问(MavenXpp3Reader
在此处使用以下代码段:https ://piotrminkowski.wordpress.com/2017/04/14/microservices-api-documentation-with-swagger2/ ),并且HTML
仅在网关API
添加了额外的修剪 API,例如dictionary
.
我想生成包含许多 API 的单个文档,而不是多个文档。
解决方案
推荐阅读
- macos - 如何在 mac 上安装 clang 11
- functional-programming - 无法在 agda 中安装默认库
- python - 将列从对象转换为浮点数时出现值错误
- python - 打包一个包含 .so 库的 python 项目
- excel - 在 Excel 中单击切片器中的选项之一时自动运行宏
- python - 在 python 中使用 group by 和排序后如何在数据框中获得前 3 名的销售额?
- python-3.x - 我的 Django 博客中没有加载我在 aws s3 中的静态文件
- linux - 将多行 grep 结果写入 zsh 中的分隔文件并从匹配捕获组中命名文件
- python - 如何将一个数据帧完全划分到另一个数据帧
- sql - 如何在 SQL 中将 cell1 与 cell 2 组 2 进行比较