Example cannot be a JSON reference pointing outside '#/components/examples'

Issue ID: v3-validation-reference-example

Description

One or more JSON references to reusable examples in your API point outside the #/components/examples object in the API definition. The $ref of all reusable examples must point to an example object in the components object, otherwise they have no effect.

For more details, see the OpenAPI Specification.

Example

The following is an example of how this issue could look in your API definition. Here, a reusable example has been defined, but it is incorrectly references from schemas and therefore ignored:

{
    "content": {
        "application/json": {
            "schema": {
                "type": "array",
                "items": {
                    "$ref": "#/components/schemas/Pet"
                }
            },
            "examples": {
                "objectExample": {
                    "$ref": "#/components/schemas/Pet"
                }
            }
        }
    }
}

Remediation

Make sure that all JSON references to reusable examples point to #/components/examples.

{
    "content": {
        "application/json": {
            "schema": {
                "type": "array",
                "items": {
                    "$ref": "#/components/schemas/Pet"
                }
            },
            "examples": {
                "objectExample": {
                    "$ref": "#/components/examples/Pet"
                }
            }
        }
    }
}