Skip to content

Commit

Permalink
Clarify message examples definition (#453)
Browse files Browse the repository at this point in the history
* Clarify message examples definition

* Update versions/2.0.0/asyncapi.md

Co-authored-by: Lukasz Gornicki <[email protected]>

* Add links to headers and payload and clarify examples should validate against definitions

* Add JSON Schema definition of examples

Co-authored-by: Lukasz Gornicki <[email protected]>
  • Loading branch information
fmvilas and derberg authored Oct 20, 2020
1 parent d9124ca commit 94baeb8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
27 changes: 26 additions & 1 deletion versions/2.0.0/asyncapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ Field Name | Type | Description
<a name="messageObjectTags"></a>tags | [Tags Object](#tagsObject) | A list of tags for API documentation control. Tags can be used for logical grouping of messages.
<a name="messageObjectExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this message.
<a name="messageObjectBindings"></a>bindings | [Message Bindings Object](#messageBindingsObject) | A map where the keys describe the name of the protocol and the values describe protocol-specific definitions for the message.
<a name="messageObjectExamples"></a>examples | [Map[`string`, `any`]] | An array with examples of valid message objects.
<a name="messageObjectExamples"></a>examples | [Map[`string`, `any`]] | An array of key/value pairs where keys MUST be either **headers** and/or **payload**. Values MUST contain examples that validate against the [headers](#messageObjectHeaders) or [payload](#messageObjectPayload) fields, respectively.
<a name="messageObjectTraits"></a>traits | [[Message Trait Object](#messageTraitObject) &#124; [Reference Object](#referenceObject)] | A list of traits to apply to the message object. Traits MUST be merged into the message object using the [JSON Merge Patch](https://tools.ietf.org/html/rfc7386) algorithm in the same order they are defined here. The resulting object MUST be a valid [Message Object](#messageObject).

This object can be extended with [Specification Extensions](#specificationExtensions).
Expand Down Expand Up @@ -1070,6 +1070,22 @@ Name | Allowed values | Notes
},
"traits": [
{ "$ref": "#/components/messageTraits/commonHeaders" }
],
"examples": [
{
"headers": {
"correlationId": "my-correlation-id",
"applicationInstanceId": "myInstanceId"
},
"payload": {
"user": {
"someUserKey": "someUserValue"
},
"signup": {
"someSignupKey": "someSignupValue"
}
}
}
]
}
```
Expand Down Expand Up @@ -1105,6 +1121,15 @@ correlationId:
location: $message.header#/correlationId
traits:
- $ref: "#/components/messageTraits/commonHeaders"
examples:
- headers:
correlationId: my-correlation-id
applicationInstanceId: myInstanceId
payload:
user:
someUserKey: someUserValue
signup:
someSignupKey: someSignupValue
```

Example using Avro to define the payload:
Expand Down
9 changes: 8 additions & 1 deletion versions/2.0.0/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,14 @@
"examples": {
"type": "array",
"items": {
"type": "object"
"type": "object",
"additionalProperties": false,
"properties": {
"headers": {
"type": "object"
},
"payload": {}
}
}
},
"bindings": {
Expand Down

0 comments on commit 94baeb8

Please sign in to comment.