Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema Validation Error for Example in OpenAPI 3.0.0 Document #2669

Open
sandeep2rawat opened this issue Aug 16, 2024 · 0 comments
Open

Schema Validation Error for Example in OpenAPI 3.0.0 Document #2669

sandeep2rawat opened this issue Aug 16, 2024 · 0 comments

Comments

@sandeep2rawat
Copy link

Description:
I'm encountering an issue with Spectral when validating an OpenAPI 3.0.0 document. The error is raised in the example section of a schema definition. The issue seems to be related to the presence of the type: HEADER property within the example, which causes Spectral to throw a validation error. However, when the type property is removed from the example, the validation passes without any errors.

OpenAPI Document:
Here's a minimal reproducible example of the OpenAPI document that triggers the issue:

openapi: 3.0.0
info:
  title: ''
  version: '1.0'
paths: {}
components:
  schemas:
    Template:
      type: object
      title: ''
      description: Message Template
      properties:
        components:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - HEADER
                  - BODY
                  - BUTTONS
                  - FOOTER
                example: BODY
              text:
                type: string
                example: >-
                  hello {{var_1}}, we have an upcoming mega sale event at {{var_2}},
                  please check attached location
              example:
                type: object
                properties:
                  month:
                    type: string
      example:
        components:
          - text: '{{month}} Sale Offer'
            type: HEADER
            example:
              month: June

Error Message:
When running Spectral, I receive the following error:

schema is invalid: data/type must be equal to one of the allowed values, data/type must be array, data/type must match a schema in anyOf

Steps to Reproduce:

  1. Create an OpenAPI 3.0.0 document with the schema definition provided above.
  2. Run the Spectral linter on the document (Or paste it in stoplight app).
  3. Observe the validation error reported by Spectral.

Additional Context:

  • The error appears to be associated with the type: HEADER field within the example.
  • If the type: HEADER is removed from the example, the validation passes without any errors.

Expected Behavior:
The example should be considered valid by Spectral, or the error message should clearly explain why the example is invalid according to the OpenAPI specification.

Environment:

  • Spectral version: Using stoplight app
  • OpenAPI version: 3.0.0

Attaching the screenshot for reference.

With error
image
Without error (commented type)
image

@sandeep2rawat sandeep2rawat changed the title Schema Validation Error for Example in OpenAPI 3.1.0 Document Schema Validation Error for Example in OpenAPI 3.0.0 Document Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant