首页 > 解决方案 > 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 的单个文档,而不是多个文档。

标签: javamavenswagger

解决方案


推荐阅读