Skip to content

Commit

Permalink
feat: validate unparsed AsyncAPI document (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu authored Feb 9, 2023
1 parent 8951247 commit 9e6da02
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 102 deletions.
29 changes: 14 additions & 15 deletions src/ruleset/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
169 changes: 82 additions & 87 deletions test/ruleset/rules/asyncapi-document-unresolved.spec.ts
Original file line number Diff line number Diff line change
@@ -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,
},
],
},
]);

0 comments on commit 9e6da02

Please sign in to comment.