问题描述
是否有任何工具/库可以将OpenAPI 2.0定义转换为OpenAPI 3.0,而无需每行执行一次?
Are there any tools/libraries to convert OpenAPI 2.0 definitions to OpenAPI 3.0, without doing it one per row?
我用Google搜索,但没有找到.
I googled but found none.
推荐答案
Swagger编辑器
将您的OpenAPI 2.0定义粘贴到 https://editor.swagger.io 并选择编辑>从菜单转换为OpenAPI 3 .
将OpenAPI 2.0和Swagger 1.x定义转换为OpenAPI 3.0.
Converts OpenAPI 2.0 and Swagger 1.x definitions to OpenAPI 3.0.
https://converter.swagger.io/api/convert?url=OAS2_YAML_OR_JSON_URL
这将为您提供JSON.如果要使用YAML,请发送带有Accept: application/yaml
标头的请求:
This gives you JSON. If you want YAML, send the request with the Accept: application/yaml
header:
curl "https://converter.swagger.io/api/convert?url=OAS2_YAML_OR_JSON_URL" -H "Accept: application/yaml" -o ./openapi.yaml
API文档: https://converter.swagger.io
GitHub存储库: https://github.com/swagger-api/swagger-converter
GitHub repo: https://github.com/swagger-api/swagger-converter
还可以将OpenAPI 2.0和Swagger 1.x定义转换为OpenAPI 3.0. Swagger Codegen具有CLI版本, Maven插件, Docker映像.
Can also convert OpenAPI 2.0 and Swagger 1.x definitions to OpenAPI 3.0. Swagger Codegen has a CLI version, Maven plugin, Docker images.
这是一个使用命令行版本的示例(您可以从 Maven Central ).将整个命令写在一行上.使用openapi-yaml
获取YAML或使用openapi
获取JSON.
Here's an example using the command-line version (you can download the latest JAR from Maven Central). Write the entire command on one line. Use openapi-yaml
to get YAML or openapi
to get JSON.
java -jar swagger-codegen-cli-3.0.19.jar generate
-l openapi-yaml
-i https://petstore.swagger.io/v2/swagger.yaml
-o OUT_DIR
GitHub存储库: https://github.com/swagger-api/swagger-codegen
GitHub repo: https://github.com/swagger-api/swagger-codegen
这篇关于如何将OpenAPI 2.0转换为OpenAPI 3.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!