Quick answer: OpenAPI is a machine-readable contract that describes an HTTP API — its paths, operations, request and response shapes, authentication, and examples. Treat it as the single source of truth and let it drive design, debugging, testing, mocking, documentation, code generation, and MCP servers. The spec pays off when it lives in version control, gets validated in CI, and is written before the code; a document that is reverse-engineered after release and then left to drift is little more than decoration.

This guide collects the decisions that actually come up when you run OpenAPI on a real service: which version to target, how to split a document that grows past a few hundred lines, how to model the data shapes that break naive codegen, and how to keep the contract honest over time. Each section links to a focused article with concrete examples.

All articles in this guide

Each article below is a focused, pain-point-driven read that belongs to this hub. New ones are added on a regular schedule; the ones still in progress are marked.

1Case

A Saved API Example Drifts from the Spec

A saved response example stops matching the API. Keeping examples bound to the spec.

Read the article →
2Case

Committed Generated Types Silently Drift from the Spec

Generated types checked into the repo fall behind the spec. Regenerating in CI instead.

Read the article →
3Case

What Changed in OpenAPI 3.2 for SSE and AI

The 3.2 changes that matter for streaming and AI tooling, without the changelog noise.

Read the article →
4Case

Nullable, Optional, and Omitted Data in OpenAPI 3.1

Null, optional, and missing fields are distinct. Getting the 3.1 model right.

Read the article →
5Case

oneOf, anyOf, allOf, and Discriminator Polymorphism

Choosing between the composition keywords and when a discriminator actually helps.

Read the article →
6Case

PATCH: JSON Merge Patch vs RFC 6902 vs PUT

Partial updates three ways, with the failure modes of each approach.

Read the article →
7Case

OpenAPI Linting with Spectral and a Style Guide in CI

Catching style and contract problems in CI before they reach review.

Read the article →
8Case

API Deprecation and the Sunset Header Policy

Retiring an endpoint without breaking clients: versioning, Sunset, and the timeline.

Read the article →
9Case

Designing Cursor Pagination: Why Offset Hits a Wall

Cursors return a stable position so live feeds do not skip or duplicate, while deep pages stay cheap.

Read the article →
10Case

OpenAPI default Values: Convenient for Docs, Dangerous for Validation

Treat defaults as documentation and verify them against live behavior rather than relying on mocks.

Read the article →
11Case

Query Parameter Serialization: Why explode and deepObject Quietly Break Clients

Why array and object query parameters need explicit style and explode to avoid silent contract drift.

Read the article →
12Case

Defining File Uploads: multipart/form-data vs Base64 Bodies

When to model uploads as multipart binary and when Base64 bytes are justified by a JSON-only transport.

Read the article →
13Case

Defining Webhooks and Callbacks in OpenAPI: Outbound Requests as Part of the Contract

How to document outbound webhooks and callbacks as a full contract with signing and ack behavior.

Read the article →
14Case

Using OpenAPI links to Connect a Response to the Next Request

How to declare links between operations so generated clients can follow workflows instead of hardcoding field extraction.

Read the article →
15Case

Defining Multiple Security Schemes and When a Client Sends the Wrong One

Declaring multiple security schemes per operation so clients send the right credential instead of a mismatched one.

Read the article →
16Case

Templating the servers Object with Variables for Local, Staging, and Production

Templating base URLs across environments with server variables.

Read the article →
17Case

Defining HEAD and OPTIONS: What the Contract Must Guarantee Beyond GET

What HEAD and OPTIONS must guarantee and how to document the metadata methods.

Read the article →

What OpenAPI is and when to write it

An OpenAPI document is a structured description of an API, usually written in YAML or JSON. The workflow that holds up over years is design-first: agree on the contract, review it like code, and only then implement against it. The case for doing this — and the cost of skipping it — is laid out in designing an API before the first line of code. If you are on the other side of that problem, inheriting a running service with no contract, the honest path is to scan code into OpenAPI without hallucinating; the story of doing exactly that is in we inherited a service with no OpenAPI.

Versions: 3.0, 3.1, and what 3.2 changes

Most teams should target 3.1 today, because it aligns the schema dialect with JSON Schema and removes the awkward nullable workaround. If you are deciding what to adopt, read what changed in OpenAPI 3.2 for SSE and AI. The practical differences between nullable, optional fields, and an explicitly omitted value are easy to get wrong; nullable, optional, and omitted data in 3.1 works through them with before/after documents.

Structure: multi-file documents and reusable components

Once a document covers more than a handful of operations, a single flat file becomes unmaintainable. Split paths and schemas into separate files and link them with $ref. The patterns for doing this without creating a tangle of relative paths are in reusable JSON Schema components and $ref. Two structures repeatedly cause trouble: recursive and cyclic schema refs (think trees and threads) and free-form maps, covered in additionalProperties and free-form objects.

Data modeling: the shapes that break naive clients

Plain objects and strings are easy; the edge cases are where generated clients and mocks fall apart. Work through these as you meet them:

Operations: naming, servers, and common endpoint patterns

The metadata around an operation is what makes codegen and docs usable. Pick stable operationId values and consistent tag names following operationId and tag naming conventions, and describe environments with servers, server variables, and multiple environments. A handful of endpoint patterns recur across almost every API; each has a dedicated article:

Authentication and security

Describe how a caller authenticates rather than leaving it to prose. Start with documenting API authentication with security schemes, then handle multiple schemes, AND/OR logic, and optional auth. Enforce the contract at the edge with request validation middleware, and expose the standard probes in health, readiness, and liveness endpoints.

Reliability: rate limits, concurrency, and deprecation

A good contract tells callers how to behave under contention and how to migrate. Communicate throttling with 429 and Retry-After, guard concurrent edits with ETag and If-Match, and retire endpoints cleanly using an API deprecation and Sunset policy.

Keeping the contract honest: linting, examples, and docs

A contract that silently drifts is worse than none, because people trust it. Enforce style and structural rules in CI with Spectral and a style guide, keep examples as a single source of truth — the failure mode when they don't is in a saved API example drifting from the spec — and render it for humans by choosing among Swagger UI, Redoc, Scalar, and Elements.

Recovering a spec from existing code

When the code came first, generate a draft from the framework rather than hand-writing it, then verify the result. The routes are framework-specific: generate OpenAPI from Express and NestJS, and from FastAPI and Django REST, with the general approach in generating OpenAPI from existing code. Understand where automated recovery must stay honest — and where it cannot infer intent — in AST vs AI reverse engineering and the honest gaps.

Where to go next

Powerduck is the local-first, OpenAPI-first workspace that carries this whole flow — from the contract through debug, test, mock, and the tools an agent can call. See it on the Powerduck homepage.

OpenAPI is the spine, but the contract only delivers value when it drives the rest of the lifecycle. From here, move into API testing, mocking, code generation, and — once you want AI agents to call the API correctly — the MCP server guide. If you are comparing tools to work with the spec, the Postman alternatives page compares the local-first, OpenAPI-first options.

Frequently asked questions

Q

Should I write OpenAPI in YAML or JSON?

A

YAML is more readable for hand-authored design and supports comments; JSON is easier to generate and diff mechanically. Both are valid; use whichever your workflow produces, and keep it in version control.

Q

Can OpenAPI describe event-driven or streaming APIs?

A

It describes the HTTP entry points well, and 3.2 adds better support for streamed responses; the semantics of brokers and message schemas are better expressed with AsyncJSON Schema or an event-specific spec. For testing streams, see SSE and WebSocket.

Q

How do I stop generated clients drifting from the spec?

A

Regenerate as part of CI, never hand-edit the output, and fail the build on diffs; the failure mode is documented in generated types silently drifting.