From ee46d82fe91123724ed1b37e4844413858e49a56 Mon Sep 17 00:00:00 2001 From: Matatjahu Date: Tue, 7 Feb 2023 17:31:47 +0100 Subject: [PATCH] feat: validate unparsed AsyncAPI document --- src/ruleset/ruleset.ts | 29 ++- .../asyncapi-document-unresolved.spec.ts | 169 +++++++++--------- 2 files changed, 96 insertions(+), 102 deletions(-) diff --git a/src/ruleset/ruleset.ts b/src/ruleset/ruleset.ts index d088bd9a2..0f87c3d15 100644 --- a/src/ruleset/ruleset.ts +++ b/src/ruleset/ruleset.ts @@ -53,21 +53,20 @@ export const coreRuleset = { }, }, }, - // enable after fixing https://github.com/asyncapi/spec-json-schemas/issues/296 - // 'asyncapi-document-unresolved': { - // description: 'Checking if the AsyncAPI document has valid unresolved structure.', - // message: '{{error}}', - // severity: 'error', - // recommended: true, - // resolved: false, - // given: '$', - // then: { - // function: documentStructure, - // functionOptions: { - // resolved: false, - // }, - // }, - // }, + 'asyncapi-document-unresolved': { + description: 'Checking if the AsyncAPI document has valid unresolved structure.', + message: '{{error}}', + severity: 'error', + recommended: true, + resolved: false, + given: '$', + then: { + function: documentStructure, + functionOptions: { + resolved: false, + }, + }, + }, 'asyncapi-internal': { description: 'That rule is internal to extend Spectral functionality for Parser purposes.', recommended: true, diff --git a/test/ruleset/rules/asyncapi-document-unresolved.spec.ts b/test/ruleset/rules/asyncapi-document-unresolved.spec.ts index d2242b79b..77876052b 100644 --- a/test/ruleset/rules/asyncapi-document-unresolved.spec.ts +++ b/test/ruleset/rules/asyncapi-document-unresolved.spec.ts @@ -1,90 +1,85 @@ -// import { testRule, DiagnosticSeverity } from '../tester'; +import { testRule, DiagnosticSeverity } from '../tester'; -describe('asyncapi-document-unresolved', () => { - it.todo('add tests after fixing https://github.com/asyncapi/spec-json-schemas/issues/296'); -}); +testRule('asyncapi-document-unresolved', [ + { + name: 'valid case', + document: { + asyncapi: '2.0.0', + info: { + title: 'Valid AsyncApi document', + version: '1.0', + }, + channels: { + someChannel: { + publish: { + message: { + $ref: '#/components/messages/someMessage', + }, + }, + }, + }, + components: { + messages: { + someMessage: {}, + }, + }, + }, + errors: [], + }, -// -// testRule('asyncapi-document-unresolved', [ -// { -// name: 'valid case', -// document: { -// asyncapi: '2.0.0', -// info: { -// title: 'Valid AsyncApi document', -// version: '1.0', -// }, -// channels: { -// someChannel: { -// publish: { -// message: { -// $ref: '#/components/messages/someMessage', -// }, -// }, -// }, -// }, -// components: { -// messages: { -// someMessage: {}, -// }, -// }, -// }, -// errors: [], -// }, + { + name: 'invalid case (reference for operation object is not allowed)', + document: { + asyncapi: '2.0.0', + info: { + title: 'Valid AsyncApi document', + version: '1.0', + }, + channels: { + someChannel: { + publish: { + $ref: '#/components/x-operations/someOperation', + }, + }, + }, + components: { + 'x-operations': { + someOperation: {}, + }, + }, + }, + errors: [ + { + message: 'Referencing in this place is not allowed', + path: ['channels', 'someChannel', 'publish'], + severity: DiagnosticSeverity.Error, + }, + ], + }, -// { -// name: 'invalid case (reference for operation object is not allowed)', -// document: { -// asyncapi: '2.0.0', -// info: { -// title: 'Valid AsyncApi document', -// version: '1.0', -// }, -// channels: { -// someChannel: { -// publish: { -// $ref: '#/components/x-operations/someOperation', -// }, -// }, -// }, -// components: { -// 'x-operations': { -// someOperation: {}, -// }, -// }, -// }, -// errors: [ -// { -// message: 'Referencing in this place is not allowed', -// path: ['channels', 'someChannel', 'publish'], -// severity: DiagnosticSeverity.Error, -// }, -// ], -// }, - -// { -// name: 'invalid case (case when other errors should also occur but we filter them out - required info field is omitted)', -// document: { -// asyncapi: '2.0.0', -// channels: { -// someChannel: { -// publish: { -// $ref: '#/components/x-operations/someOperation', -// }, -// }, -// }, -// components: { -// 'x-operations': { -// someOperation: {}, -// }, -// }, -// }, -// errors: [ -// { -// message: 'Referencing in this place is not allowed', -// path: ['channels', 'someChannel', 'publish'], -// severity: DiagnosticSeverity.Error, -// }, -// ], -// }, -// ]); + { + name: 'invalid case (case when other errors should also occur but we filter them out - required info field is omitted)', + document: { + asyncapi: '2.0.0', + channels: { + someChannel: { + publish: { + $ref: '#/components/x-operations/someOperation', + }, + }, + }, + components: { + 'x-operations': { + someOperation: {}, + }, + }, + }, + errors: [ + { + message: 'Referencing in this place is not allowed', + path: ['channels', 'someChannel', 'publish'], + severity: DiagnosticSeverity.Error, + }, + ], + }, +]);