How to convert OpenAPI 2.0 to OpenAPI 3.0?

China☆狼群 提交于 2020-01-30 08:07:08

问题


Are there any tools/libraries to convert OpenAPI 2.0 definitions to OpenAPI 3.0, without doing it one per row?

I googled but found none.


回答1:


Swagger Editor

Paste your OpenAPI 2.0 definition into https://editor.swagger.io and select Edit > Convert to OpenAPI 3 from the menu.

Swagger Converter

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

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 docs: https://converter.swagger.io

GitHub repo: https://github.com/swagger-api/swagger-converter

Swagger Codegen version 3.x

Can also convert OpenAPI 2.0 and Swagger 1.x definitions to OpenAPI 3.0.

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.16.jar generate
     -l openapi-yaml
     -i https://petstore.swagger.io/v2/swagger.yaml
     -o OUT_DIR

GitHub repo: https://github.com/swagger-api/swagger-codegen



来源:https://stackoverflow.com/questions/59749513/how-to-convert-openapi-2-0-to-openapi-3-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!