Are there any tools/libraries to convert OpenAPI 2.0 definitions to OpenAPI 3.0, without doing it one per row?
Swagger Editor has a Convert to OpenAPI 3 option under the Edit drop-down that acts as an interface to this API. All we need to do is open our document in Swagger Editor, then convert by using Edit > Convert to OpenAPI 3. This will replace our document with the OAS 3.0 version. It worked!
OpenAPI 3 is the successor of the widely used OpenAPI/Swagger 2.0 format, for machine-readable API definitions. It contains a variety of changes, and even though everything that can be expressed in Version 2 is supported in Version 3 as well, specifications are not backwards-compatible.
Although the terms once referred to the same thing, they can no longer be used interchangeably…even though some people still do. In 2021, OpenAPI refers to the industry-standard specification for RESTful API design. Swagger refers to a set of SmartBear tools.
Paste your OpenAPI 2.0 definition into https://editor.swagger.io and select Edit > Convert to OpenAPI 3 from the menu.
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
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.
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 repo: https://github.com/swagger-api/swagger-codegen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With