Skip to content

Commit 67a15d9

Browse files
authored
Merge pull request #155 from kokovtsev/asyncapi-fix-message-examples
fix: AsyncAPI: update the `examples` codec according to the spec (closes #154)
2 parents 9d24059 + 036467a commit 67a15d9

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"eslint": "^6.7.2",
5353
"fast-check": "^1.17.0",
5454
"fp-ts": "^2.1.0",
55-
"io-ts": "^2.0.1",
55+
"io-ts": "^2.0.5",
5656
"io-ts-types": "^0.5.1",
5757
"jest": "^24.9.0",
5858
"nodemon": "^2.0.12",
@@ -62,7 +62,7 @@
6262
},
6363
"peerDependencies": {
6464
"fp-ts": "^2.1.0",
65-
"io-ts": "^2.0.1",
65+
"io-ts": "^2.0.5",
6666
"io-ts-types": "^0.5.1"
6767
},
6868
"jest": {

src/schema/asyncapi-2.0.0/message-object.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface MessageObject {
2222
readonly description: Option<string>;
2323
readonly tags: Option<TagsObject>;
2424
readonly externalDocs: Option<ExternalDocumentationObject>;
25-
readonly examples: Option<Record<string, unknown>>;
25+
readonly examples: Option<Record<string, unknown>[]>;
2626
readonly traits: Option<MessageTraitObject[]>;
2727
}
2828

@@ -39,7 +39,7 @@ export const MessageObjectCodec: Codec<MessageObject> = type(
3939
description: optionFromNullable(string),
4040
tags: optionFromNullable(TagsObjectCodec),
4141
externalDocs: optionFromNullable(ExternalDocumentationObjectCodec),
42-
examples: optionFromNullable(record(string, unknown)),
42+
examples: optionFromNullable(array(record(string, unknown))),
4343
traits: optionFromNullable(array(MessageTraitObjectCodec)),
4444
},
4545
'MessageObject',

test/specs/asyncapi-2.0.0/channel-params.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ channels:
2020
time:
2121
type: string
2222
format: date-time
23+
examples:
24+
- payload: |
25+
```
26+
{"time": "2021-10-01T12:25:36Z", "text": "First message"}
27+
```
28+
- {"time": "2021-10-01T12:25:43Z", "text": "Second message"}
2329
publish:
2430
message:
2531
description: Outgoing message

test/specs/asyncapi-2.0.0/streetlights-api.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ components:
6868
$ref: '#/components/schemas/Lumens'
6969
sentAt:
7070
$ref: '#/components/schemas/SentAt'
71+
examples:
72+
- >
73+
```
74+
{
75+
"id": 123,
76+
"lumens": 470,
77+
"sentAt": "2021-10-04T08:42:25Z"
78+
}
79+
```
80+
- { "id": 123, "lumens": 470, "sentAt": "2021-10-04T08:42:25Z" }
7181
Id:
7282
type: integer
7383
minimum: 0

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,10 +2621,10 @@ io-ts-types@^0.5.1:
26212621
resolved "https://registry.yarnpkg.com/io-ts-types/-/io-ts-types-0.5.1.tgz#55bedec94e3cce1413d60c014918091d0dffbbce"
26222622
integrity sha512-wdlK7Gn9gBaI3BT44mpwU+Y54J3GTT5R3dkM7CYZoaPMKWDwp/jYZ1Bj8/RRfcwP2ElJjuGre06avjkHLvgl7w==
26232623

2624-
io-ts@^2.0.1:
2625-
version "2.0.1"
2626-
resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.0.1.tgz#1261c12f915c2f48d16393a36966636b48a45aa1"
2627-
integrity sha512-RezD+WcCfW4VkMkEcQWL/Nmy/nqsWTvTYg7oUmTGzglvSSV2P9h2z1PVeREPFf0GWNzruYleAt1XCMQZSg1xxQ==
2624+
io-ts@^2.0.5:
2625+
version "2.0.5"
2626+
resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.0.5.tgz#e6e3db9df8b047f9cbd6b69e7d2ad3e6437a0b13"
2627+
integrity sha512-pL7uUptryanI5Glv+GUv7xh+aLBjxGEDmLwmEYNSx0yOD3djK0Nw5Bt0N6BAkv9LadOUU7QKpRsLcqnTh3UlLA==
26282628

26292629
is-accessor-descriptor@^0.1.6:
26302630
version "0.1.6"

0 commit comments

Comments
 (0)