From 9ceabca80969885c240349d6ebba15c09a4f8697 Mon Sep 17 00:00:00 2001 From: Calem Roelofs <96050034+CalemRoelofsSB@users.noreply.github.com> Date: Tue, 25 Apr 2023 17:21:46 +0100 Subject: [PATCH] feat(rulesets): add traits array path to headers rule (#2460) --- ...syncapi-headers-schema-type-object.test.ts | 41 +++++++++++++++++++ packages/rulesets/src/asyncapi/index.ts | 1 + 2 files changed, 42 insertions(+) diff --git a/packages/rulesets/src/asyncapi/__tests__/asyncapi-headers-schema-type-object.test.ts b/packages/rulesets/src/asyncapi/__tests__/asyncapi-headers-schema-type-object.test.ts index 36e99de4e..c0b971b06 100644 --- a/packages/rulesets/src/asyncapi/__tests__/asyncapi-headers-schema-type-object.test.ts +++ b/packages/rulesets/src/asyncapi/__tests__/asyncapi-headers-schema-type-object.test.ts @@ -26,6 +26,18 @@ const document = { message: cloneDeep(headersBearer), }, }, + 'users/{userId}/loggedIn': { + publish: { + message: { + traits: [cloneDeep(headersBearer)], + }, + }, + subscribe: { + message: { + traits: [cloneDeep(headersBearer)], + }, + }, + }, }, components: { messageTraits: { @@ -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, + }, + ], + }, ]), ]); diff --git a/packages/rulesets/src/asyncapi/index.ts b/packages/rulesets/src/asyncapi/index.ts index 94221b93f..eb20fa1fb 100644 --- a/packages/rulesets/src/asyncapi/index.ts +++ b/packages/rulesets/src/asyncapi/index.ts @@ -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,