asyncapi-message-examples
Examples of message object should follow by "payload" and "headers" schemas.
- Applies to
messagemessageTraitsmessagesoneOftraits- Selects
$.channels.*.[publish,subscribe].message$.channels.*.[publish,subscribe].message.oneOf.*$.components.channels.*.[publish,subscribe].message$.components.channels.*.[publish,subscribe].message.oneOf.*$.components.messages.*$.channels.*.[publish,subscribe].message.traits.*$.channels.*.[publish,subscribe].message.oneOf.*.traits.*$.components.channels.*.[publish,subscribe].message.traits.*$.components.channels.*.[publish,subscribe].message.oneOf.*.traits.*$.components.messages.*.traits.*$.components.messageTraits.*- Function
asyncApi2MessageExamplesValidation- 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-message-examples: error # or off, or another severity
Definition
As defined in @openlint/openlint-rulesets. Functions show by name.
asyncapi-message-examples:
description: Examples of message object should follow by "payload" and "headers" schemas.
message: '{{error}}'
severity: error
recommended: true
formats:
- AsyncAPI 2.x
given:
- '$.channels.*.[publish,subscribe].message'
- '$.channels.*.[publish,subscribe].message.oneOf.*'
- '$.components.channels.*.[publish,subscribe].message'
- '$.components.channels.*.[publish,subscribe].message.oneOf.*'
- $.components.messages.*
- '$.channels.*.[publish,subscribe].message.traits.*'
- '$.channels.*.[publish,subscribe].message.oneOf.*.traits.*'
- '$.components.channels.*.[publish,subscribe].message.traits.*'
- '$.components.channels.*.[publish,subscribe].message.oneOf.*.traits.*'
- $.components.messages.*.traits.*
- $.components.messageTraits.*
then:
function: asyncApi2MessageExamplesValidation
About this rule
All examples in message object should follow payload and headers schemas.
Bad Example
asyncapi: "2.0.0"
info:
title: Bad API
version: "1.0.0"
components:
messages:
someMessage:
payload:
type: string
headers:
type: object
examples:
- payload: 2137
headers: someHeader
Good Example
asyncapi: "2.0.0"
info:
title: Good API
version: "1.0.0"
components:
messages:
someMessage:
payload:
type: string
headers:
type: object
examples:
- payload: foobar
headers:
someHeader: someValue