Skip to content

Commit 9ceabca

Browse files
feat(rulesets): add traits array path to headers rule (stoplightio#2460)
1 parent f2bddb5 commit 9ceabca

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/rulesets/src/asyncapi/__tests__/asyncapi-headers-schema-type-object.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ const document = {
2626
message: cloneDeep(headersBearer),
2727
},
2828
},
29+
'users/{userId}/loggedIn': {
30+
publish: {
31+
message: {
32+
traits: [cloneDeep(headersBearer)],
33+
},
34+
},
35+
subscribe: {
36+
message: {
37+
traits: [cloneDeep(headersBearer)],
38+
},
39+
},
40+
},
2941
},
3042
components: {
3143
messageTraits: {
@@ -131,5 +143,34 @@ testRule('asyncapi-headers-schema-type-object', [
131143
},
132144
],
133145
},
146+
147+
{
148+
name: `channels.{channel}.${property}.message.traits.[*].headers lacks "type" property`,
149+
document: produce(document, draft => {
150+
draft.channels['users/{userId}/loggedIn'][property].message.traits[0].headers = { const: 'Hello World!' };
151+
}),
152+
errors: [
153+
{
154+
message: 'Headers schema type must be "object" ("headers" property must have required property "type").',
155+
path: ['channels', 'users/{userId}/loggedIn', property, 'message', 'traits', '0', 'headers'],
156+
severity: DiagnosticSeverity.Error,
157+
},
158+
],
159+
},
160+
161+
{
162+
name: `channels.{channel}.${property}.message.traits.[*].headers is not of type "object"`,
163+
document: produce(document, draft => {
164+
draft.channels['users/{userId}/loggedIn'][property].message.traits[0].headers = { type: 'integer' };
165+
}),
166+
errors: [
167+
{
168+
message:
169+
'Headers schema type must be "object" ("type" property must be equal to one of the allowed values: "object". Did you mean "object"?).',
170+
path: ['channels', 'users/{userId}/loggedIn', property, 'message', 'traits', '0', 'headers', 'type'],
171+
severity: DiagnosticSeverity.Error,
172+
},
173+
],
174+
},
134175
]),
135176
]);

packages/rulesets/src/asyncapi/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export default {
9090
'$.components.messageTraits.*.headers',
9191
'$.components.messages.*.headers',
9292
'$.channels.*.[publish,subscribe].message.headers',
93+
'$.channels.*.[publish,subscribe].message.traits[*].headers',
9394
],
9495
then: {
9596
function: schema,

0 commit comments

Comments
 (0)