Dev tools
OpenAPI vs Swagger: What's the Difference?
OpenAPI vs Swagger: OpenAPI is the API description standard, Swagger is SmartBear's tools for it. History, versions, 2.0 to 3.x changes and tool choices.
In OpenAPI vs Swagger, the short answer is that OpenAPI is the specification and Swagger is a family of tools. The OpenAPI Specification (OAS) is an open standard, governed by the OpenAPI Initiative under the Linux Foundation, for describing HTTP APIs in a YAML or JSON file: endpoints, parameters, request and response bodies, authentication. Swagger is the original name of that specification, and today the brand of SmartBear's tools that work with it, such as Swagger UI, Swagger Editor and Swagger Codegen.
The difference between Swagger and OpenAPI confuses people because of history: until 2016, the specification itself was called Swagger. "Swagger 2.0" files still exist everywhere, and many people use "Swagger" to mean any API description file. This guide explains the history, what changed between Swagger 2.0 and OpenAPI 3.x with side-by-side examples, the tools on both sides, and what to use for a new API.
OpenAPI vs Swagger at a Glance
| OpenAPI | Swagger | |
|---|---|---|
| What it is | A specification (a standard file format) | A set of tools, and the old name of the specification |
| Owner | OpenAPI Initiative, a Linux Foundation project | SmartBear (tools); the specification was donated in 2015 |
| Current versions | 3.0.x, 3.1.x and 3.2.x | Tools support Swagger 2.0 and OpenAPI 3.x files to varying degrees |
| File key | openapi: 3.1.0 | swagger: "2.0" in old files |
| Licence | Open specification | Core tools are open source; SmartBear also sells commercial products |
| Examples | The spec documents on spec.openapis.org | Swagger UI, Swagger Editor, Swagger Codegen |
What Is OpenAPI?
What is OpenAPI? It's a standard, language-neutral way to describe an HTTP API so that both people and programs understand it without reading the source code. An OpenAPI document (often openapi.yaml) lists the API's paths, the operations on each (GET, POST and so on), their parameters, request bodies, responses, data schemas and security schemes.
That single file then drives a lot of tooling:
- Interactive documentation that lets readers try calls in the browser.
- Client SDK generation in many languages.
- Server stubs and request validation.
- Mock servers for front-end teams to build against before the API exists.
- Contract testing to catch changes that break clients.
- API gateways that import routes and security rules.
- AI agents and tools that read the description to learn how to call an API.
A minimal OpenAPI 3.1 document:
openapi: 3.1.0
info:
title: Notes API
version: 1.0.0
servers:
- url: https://api.example.com/v1
paths:
/notes/{id}:
get:
summary: Get a note
parameters:
- name: id
in: path
required: true
schema: { type: string }
responses:
"200":
description: The note
content:
application/json:
schema: { $ref: "#/components/schemas/Note" }
components:
schemas:
Note:
type: object
required: [id, text]
properties:
id: { type: string }
text: { type: string }Is Swagger the Same as OpenAPI?
Is Swagger the same as OpenAPI? Not any more, though they share a history:
| When | What happened |
|---|---|
| 2010 | Tony Tam, then at Reverb Technologies (maker of Wordnik), releases the Swagger specification and tools |
| 2015 | SmartBear, which now backed Swagger, forms the OpenAPI Initiative under the Linux Foundation (announced 5 November) and donates the specification |
| 2016 | The specification is renamed the OpenAPI Specification; OAS 2.0 is the same as Swagger 2.0 |
| July 2017 | OpenAPI 3.0.0 is released, the first version developed under the new name |
| February 2021 | OpenAPI 3.1.0 aligns schemas fully with JSON Schema and adds webhooks |
| September 2025 | OpenAPI 3.2.0 adds streaming media types, hierarchical tags, the QUERY method and the OAuth device flow |
After the rename, "Swagger" refers to SmartBear's tooling. So a sentence like "we have a Swagger file" usually means an OpenAPI (or Swagger 2.0) document, and "Swagger page" usually means documentation rendered by Swagger UI.
The OpenAPI Specification: Versions Compared
The OpenAPI specification has moved on considerably since Swagger 2.0:
| Feature | Swagger 2.0 / OAS 2.0 | OpenAPI 3.0 | OpenAPI 3.1 | OpenAPI 3.2 |
|---|---|---|---|---|
| Version field | swagger: "2.0" | openapi: 3.0.x | openapi: 3.1.x | openapi: 3.2.x |
| Servers | host, basePath, schemes | servers list with variables | Same | Same |
| Request body | A body parameter | requestBody with per-media-type content | Same | Same, plus streaming media types |
| Reusable parts | definitions, parameters, responses | components (schemas, responses, parameters, examples, request bodies, headers, security schemes, links, callbacks) | Same, plus path items | Same, plus reusable media types |
| Schemas | A subset of an old JSON Schema draft | Extended subset of JSON Schema | Full JSON Schema 2020-12 compatibility | Same |
| Multiple content types | Global consumes and produces | Per operation and response | Same | Same |
oneOf, anyOf, not | Not supported | Supported | Supported | Supported |
| Callbacks and webhooks | No | Callbacks | Callbacks and top-level webhooks | Same |
| Null values | Vendor extension | nullable: true | type: [string, "null"] | Same |
Key OpenAPI Terms
| Term | Meaning |
|---|---|
| Document | The whole description, usually one YAML or JSON file, sometimes split across files with references |
| Path | A URL template such as /notes/{id} |
| Operation | One HTTP method on a path, such as GET /notes/{id}, with an optional operationId that code generators use as a function name |
| Parameter | An input in the path, query string, header or cookie |
| Request body | The payload sent with POST, PUT or PATCH, described per media type |
| Response | A status code with its description, headers and body schema |
| Schema | The shape of a piece of data, written in JSON Schema |
| Component | A reusable definition referenced with $ref |
| Tag | A label that groups operations in documentation |
Swagger 2.0 to OpenAPI 3: A Side-by-Side Example
Here's the same POST operation in both formats. Swagger 2.0:
swagger: "2.0"
host: api.example.com
basePath: /v1
schemes: [https]
consumes: [application/json]
paths:
/notes:
post:
parameters:
- in: body
name: note
required: true
schema: { $ref: "#/definitions/Note" }
responses:
"201": { description: Created }
definitions:
Note: { type: object, properties: { text: { type: string } } }OpenAPI 3.1:
openapi: 3.1.0
servers:
- url: https://api.example.com/v1
paths:
/notes:
post:
requestBody:
required: true
content:
application/json:
schema: { $ref: "#/components/schemas/Note" }
responses:
"201": { description: Created }
components:
schemas:
Note: { type: object, properties: { text: { type: string } } }The main moves when migrating are: host, basePath and schemes become servers; body parameters become requestBody; definitions move under components/schemas; global consumes and produces become per-operation content maps; and securityDefinitions become components/securitySchemes. Conversion tools handle most of this automatically, but review the output, especially for file uploads and polymorphic schemas.
Swagger UI and the Swagger Tools
Swagger UI is the best-known Swagger tool: it renders an OpenAPI document as interactive documentation where you can expand each endpoint and send test requests from the browser. Many frameworks bundle it. FastAPI, for example, generates an OpenAPI document from your code and serves Swagger UI at /docs automatically, as our comparison of FastAPI vs Flask shows.
| Tool | Type | What it does |
|---|---|---|
| Swagger UI | Open source (SmartBear) | Interactive API documentation in the browser |
| Swagger Editor | Open source (SmartBear) | Browser editor with live preview and validation |
| Swagger Codegen | Open source (SmartBear) | Generates client libraries and server stubs |
| OpenAPI Generator | Open source (community fork of Swagger Codegen) | Generates clients and servers for many languages |
| Redoc | Open source | Three-panel reference documentation |
| Scalar, Stoplight Elements | Open source and commercial | Alternative documentation renderers |
| Spectral | Open source | Lints OpenAPI files against style rules |
| Postman, Insomnia | Commercial and free tiers | Import OpenAPI files as request collections |
None of these lock you in. Because OpenAPI is a standard, you can write one document and render it with Swagger UI today and Redoc tomorrow.
Design-First vs Code-First
There are two ways to produce an OpenAPI document:
| Design-first | Code-first | |
|---|---|---|
| How | Write the OpenAPI file, review it, then implement the API | Annotate or type your code; a framework generates the file |
| Pros | Agreement before coding; front-end and back-end work in parallel; mocks from day one | No duplicate source of truth; docs always match the code |
| Cons | Spec and code can drift unless you validate against each other | API design gets shaped by implementation details |
| Common tools | Swagger Editor, Stoplight, plain YAML in Git | FastAPI, NestJS, Spring (springdoc), ASP.NET, Go generators |
Either works. The important part is keeping the document accurate, ideally by validating responses against it in tests.
Describing Authentication
OpenAPI documents also describe how clients authenticate, so documentation and generated clients handle it automatically. Schemes are defined once under components/securitySchemes and applied globally or per operation:
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
apiKey:
type: apiKey
in: header
name: X-API-Key
security:
- bearerAuth: []Supported types include API keys (in a header, query string or cookie), HTTP authentication such as Basic and Bearer, OAuth 2.0 flows with their scopes, OpenID Connect discovery and, since 3.1, mutual TLS. Swagger UI uses these definitions to show an "Authorize" button, so readers can try authenticated calls.
Keeping the Document Accurate
An OpenAPI file that doesn't match the API is worse than none, because clients and tests trust it. Practical ways to keep them in step:
- Lint on every pull request with a tool such as Spectral, using rules for naming, descriptions, examples and error formats.
- Detect breaking changes by diffing the new document against the last release; removed fields, new required parameters and changed types should fail the build or need sign-off.
- Validate real traffic in tests: check that responses match the documented schemas, and that the server rejects requests the document says are invalid.
- Generate where you can. Generating the document from code, or code from the document, removes one copy that could drift.
- Version the document with the code in the same repository, and publish it with each release.
OpenAPI for AI Agents and Integrations
A good OpenAPI document has a new audience: software that reads it to call your API. Integration platforms import OpenAPI files to build connectors, API gateways use them to configure routes and validation, and many AI agent frameworks can turn an OpenAPI description into tools a language model can call. Clear operation summaries, parameter descriptions and examples help these tools as much as they help human readers.
The OpenAPI Initiative also maintains companion specifications: Arazzo for describing multi-step API workflows, and Overlay for applying repeatable changes to an OpenAPI document, such as adding descriptions for a public version.
OpenAPI and Other API Styles
OpenAPI describes REST-style HTTP APIs. Other styles use their own description formats: GraphQL APIs are described by their schema, gRPC by Protocol Buffers files, and event-driven APIs often by AsyncAPI. Our comparisons of REST vs GraphQL and gRPC vs REST cover when each style fits.
OpenAPI vs Swagger: Which Should You Use?
There's no real choice between them: you write an OpenAPI document, and you can use Swagger tools (or others) to work with it.
- New API: use OpenAPI 3.1 for the widest tool support; adopt 3.2 features once your toolchain supports them.
- Existing Swagger 2.0 file: migrate to OpenAPI 3.x when you next touch the API seriously, since newer tools increasingly expect it.
- Documentation: Swagger UI for try-it-out docs; Redoc or Scalar for reference-style docs.
- SDKs: OpenAPI Generator or a commercial SDK generator.
- Quality: lint with Spectral and validate requests in CI.
Common Mistakes
- Saying "Swagger" when you mean the spec version. Specify "OpenAPI 3.1" or "Swagger 2.0" so tools and teammates know what to expect.
- Letting the document drift from the real API.
- Overusing `additionalProperties: true` and loose schemas, which make generated clients weak.
- Skipping examples. Good examples make documentation and mocks far more useful.
- Assuming every tool supports every version. Check support for 3.1 and 3.2 before upgrading.
FAQ
Is Swagger still used?
Yes. Swagger UI, Swagger Editor and Swagger Codegen are widely used, and many older APIs still have Swagger 2.0 documents.
Is OpenAPI only for REST APIs?
It describes HTTP APIs, which in practice means REST-style APIs. GraphQL, gRPC and event-driven APIs use their own description formats.
Should I write OpenAPI in YAML or JSON?
Either is valid. YAML is easier for people to read and write; JSON is easier for some tools. Many teams author in YAML and convert to JSON when needed.
Can Swagger UI display OpenAPI 3.1?
Recent versions support OpenAPI 3.0 and 3.1. Check the release notes for your version, and for OpenAPI 3.2 support.
What is the difference between OpenAPI and an API schema?
An OpenAPI document describes the whole API: paths, operations, security and data. A schema usually means the shape of one data object, which OpenAPI defines using JSON Schema.