OpenAPI 3.0 Documentation
Team standard: OpenAPI Specification 3.0.x
OAS 3.1 and 3.2 exist as newer versions with full JSON Schema alignment; migrate when tooling support matures.
Rules below are either spec (required by OAS 3.0.x — violations break tooling) or convention (industry best practice from OpenAPI Initiative — violations hurt developer experience).
Core Principle
Documentation is complete when a developer who has never seen the codebase can:
- Understand what each endpoint does from
summary + description alone
- Know exactly what to send from the request schema + examples
- Know all possible responses including errors — without asking the implementer
Naming Rules (convention)
| Element |
Convention |
Rule |
operationId |
camelCase verb+noun |
Unique across entire spec. Name the capability: createOrder not postV1Orders |
| Schema names |
PascalCase |
CreateUserRequest, OrderResponse — in components/schemas, not inline |
| Tag names |
Title Case |
Match resource noun: Users, Orders, Payment Methods |
| Parameter names |
camelCase |
userId, pageSize, sortOrder |
| Max length |
50 chars |
Names over 50 chars break SDK generators and portals |
Every Operation Must Have (spec + convention)
| Field |
Rule |
summary |
One sentence, verb-first: "Create a user account" — under 50 chars |
description |
Business context: when to call this, side effects, rate limits, preconditions |
operationId |
Unique camelCase verb+noun |
tags |
At least one tag matching a resource group |
security |
Declare the auth scheme, or [] for explicitly public endpoints |
responses |
At least one 2xx + all expected 4xx errors |
Schema Rules
- No inline schemas (convention) — define all schemas in
components/schemas, reference with $ref
- Every property has
description (convention) — explain business meaning, not just the type
- Every property has
example (convention) — use realistic data, never "string", 1, or true
- Examples must be valid (spec) — they must conform to the schema (tools use them for test generation)
- Required parameters before optional (convention) — in
required array and parameter lists
- Use
format (convention) where applicable: email, date-time, uuid, uri, int64
- Document every
enum value (convention) — explain what each value means in description
Response Rules
- Document all response codes the endpoint can realistically return
- Every error response includes: machine-readable
code + human-readable message
- Reuse error response schema via
$ref — consistent shape across all endpoints
- 4xx responses always have an
example showing real error payload
GET endpoints must have at least one 2xx response with content (not just 204)
Reusability Rules (DRY)
- Common responses (
401 Unauthorized, 500 Internal Server Error) → components/responses
- Common schemas (error body, pagination, timestamps) →
components/schemas
- Common parameters (
page, limit, Authorization header) → components/parameters
- Security schemes →
components/securitySchemes, applied globally, overridden per-endpoint
- Never repeat the same schema inline in multiple places
File & Structure Rules
- Spec file committed to source control as a first-class artifact (convention — OpenAPI Initiative)
servers array not empty — include at least production + staging URLs (convention)
info.contact includes team name or support email (convention)
info.description explains what the service does and who consumes it (convention)
- Tags defined at root level with descriptions (convention)
- Large APIs (>20 endpoints): split into multiple files using
$ref with URL hierarchy (convention)
Quality Checklist
Before finalizing OpenAPI docs:
Structure
Operations
Schemas
Responses
Reusability
Validation Tools
Use these to catch spec errors automatically:
- Spectral (by Stoplight) — linting rules engine, supports custom rulesets
- Swagger Editor — browser-based, real-time validation
- openapi-validator (IBM) — CLI validation
- Integrate into CI: fail PR if spec fails linting rules
1---2name: swagger-docs3description: Use when writing or updating Swagger/OpenAPI docs, documenting new endpoints, reviewing existing API docs for completeness, or generating OpenAPI spec from code. Skip when the API is internal-only with no external consumers and no doc requirement. Skip when making API design decisions (endpoint naming, HTTP conventions, versioning strategy) — use api-design instead.4---56# OpenAPI 3.0 Documentation78**Team standard**: [OpenAPI Specification 3.0.x](https://spec.openapis.org/oas/v3.0.3)9OAS 3.1 and 3.2 exist as newer versions with full JSON Schema alignment; migrate when tooling support matures.10Rules below are either **spec** (required by OAS 3.0.x — violations break tooling) or **convention** (industry best practice from OpenAPI Initiative — violations hurt developer experience).1112---1314## Core Principle1516Documentation is complete when a developer who has never seen the codebase can:171. Understand what each endpoint does from `summary` + `description` alone182. Know exactly what to send from the request schema + examples193. Know all possible responses including errors — without asking the implementer2021---2223## Naming Rules *(convention)*2425| Element | Convention | Rule |26|---------|-----------|------|27| `operationId` | `camelCase` verb+noun | Unique across entire spec. Name the capability: `createOrder` not `postV1Orders` |28| Schema names | `PascalCase` | `CreateUserRequest`, `OrderResponse` — in `components/schemas`, not inline |29| Tag names | `Title Case` | Match resource noun: `Users`, `Orders`, `Payment Methods` |30| Parameter names | `camelCase` | `userId`, `pageSize`, `sortOrder` |31| Max length | 50 chars | Names over 50 chars break SDK generators and portals |3233---3435## Every Operation Must Have *(spec + convention)*3637| Field | Rule |38|-------|------|39| `summary` | One sentence, verb-first: "Create a user account" — under 50 chars |40| `description` | Business context: when to call this, side effects, rate limits, preconditions |41| `operationId` | Unique camelCase verb+noun |42| `tags` | At least one tag matching a resource group |43| `security` | Declare the auth scheme, or `[]` for explicitly public endpoints |44| `responses` | At least one 2xx + all expected 4xx errors |4546---4748## Schema Rules4950- **No inline schemas** *(convention)* — define all schemas in `components/schemas`, reference with `$ref`51- **Every property has `description`** *(convention)* — explain business meaning, not just the type52- **Every property has `example`** *(convention)* — use realistic data, never `"string"`, `1`, or `true`53- **Examples must be valid** *(spec)* — they must conform to the schema (tools use them for test generation)54- **Required parameters before optional** *(convention)* — in `required` array and parameter lists55- **Use `format`** *(convention)* where applicable: `email`, `date-time`, `uuid`, `uri`, `int64`56- **Document every `enum` value** *(convention)* — explain what each value means in `description`5758---5960## Response Rules6162- Document **all** response codes the endpoint can realistically return63- Every error response includes: machine-readable `code` + human-readable `message`64- Reuse error response schema via `$ref` — consistent shape across all endpoints65- 4xx responses always have an `example` showing real error payload66- `GET` endpoints must have at least one 2xx response with content (not just 204)6768---6970## Reusability Rules (DRY)7172- Common responses (`401 Unauthorized`, `500 Internal Server Error`) → `components/responses`73- Common schemas (error body, pagination, timestamps) → `components/schemas`74- Common parameters (`page`, `limit`, `Authorization` header) → `components/parameters`75- Security schemes → `components/securitySchemes`, applied globally, overridden per-endpoint76- Never repeat the same schema inline in multiple places7778---7980## File & Structure Rules8182- Spec file committed to source control as a first-class artifact *(convention — OpenAPI Initiative)*83- `servers` array not empty — include at least production + staging URLs *(convention)*84- `info.contact` includes team name or support email *(convention)*85- `info.description` explains what the service does and who consumes it *(convention)*86- Tags defined at root level with descriptions *(convention)*87- Large APIs (>20 endpoints): split into multiple files using `$ref` with URL hierarchy *(convention)*8889---9091## Quality Checklist9293Before finalizing OpenAPI docs:9495**Structure**96- [ ] `servers` is not empty97- [ ] `info.contact` is filled98- [ ] All tags defined at root with descriptions99- [ ] Spec committed to source control100101**Operations**102- [ ] Every operation has `summary`, `description`, `operationId`, `tags`, `security`103- [ ] `operationId` is unique, camelCase, under 50 chars104- [ ] Required parameters listed before optional105106**Schemas**107- [ ] No inline schemas — all in `components/schemas`108- [ ] Every property has `description` (business meaning, not type restatement)109- [ ] Every property has a realistic `example`110- [ ] All examples validated against their schema111- [ ] Enums have per-value explanations in `description`112113**Responses**114- [ ] All expected 4xx/5xx documented115- [ ] Error responses use consistent shared schema via `$ref`116- [ ] Every error response has a realistic `example`117118**Reusability**119- [ ] Common responses in `components/responses`120- [ ] No duplicated schema shapes — use `$ref`121122---123124## Validation Tools125126Use these to catch spec errors automatically:127- **Spectral** (by Stoplight) — linting rules engine, supports custom rulesets128- **Swagger Editor** — browser-based, real-time validation129- **openapi-validator** (IBM) — CLI validation130- Integrate into CI: fail PR if spec fails linting rules