Table of Contents

OpenAPI document structures

Sources

Structure by Version

surprising how much the structure can change between versions; here's a handful of versions to show that. note the structure is the same for JSON and YAML versions.

3.0.1

3.0.2

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md

3.0.3

https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md

3.0.4

3.1.0

3.1.1

Gotchas

$ref can NOT have ANY sibling elements so in order to, say, add a description to a field with a $refed type you need to wrap the ref in a “allOf”:[{}] e.g., instead of

"data": {
  "description": "List of Contacts",
  "$ref": "#/components/schemas/ContactArray"
}

use

"data": {
  "description": "List of Contacts",
  "allOf":[{"$ref": "#/components/schemas/ContactArray"}]
}

otherwise the description will be lost because according to https://swagger.io/docs/specification/v3_0/using-ref/

Any sibling elements of a ''$ref'' are ignored. This is because ''$ref'' works by replacing itself and everything on its level with the definition it is pointing at.