OpenAPI is a standard for describing an HTTP API in a single machine-readable file: its endpoints, parameters, request and response formats, and authentication method. Once that file exists, you can generate a documentation site, client code for several languages, tests and a mock server from the same source. As the API changes, they all update together.
What Is OpenAPI?
OpenAPI is a language-agnostic format for describing HTTP APIs. The OpenAPI Specification 3.2.0 (opens in a new tab) states its purpose as letting both humans and computers understand what a service can do without access to source code, extra documentation or network traffic. The document is written in YAML or JSON and usually lives in the project as openapi.yaml.
For each endpoint, the document records which HTTP method calls it, which parameters it takes, and what it returns on success and on error. Data structures are defined once and referenced everywhere else.
Why Does OpenAPI Make Your Life Easier?
The biggest gain is that everything about the API lives in one place. Without a spec, the docs sit on a wiki page, the client code sits in the mobile team's repository and the validation rules sit on the server, and over time they drift apart. An OpenAPI document becomes their shared source:
- The documentation site is generated from it, so handwritten pages never go stale.
- Client code is generated from it, so mobile and web teams work with the same types.
- Incoming requests can be validated against its schemas.
- Front-end work can start before the back end is ready, using a mock server built from the spec.
- Changes between versions can be diffed to catch breaking changes.
The same goes for teams integrating with outside partners. Handing over an OpenAPI document replaces a long email thread. I cover the wider integration process in the API integration guide.
What Does an OpenAPI Document Look Like?
Here's the definition of a small order API with a single endpoint:
openapi: 3.1.0
info:
title: Order API
version: 1.0.0
paths:
/orders/{id}:
get:
operationId: getOrder
summary: Get a single order
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: Order found
content:
application/json:
schema:
$ref: "#/components/schemas/Order"
"404":
description: Order not found
components:
schemas:
Order:
type: object
required: [id, status, total]
properties:
id: { type: string }
status: { type: string, enum: [pending, paid, shipped] }
total: { type: number }The paths section holds the endpoints and components holds reusable data structures. operationId looks like a minor detail, but it matters: client generators usually take function names from it. Leave it out and you'll get meaningless names in the generated code.
Design First or Code First?
There are two approaches. With design first, you write the document before any code and teams agree on it. With code first, the document is generated from definitions in your code, which many web frameworks support either directly or through an add-on package.
For an API that outside teams or customers will use, design first is the safer choice. The contract is clear from the start and the implementation has to follow it. For an internal API used only by your own front end, generating from code is practical. Whichever you pick, validate the document in your continuous integration (CI) pipeline so any gap between spec and code shows up early.
Generating a Documentation Site
Plenty of tools turn an OpenAPI document into an interactive documentation page. Swagger UI, Redoc and Scalar are among the most widely used. They group and list endpoints, show sample requests and responses, and some let readers send test requests straight from the page.
The quality of the docs depends more on the descriptions in your document than on the tool. A one-sentence summary for each endpoint, a short description for each field and realistic example values let readers get their work done without asking questions.
Generating API Clients
Client code may be the biggest payoff. The OpenAPI Generator project (opens in a new tab) says that with more than 50 client generators it can produce code for any server that exposes an OpenAPI document, and that API maintainers can ship those clients as official SDKs. The generated code comes with request functions, data models and type definitions.
A setup that works well in practice:
- Keep the document in the repository and put every change through code review.
- Validate the document and regenerate the client in your CI pipeline.
- Publish the generated client as a package or copy it into the front-end project.
- When a breaking change slips in, a build error shows you before your users notice.
Don't edit generated code by hand. The next generation run wipes out your changes. If you need customization, use the generator's options or templates.
Versions: 3.0, 3.1 and 3.2
You'll see three versions in the wild. The OpenAPI guide to upgrading from 3.0 to 3.1 (opens in a new tab) explains that 3.1 became fully compatible with JSON Schema Draft 2020-12. Earlier versions used a modified subset of JSON Schema, which caused confusion. The most common change during an upgrade is replacing nullable: true with a type array (type: [string, "null"]).
The OpenAPI Initiative released version 3.2.0 in its announcement of September 23, 2025 (opens in a new tab). Headline features include support for the query HTTP method for safe, idempotent queries, streaming media types, nested tags, and the OAuth 2.0 Device Authorization Flow for limited-input devices like smart TVs.
If you're starting a new project, 3.1 is well supported by most tools. Before moving to 3.2, check that your documentation and client generators support it.
OpenAPI and AI
A well-written OpenAPI document also pays off in AI integrations. OpenAI's function calling guide (opens in a new tab) explains that function tools given to a model are defined with JSON Schema. Since OpenAPI 3.1 schemas are JSON Schema compatible, handing your data structures to a model as tool definitions largely reuses work you've already done.
Here the descriptions in your document serve a second reader: the model decides which tool to call, and when, based on them. Writing "Returns the status and total of a single order by its order number" instead of just "getOrder" tells both developers and the model a lot more.
Still, don't expose your whole API to the model. Offer only the endpoints it really needs, with limited permissions. I collected what to watch for when connecting AI APIs to an application in the AI API integration guide.
Checklist for a Good OpenAPI Document
- Every operation has a meaningful
operationIdand a shortsummary. - Error responses (400, 401, 404, 422, 500) are defined alongside successful ones.
- The authentication method is declared under
securitySchemes. - Fields include example values and constraints (required, length,
enum). - Repeated structures are defined once under
components. - A lint tool checks the document in CI.
Frequently Asked Questions
Are Swagger and OpenAPI the same thing?
Not quite. OpenAPI is the name of the specification, maintained by the OpenAPI Initiative. Swagger is the name of a tool family that includes Swagger UI. Because the specification used to be called Swagger, people still mix the two up.
Can OpenAPI describe GraphQL APIs?
No. OpenAPI describes REST-style HTTP APIs, and GraphQL has its own schema language. I compare the two approaches in the post on REST vs GraphQL.
Is an OpenAPI document worth it for a small project?
If a single front end uses the API and the team is one person, a document generated from code is enough. If several clients, another team or an outside company will use the API, the document pays for itself quickly.
To build an API that's documented and ready for integration from day one, see the SaaS and custom software development service or tell me about your project on the contact page.



