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

False "oas3-valid-media-example" error reported: "property must match exactly one schema in oneOf" #2612

Open
JPPortier opened this issue Apr 11, 2024 · 0 comments

Comments

@JPPortier
Copy link

Describe the bug

When validating an example with oneOf schema, an oas3-valid-media-exampleerror is reported even if correct

To Reproduce

  1. Given this OpenAPI/AsyncAPI document
    spectral-issue-poc.yaml file content:
openapi: 3.0.2
info:
  description: POC
  title: POC
  version: "1.0"
  license:
    name: MIT
    url: "https://www.poc.com"
  contact:
    email: support@poc.com
    name: support at poc
    url : "https://www.poc.com"
servers:
  - url: https://foo.com
security:
  - Basic: []
tags:
  - description: foo description
    name: Poc
paths:
  '/poc':
    post:
      description: foo description
      tags:
        - Poc
      summary: Trigger a poc
      operationId: poc-operation
      requestBody:
        $ref: "#/components/requestBodies/poc-request"
      responses:
        "200":
          description: "Done"
components:
  examples:

    poc-sample:
      summary: poc sample
      value:
        message:
          text_message:
            text: "This is a text message."

  requestBodies:
    poc-request:
      description: This is the request body for sending a message. `app_id`, `recipient`, and `message` are all required fields.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/poc-payload-request"
          examples:
            sample:
              $ref: "#/components/examples/poc-sample"
      required: true

  schemas:
    poc-payload-request:
      type: object
      required:
        - "message"
      properties:
        message:
          $ref: "#/components/schemas/message-types"

    message-types:
      type: object
      oneOf:
        - $ref: "#/components/schemas/message-type-foo"
        - $ref: "#/components/schemas/message-type-text"

    message-type-foo:
      type: object
      properties:
        foo_message:
          type: object
          required:
            - foo
          properties:
            foo:
              type: string
    message-type-text:
      type: object
      properties:
        text_message:
          type: object
          required:
            - text
          properties:
            text:
              type: string

  securitySchemes:
    Basic:
      type: http
      scheme: basic

And this ruleset.yaml file:

extends: ["spectral:oas"]
  1. Run this CLI command '....'
spectral lint "spectral-issue-poc.yaml" --ruleset ruleset.yaml
  1. See error
spectral-issue-poc.yaml
 39:17  error  oas3-valid-media-example  "message" property must match exactly one schema in oneOf  components.examples.poc-sample.value.message

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)

Expected behavior
Example is compliant with spec and error should not been reported

Environment (remove any that are not applicable):

Additional context
Add any other context about the problem here.

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