Skip to content

False positive: oas3-examples-value-or-externalValue incorrectly reported on valid examples when broken $ref exists #2837

@Relequestual

Description

@Relequestual

Description

The oas3-examples-value-or-externalValue rule incorrectly reports errors against valid examples in components/examples when there are broken $ref references to non-existent examples elsewhere in the OpenAPI file.

Expected Behavior

  • Valid examples with proper value or externalValue fields should pass validation
  • The oas3-examples-value-or-externalValue rule should not trigger false positives

Actual Behavior

  • Valid examples in components/examples that have proper value fields are incorrectly flagged
  • Error is reported at path: ["components", "examples"] instead of the broken reference location

Minimal Reproduction

File: minimal-reproduction.yaml

openapi: 3.0.3
info:
  title: Minimal Test
  version: 1.0.0
paths:
  /test:
    get:
      responses:
        '200':
          content:
            application/json:
              examples:
                test:
                  $ref: '#/components/examples/non-existent'  # ← BROKEN REFERENCE
components:
  examples:
    valid-example:      # ← CORRECTLY FORMATTED
      value:
        test: "data"

Command to reproduce:

spectral lint minimal-reproduction.yaml

Expected output: Error about broken $ref reference
Actual output:

{
  "code": "oas3-examples-value-or-externalValue",
  "path": ["components", "examples"],
  "message": "Examples must have either \"value\" or \"externalValue\" field.",
  "range": {
    "start": {"line": 15, "character": 11},
    "end": {"line": 18, "character": 20}
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions