Skip to content

Swagger 2.0 to OpenAPI 3 converter

Runs in your browser. Nothing is uploaded.

Convert a Swagger 2.0 file to OpenAPI 3.0, and convert an API description from JSON to YAML or back.

Conversion

Input

{
  "swagger": "2.0",
  "info": {
    "title": "Swagger Petstore",
    "version": "1.0.0",
    "description": "A sample API that uses a pet store as an example."
  },
  "host": "petstore.example.com",
  "basePath": "/v1",
  "schemes": [
    "https"
  ],
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "securityDefinitions": {
    "api_key": {
      "type": "apiKey",
      "name": "X-API-Key",
      "in": "header"
    }
  },
  "security": [
    {
      "api_key": []
    }
  ],
  "paths": {
    "/pets": {
      "get": {
        "operationId": "listPets",
        "summary": "List all pets",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "type": "integer",
            "format": "int32",
            "description": "How many pets to return"
          }
        ],
        "responses": {
          "200": {
            "description": "The pets",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/Pet"
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createPet",
        "summary": "Add a pet",
        "parameters": [
          {
            "name": "pet",
            "in": "body",
            "required": true,
            "schema": {
              "$ref": "#/definitions/Pet"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }
    },
    "/pets/{petId}": {
      "get": {
        "operationId": "showPetById",
        "summary": "Info for a specific pet",
        "parameters": [
          {
            "name": "petId",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "The pet",
            "schema": {
              "$ref": "#/definitions/Pet"
            }
          },
          "404": {
            "description": "Not found"
          }
        }
      }
    }
  },
  "definitions": {
    "Pet": {
      "type": "object",
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        },
        "name": {
          "type": "string"
        },
        "tag": {
          "type": "string"
        }
      }
    }
  }
}

Result

Paste, upload or load a file to start

How it works

Paste, upload or load a Swagger 2.0 file. The page converts it with the converter APIGit's editor uses, and shows the OpenAPI 3 document in an output editor, in the same format as the input. Two other modes turn any JSON into YAML or any YAML into JSON.

The sample is a Swagger 2.0 pet store in JSON with a body parameter, a definition and a security definition. In the converted file, the body parameter of POST /pets is now a requestBody, and its schema reference points to components:

      "post": {
        "operationId": "createPet",
        "summary": "Add a pet",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Pet"
              }
            }
          },
          "required": true
        },
        "responses": {
          "201": {
            "description": "Created"
          }
        }
      }

The securityDefinitions entry is now a security scheme under components:

  "components": {
    "securitySchemes": {
      "api_key": {
        "type": "apiKey",
        "name": "X-API-Key",
        "in": "header"
      }
    },

What it does not do

  • It converts to OpenAPI 3.0, not 3.1.
  • It does not take an OpenAPI 3 document, a Postman collection or a RAML file; the input must have a swagger field.
  • It does not fix what was wrong in the 2.0 file. Check the result with "Check this".
  • Nothing is uploaded, and nothing is kept outside this browser.

This tool and APIGit

This toolWith APIGit
Convert one fileImport a Swagger 2.0 file into a repository, or a Postman collection (v2.0 and v2.1) converted to OpenAPI
An output to copyThe converted spec committed to Git, with history and review
No check of the resultThe editor's Governance view checks it with the best-practice and OWASP rule sets; apigit lint with any of the four
A file on your diskA mock server from the spec: Swagger 2.0 is converted automatically

Questions and answers

Which version does it convert to?
OpenAPI 3.0. A Swagger 2.0 file in, an OpenAPI 3.0.0 document out, in the input's format: JSON for JSON, YAML for YAML.
What changes on the way from Swagger 2.0 to OpenAPI 3?
host, basePath and schemes become servers; a body parameter becomes a requestBody; definitions move to components.schemas and every $ref follows; securityDefinitions become components.securitySchemes; produces and consumes become the media types of each response and request.
Can it convert JSON to YAML?
Yes. Pick JSON to YAML or YAML to JSON above the input. These modes take any JSON or YAML document, not only API descriptions.
What if my file is already OpenAPI 3?
The converter refuses it with a message: it takes a document with a swagger field. Use the JSON and YAML modes to change its format only.
Is my file uploaded?
No. The conversion runs in your browser; the result is yours to copy or download.
Do I need to convert before I use APIGit?
No. APIGit accepts a Swagger 2.0 file at import, and a mock server converts one automatically. Converting is still worth it when you want to edit in OpenAPI 3.