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.35k stars 226 forks source link

asyncapi asyncApi2SchemaValidation does not allow string examples for other schema types #2624

Open timonback opened 1 month ago

timonback commented 1 month ago

Describe the bug The spectral rule asyncApi2SchemaValidation currently enforces that all examples have the same type as the schema type. However, we believe that there are cases in AsyncAPI, where it is needed to accept string examples regardless of the schema type.

To Reproduce

  1. Use the AsyncAPI document: https://github.com/asyncapi/spec/issues/1038#issuecomment-1969489452
  2. Open it in AsyncAPI studio (Or run the cli)
    1. Run spectral lint --ruleset rule.yaml test.yaml
    2. With rule.yaml: extends: "spectral:asyncapi"
    3. We had to change the version to 2.6.0, as the cli does not support 3.0.0 yet
  3. See the error: 66:11 error asyncapi-schema-examples "0" property type must be object components.schemas.io.github.springwolf.examples.kafka.dtos.XmlPayloadDto.examples[0]

Expected behavior No error/validation message

Screenshots N/A

Environment (remove any that are not applicable):

Additional context We are embedding xml and/or yaml as string in examples in an AsyncAPI (JSON) document.

Relates to https://github.com/asyncapi/spec/issues/1038

timonback commented 2 weeks ago

Update: Identical PR in parser-js has been merged: https://github.com/asyncapi/parser-js/pull/1007

EDIT: actually, it was only updated, not merged yet