在使用 Spring Boot 的 Maven 项目中,有多个 OpenAPI 3.0 规范文件。一个规范定义了所有 HTTP 错误 (errors.yml),并且 error.yml 的组件在其他规范中引用。
我想生成一个输出规范,其中包含 error.yml 的所有组件。
输入规格:
schema:
$ref: "errors.yml#/components/schemas/Error"
期望的输出规格:
schema:
$ref: "#/components/schemas/Error"
...
Error:
...
我可以使用 swagger-codegen-cli 来做到这一点:
java -Dfile.encoding=UTF-8 -jar swagger-codegen-cli-3.0.33.jar generate -l openapi-yaml -i search-api-contract/target/expert_api.yml -o . -DoutputFile=search-api-contract/target/expert_api.yml
如何使用 Maven pom.xml 生成一份规范?
Swagger Codegen 有一个Maven插件。你可以这样使用它:
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.33</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>path/to/main/openapi.yaml</inputSpec>
<!-- Use 'openapi-yaml' to get resolved YAML or 'openapi' to get resolved JSON -->
<language>openapi-yaml</language>
<!-- Default is ${project.build.directory}/generated-sources/swagger -->
<output>path/to/output/folder</output>
<configOptions>
<!-- Default output file name is 'openapi.yaml' or 'openapi.json' -->
<outputFile>myapi.yaml</outputFile>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)