Skip to content

no-invalid-media-type-examples not triggering warning for unevaluated properties #2410

@Breed43214

Description

@Breed43214

Describe the bug

From v2.8.0 onwards, no-invalid-media-type-examples rule does not warn on invalid media type examples if any component schema contains an example when using the recommended ruleset.

To Reproduce

Take the example YAML below:

openapi: 3.0.3
info:
  title: Test API
  version: 1.0.0
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  description: |
    Test API for Bug Report
servers:
  - url: https://test.com/v1

security:
  - SAFTokenAuth: []
  - OAuth2: []

paths:
  /test1:
    get:
      summary: Test Request
      operationId: getTest1
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/testSchemaWithExamples"
              examples:
                scenario1:
                  value:
                    testArray:
                      - name: John
                        id: 1
                      - name: James
                        id: 2
                      - name: Joe
                        id: 3
                      - names: Jill
                        id: 4
        404:
          description: Not Found
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/errorResponse"
              examples:
                scenario1:
                  value:
                    code: 60
                    message: Not Found
                    reasons:
                      - errorReason: The requested resource could not be found and does not exist.
                        recommendedAction: Please correct the request and try again.
                        property: null
components:
  schemas:
    testSchemaWithExamples:
      type: object
      properties:
        testArray:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
                #example: Joe
              id:
                type: integer  
    errorResponse:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
        reasons:
          type: array
          items:
            type: object
            properties:
              errorReason:
                type: string
              recommendedAction:
                type: string
              property:
                type: string
                nullable: true
  securitySchemes:
    SAFTokenAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    OAuth2:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: /oauth/token
          scopes: {}

When running 'lint' as-is, it gives a Example value must conform to the schema: 3 property must NOT have unevaluated properties names. Rule: no-invalid-media-type-examples upon a lint as expected when using the default recommended ruleset. However, if the example in the schema on Line 73 #example: Joe is uncommented, then the no-invalid-media-type-examples does not flag a warning for ANY unevaluated properties.

It does seem not matter which property in the schema an example is configured for. An single schema example seems to prevent no-invalid-media-type-examples rule from triggering warnings.

Specifically enabling the manually in redocly.yaml with allowAdditionalProperties: false makes no difference.

Expected behavior

no-invalid-media-type-examples should always flag a warning for unevaluated properties regardless of whether an example is configured in a schema on the recommended ruleset (where allowAdditionalProperties: is false.)

Logs

Redocly version(s)

v2.11.0

Node.js version(s)

v22.21.1

OS, environment

Description: Ubuntu 24.04.3 LTS

Additional context

Last worked in v2.7.1. It has been broke since v2.8.0.

Metadata

Metadata

Labels

Type: BugSomething isn't workingp1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions