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

oas3-valid-media-example not catching some bad example values #2580

Open
pemba-sherpa-sage opened this issue Jan 22, 2024 · 0 comments
Open
Labels
p/medium t/bug Something isn't working triaged

Comments

@pemba-sherpa-sage
Copy link

Describe the bug
oas3-valid-media-example doesn't flag the stray field provided in the media example as an error

To Reproduce

  1. Given this OpenAPI/AsyncAPI document (name.yaml)
openapi: 3.0.0
info:
  title: Sample API
  version: 1.0.0
  description: Sample OpenAPI Spec with a Schema

paths:
  /sample:
    get:
      summary: Get Sample Data
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SampleSchema'
              example:
                name: null     # this is caught by the spectral rule
                dateOfBirth: 1990-01-01
                status: test  # this not caught by the spectral rule until the first error (name) is fixed
                age: 12      # this does not exist in the schema

components:
  schemas:
    SampleSchema:
      type: object
      properties:
        name:
          type: string
          example: John Doe
        dateOfBirth:
          type: string
          format: date
          example: 1990-01-01
        status:
          type: string
          enum:
            - active
            - inactive
          example: active
  1. the following spectral rule: (.spectral.yml)
extends: spectral:oas
  1. Run this CLI command '....'
spectral lint --ruleset=.spectral.yml name.yaml

Expected behavior

  • The rule should flag the stray field provided in the example (i.e age) since it does not exist in the schema
  • If an example is bad, it stops at the first bad example and doesn't process others until you fix it. I believe it should catch all instead of fail on first for example evaluation

Environment (remove any that are not applicable):

  • Spectral version 6.5.0
  • OS: Darwin/Mac
@mnaumanali94 mnaumanali94 added t/bug Something isn't working p/medium labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p/medium t/bug Something isn't working triaged
Projects
None yet
Development

No branches or pull requests

2 participants