stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI v3.1, v3.0, and v2.0 as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.37k stars 228 forks source link

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

Open pemba-sherpa-sage opened 5 months ago

pemba-sherpa-sage commented 5 months ago

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:

2. the following spectral rule: (.spectral.yml)
```yaml
extends: spectral:oas
  1. Run this CLI command '....'
    spectral lint --ruleset=.spectral.yml name.yaml

Expected behavior

Environment (remove any that are not applicable):