Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: validate unparsed AsyncAPI document #720

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Is it not caught by the spec-schema?

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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Is it not caught by the spec-schema?

path: ['channels', 'someChannel', 'publish'],
severity: DiagnosticSeverity.Error,
},
],
},
]);