asyncapi-payload-examples
Examples must be valid against their defined schema.
- Applies to
examples- Selects
$.components.messageTraits[?(@.schemaFormat === void 0)].payload.examples^$.components.messages[?(@.schemaFormat === void 0)].payload.examples^$.channels[*][publish,subscribe][?(@property === 'message' && @.schemaFormat === void 0)].payload.examples^- Function
asyncApiSchemaValidation- Specs
- AsyncAPI 2.x
- Message
{{error}}
Use it
This rule ships with OpenLint in spectral:asyncapi. Extending the ruleset turns it on:
extends: spectral:asyncapi
rules:
asyncapi-payload-examples: error # or off, or another severity
Definition
As defined in @openlint/openlint-rulesets. Functions show by name.
asyncapi-payload-examples:
description: Examples must be valid against their defined schema.
message: '{{error}}'
severity: error
recommended: true
formats:
- AsyncAPI 2.x
given:
- '$.components.messageTraits[?(@.schemaFormat === void 0)].payload.examples^'
- '$.components.messages[?(@.schemaFormat === void 0)].payload.examples^'
- >-
$.channels[*][publish,subscribe][?(@property === 'message' &&
@.schemaFormat === void 0)].payload.examples^
then:
function: asyncApiSchemaValidation
functionOptions:
type: examples
About this rule
Values of the examples array should be valid against the payload they decorate.
Good Example
payload:
type: object
properties:
value:
type: integer
required:
- value
examples:
- value: 13
- value: 17
Bad Example
payload:
type: object
properties:
value:
type: integer
required:
- value
examples:
- value: nope! # Wrong type
- notGoodEither: 17 # Missing required property