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.
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md
$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.