Skip to content

Commit

Permalink
feat(rulesets): add traits array path to headers rule (#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalemRoelofsSB authored Apr 25, 2023
1 parent f2bddb5 commit 9ceabca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ const document = {
message: cloneDeep(headersBearer),
},
},
'users/{userId}/loggedIn': {
publish: {
message: {
traits: [cloneDeep(headersBearer)],
},
},
subscribe: {
message: {
traits: [cloneDeep(headersBearer)],
},
},
},
},
components: {
messageTraits: {
Expand Down Expand Up @@ -131,5 +143,34 @@ testRule('asyncapi-headers-schema-type-object', [
},
],
},

{
name: `channels.{channel}.${property}.message.traits.[*].headers lacks "type" property`,
document: produce(document, draft => {
draft.channels['users/{userId}/loggedIn'][property].message.traits[0].headers = { const: 'Hello World!' };
}),
errors: [
{
message: 'Headers schema type must be "object" ("headers" property must have required property "type").',
path: ['channels', 'users/{userId}/loggedIn', property, 'message', 'traits', '0', 'headers'],
severity: DiagnosticSeverity.Error,
},
],
},

{
name: `channels.{channel}.${property}.message.traits.[*].headers is not of type "object"`,
document: produce(document, draft => {
draft.channels['users/{userId}/loggedIn'][property].message.traits[0].headers = { type: 'integer' };
}),
errors: [
{
message:
'Headers schema type must be "object" ("type" property must be equal to one of the allowed values: "object". Did you mean "object"?).',
path: ['channels', 'users/{userId}/loggedIn', property, 'message', 'traits', '0', 'headers', 'type'],
severity: DiagnosticSeverity.Error,
},
],
},
]),
]);
1 change: 1 addition & 0 deletions packages/rulesets/src/asyncapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default {
'$.components.messageTraits.*.headers',
'$.components.messages.*.headers',
'$.channels.*.[publish,subscribe].message.headers',
'$.channels.*.[publish,subscribe].message.traits[*].headers',
],
then: {
function: schema,
Expand Down

0 comments on commit 9ceabca

Please sign in to comment.