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

Incorrect example validation on OpenAPI and examples vlaidation on AsyncAPI when using allOf. #2596

Open
Swimburger opened this issue Mar 11, 2024 · 0 comments

Comments

@Swimburger
Copy link

Describe the bug
When using allOf to merge schema's, the example property in OpenAPI, and examples in AsyncAPI, is incorrectly validated.

To Reproduce

  1. Given this OpenAPI/AsyncAPI document '...'
openapi: 3.1.0

components:
  schemas:
    Foo:
      type: object
      additionalProperties: false
      allOf:
        - $ref: "#/components/schemas/Bar"
        - type: object
          required: [prop2]
          additionalProperties: false
          properties:
            prop2:
              type: string
      example:
        {
          prop1: "test",
          prop2: "test",
        }

    Bar:
      type: object
      additionalProperties: false
      properties:
        prop1:
          type: string
asyncapi: 2.6.0

channels:
  /:
    subscribe:
      operationId: operation-id
      message:
        oneOf:
          - $ref: "#/components/messages/Foo"

components:
  messages:
    Foo:
      messageId: foo
      payload:
        $ref: "#/components/schemas/Foo"

  schemas:
    Foo:
      type: object
      additionalProperties: false
      allOf:
        - $ref: "#/components/schemas/Bar"
        - type: object
          required: [prop2]
          additionalProperties: false
          properties:
            prop2:
              type: string
      examples:
      - {
          prop1: "test",
          prop2: "test",
        }

    Bar:
      type: object
      additionalProperties: false
      properties:
        prop1:
          type: string
  1. with the following spectral config:
extends: ["spectral:oas", "spectral:asyncapi"]
  1. Run this CLI command '....'
spectral lint {openapi,asyncapi}.yml --ruleset .spectral.yml
  1. See error
/Users/niels/spectral-repro/asyncapi.yml
  1:1  warning  asyncapi-info-contact           Info object must have "contact" object.
  1:1  warning  asyncapi-info-description       Info "description" must be present and non-empty string.
  1:1  warning  asyncapi-info-license           Info object must have "license" object.
  1:1    error  asyncapi-schema                 Object must have required property "info"
  1:1  warning  asyncapi-servers                AsyncAPI object must have non-empty "servers" object.
  1:1  warning  asyncapi-tags                   AsyncAPI object must have non-empty "tags" array.
 5:15  warning  asyncapi-operation-description  Operation "description" must be present and non-empty string.  channels./.subscribe
 31:9    error  asyncapi-payload-examples       Property "prop2" is not expected to be here                    components.schemas.Foo.examples[0]
 31:9    error  asyncapi-payload-examples       Property "prop1" is not expected to be here                    components.schemas.Foo.examples[0]
 31:9    error  asyncapi-schema-examples        Property "prop2" is not expected to be here                    components.schemas.Foo.examples[0]
 31:9    error  asyncapi-schema-examples        Property "prop1" is not expected to be here                    components.schemas.Foo.examples[0]

/Users/niels/spectral-repro/openapi.yml
  1:1   warning  info-contact               Info object must have "contact" object.
  1:1   warning  info-description           Info "description" must be present and non-empty string.
  1:1   warning  oas3-api-servers           OpenAPI "servers" must be present and non-empty array.
  1:1     error  oas3-schema                Object must have required property "info".
  5:9   warning  oas3-unused-component      Potentially unused component has been detected.           components.schemas.Foo
 16:15    error  oas3-valid-schema-example  Property "prop2" is not expected to be here               components.schemas.Foo.example

✖ 17 problems (7 errors, 10 warnings, 0 infos, 0 hints)

Expected behavior
asyncapi-payload-examples, asyncapi-schema-examples, and oas3-valid-schema-example, should not be thrown.

Environment (remove any that are not applicable):

  • Library version: 6.11.0
  • OS: macOS 14.2.1

You can find a repo reproducing the issue here: https://github.com/Swimburger/spectral-repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants