如何将 OpenAPI 2.0 转换为 OpenAPI 3.0? [关闭]

2024-03-11

是否有任何工具/库可以将 OpenAPI 2.0 定义转换为 OpenAPI 3.0,而无需每行一个?


招摇编辑器

将您的 OpenAPI 2.0 定义粘贴到https://editor.swagger.io https://editor.swagger.io并选择编辑 > 转换为 OpenAPI 3从菜单中。

招摇转换器

将 OpenAPI 2.0 和 Swagger 1.x 定义转换为 OpenAPI 3.0。

https://converter.swagger.io/api/convert?url=OAS2_YAML_OR_JSON_URL

这将为您提供 JSON。如果您需要 YAML,请使用以下内容发送请求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 https://converter.swagger.io

GitHub 仓库:https://github.com/swagger-api/swagger-converter https://github.com/swagger-api/swagger-converter

Swagger Codegen 版本 3.x

还可以将 OpenAPI 2.0 和 Swagger 1.x 定义转换为 OpenAPI 3.0。 Swagger Codegen 有一个 CLI 版本,Maven插件 https://github.com/swagger-api/swagger-codegen/tree/3.0.0/modules/swagger-codegen-maven-plugin, Docker 镜像 https://github.com/swagger-api/swagger-codegen/tree/3.0.0#public-pre-built-docker-images.

这是使用命令行版本的示例(您可以从以下位置下载最新的 JAR)梅文中心 https://mvnrepository.com/artifact/io.swagger.codegen.v3/swagger-codegen-cli)。写出整个命令在一条线上. Use openapi-yaml获取 YAML 或openapi获取 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 https://github.com/swagger-api/swagger-codegen

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何将 OpenAPI 2.0 转换为 OpenAPI 3.0? [关闭] 的相关文章

随机推荐