Are OpenAPI and Swagger the same thing?
2023-01-08
I was perusing Quora this morning and came across this question: "Are OpenAPI and Swagger the same thing?" I find people using the words "Swagger" and "OpenAPI" interchangeably, and yes, OpenAPI is the new swagger, but there are some key differences.
First off, the OpenAPI Initiative FAQ says this:
The OpenAPI Specification was based on the rebranded Swagger 2.0 specification, donated by SmartBear Software in 2015.
It is a little confusing because we not only changed the major version from 2
to 3
, but we also changed the name from Swagger to OpenAPI. An OpenAPI contract describes the same elements as Swagger but the structures are different, hence the "based on"in the OpenAPI Initiative's statement. And, as with any major version change, there are some significant differences.
For example in Swagger 2 describes the API host using top level elements in the beginning of the document, but in OpenAPI 3, the host description has been moved to a servers object:
Swagger 2.x
info:
title: My Example API
host: example.com
basePath: /v1
schemes: ['http', 'https']
OpenAPI 3.x
servers:
- url: https://hostname.site.com/{version}
description: The main prod server
variables:
subdomain:
default: production
version:
enum:
- v1
- v2
default: v2
And while my examples above are in YAML, and both Swagger and OpenAPI support both YAML and JSON, the convention for Swagger has generally been YAML but OpenAPI is becoming more common in JSON.
So, in one sense, OpenAPI and Swagger are the same thing in that they are the evolution of API design artifacts, but if you have a parser that needs to read your API contract, you’re going to need to need different versions of your tools to find, and understand, the elements you're looking for.