The shape of an OpenAPI 3.1 document
An OpenAPI document is a single YAML or JSON object. The tool first checks that openapi, info and paths exist at the top, then walks down through paths, operations and component schemas. This article follows the same order the linter reads them.
Top-level fields
| Field | Role | When missing |
|---|---|---|
openapi | The specification version, 3.0.x or 3.1.x | error — without it no rule set can be chosen |
info | Title, version, description, contact and licence | error — the document has no human identity |
paths | Paths and the operations under each method | error — in 3.1 the key is required even when empty |
servers | Base URL and server variables | note — snippets need a base URL |
components | Reusable schemas, parameters and security schemes | note — not needed when nothing is referenced |
security | Security requirements for the whole document | note — some APIs are unauthenticated |
webhooks | Incoming event definitions added in 3.1 | error when used in 3.0 |
Paths and operations
Keys under paths are paths starting with /, and each value is a path item. A path item holds method keys such as get, post, put, patch and delete, and each method's value is an operation. An operation carries operationId, summary, description, tags, parameters, requestBody and responses.
operationIdmust be unique in the document. It becomes a function name in generated code, so avoid spaces.- Every
{id}in a path template needs anin: pathparameter, and that parameter needsrequired: true. summaryis one line anddescriptioncan be several. When both are missing the linter adds notes.
Where 3.0 and 3.1 part ways
| Topic | 3.0 | 3.1 |
|---|---|---|
| Allowing null | nullable: true | type: [string, 'null'] |
| Incoming events | absent | webhooks |
| Licence identifier | license.url only | license.identifier (SPDX) |
| JSON Schema | its own variant | aligned with JSON Schema 2020-12 |
Keys beside $ref | ignored | evaluated together |
The linter reports these differences as errors. A 3.0 document that puts null in a type array gets schema.nullTypeIn30, and a 3.1 document that keeps nullable gets schema.nullableIn31.
Schemas live in components
To reuse a structure across operations, define it under components.schemas and reference it as $ref: '#/components/schemas/Name'. This tool inlines references into a tree, marks schemas that nothing references, and when a reference leads back to itself it reports a cycle and stops expanding at that point.
If you are starting out, three required fields and a single operation are enough. The linter will list what is missing in order, so building from an empty document and deleting diagnostics as you go is a fast route.
Questions
Can one document mix 3.0 and 3.1?
No. The openapi value fixes the rules for the whole document. During a migration, keep a separate 3.1 document and run this tool over each one.
May paths be empty?
3.1 allows paths as an empty object. If a document only has webhooks, this tool still reports the missing paths key, so add an empty object when there really are no paths.
Is servers required?
It is optional in the specification, but the first server URL helps both snippet generation and readers. With a relative path such as /v1 the tool prefixes api.example.com for its examples.
The synthetic rest-31 preset is a complete 3.1 document of this shape. Load it to see a run with zero errors.
Written against the OpenAPI Specification 3.1.0 (2021-02), 3.0.3 and JSON Schema 2020-12. Every example spec and host is synthetic.