Skip to content

Commit

Permalink
feat: enable AsyncAPI v3 validation
Browse files Browse the repository at this point in the history
  • Loading branch information
smoya committed Aug 1, 2023
1 parent 74ef1cf commit cb22b1a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ruleset/ruleset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AsyncAPIFormats } from './formats';

export const coreRuleset = {
description: 'Core AsyncAPI x.x.x ruleset.',
formats: AsyncAPIFormats.filterByMajorVersions(['2']).formats(), // Validation for AsyncAPI v3 is still WIP.
formats: AsyncAPIFormats.formats(),
rules: {
/**
* Root Object rules
Expand Down
13 changes: 13 additions & 0 deletions test/custom-operations/apply-traits-v3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ describe('custom operations - apply traits v3', function() {
title: 'Valid AsyncApi document',
version: '1.0',
},
channels: {
channel1: {}
},
operations: {
someOperation1: {
action: 'send',
channel: {
$ref: '#/channels/channel1'
},
traits: [
{
description: 'some description'
Expand All @@ -25,6 +32,10 @@ describe('custom operations - apply traits v3', function() {
]
},
someOperation2: {
action: 'send',
channel: {
$ref: '#/channels/channel1'
},
description: 'root description',
traits: [
{
Expand All @@ -38,6 +49,8 @@ describe('custom operations - apply traits v3', function() {
}
};
const { document, diagnostics } = await parser.parse(documentRaw);
expect(diagnostics).toHaveLength(0);

const v3Document = document as AsyncAPIDocumentV3;
expect(v3Document).toBeInstanceOf(AsyncAPIDocumentV3);

Expand Down
5 changes: 3 additions & 2 deletions test/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ describe('parse()', function() {
};
const { document, diagnostics } = await parser.parse(documentRaw);

expect(document).toBeInstanceOf(AsyncAPIDocumentV3);
expect(diagnostics.length === 0).toEqual(true); // Validation in v3 is still not enabled. This test will intentionally fail once that changes.
expect(document === undefined).toEqual(true);
expect(diagnostics.length > 0).toEqual(true);
expect(diagnostics[0].message).toEqual('Object must have required property "info"');
});

it('should return extras', async function() {
Expand Down

0 comments on commit cb22b1a

Please sign in to comment.