Skip to content

Commit

Permalink
chore: update @asyncapi/parser to 2.1.0 (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushmau5 authored Oct 23, 2023
1 parent da016d3 commit 1030ee4
Show file tree
Hide file tree
Showing 7 changed files with 3,853 additions and 10,473 deletions.
14,195 changes: 3,790 additions & 10,405 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"json2md": "^1.12.0"
},
"devDependencies": {
"@asyncapi/parser": "^1.18.0",
"@types/jest": "^26.0.23",
"@asyncapi/parser": "^2.1.0",
"@types/jest": "^29.5.1",
"@types/js-yaml": "^4.0.5",
"@types/json2md": "^1.5.1",
"@types/node": "^15.12.1",
Expand All @@ -56,9 +56,9 @@
"eslint-plugin-github": "^4.1.3",
"eslint-plugin-security": "^1.4.0",
"eslint-plugin-sonarjs": "^0.8.0-125",
"jest": "^27.0.4",
"jest": "^29.5.0",
"markdown-toc": "^1.2.0",
"ts-jest": "^27.0.3",
"ts-jest": "^29.1.0",
"typedoc": "^0.22.11",
"typedoc-plugin-markdown": "^3.11.12",
"typedoc-plugin-rename-defaults": "^0.4.0",
Expand Down
16 changes: 4 additions & 12 deletions test/fixtures/asyncapidiff.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ export const MarkdownJSONSubtypeChanges = `## Breaking
"type": "object",
"x-parser-schema-id": "<anonymous-schema-1>"
},
"schemaFormat": "application/vnd.aai.asyncapi;version=2.0.0",
"x-parser-message-name": "channelMessage",
"x-parser-message-parsed": true,
"x-parser-original-traits": [
"traits": [
{
"headers": {
"properties": {
Expand Down Expand Up @@ -173,10 +171,8 @@ export const MarkdownJSONSubtypeChanges = `## Breaking
"type": "object",
"x-parser-schema-id": "<anonymous-schema-1>"
},
"schemaFormat": "application/vnd.aai.asyncapi;version=2.0.0",
"x-parser-message-name": "channelMessage",
"x-parser-message-parsed": true,
"x-parser-original-traits": [
"traits": [
{
"headers": {
"properties": {
Expand Down Expand Up @@ -219,10 +215,8 @@ export const MarkdownYAMLSubtypeChanges = `## Breaking
x-parser-schema-id: <anonymous-schema-2>
type: object
x-parser-schema-id: <anonymous-schema-1>
schemaFormat: application/vnd.aai.asyncapi;version=2.0.0
x-parser-message-name: channelMessage
x-parser-message-parsed: true
x-parser-original-traits:
traits:
- headers:
properties:
some-common-header:
Expand Down Expand Up @@ -261,10 +255,8 @@ export const MarkdownYAMLSubtypeChanges = `## Breaking
x-parser-schema-id: <anonymous-schema-2>
type: object
x-parser-schema-id: <anonymous-schema-1>
schemaFormat: application/vnd.aai.asyncapi;version=2.0.0
x-parser-message-name: channelMessage
x-parser-message-parsed: true
x-parser-original-traits:
traits:
- headers:
properties:
some-common-header:
Expand Down
20 changes: 8 additions & 12 deletions test/fixtures/diff.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,22 @@ export const diffOutput = [
type: 'object',
'x-parser-schema-id': '<anonymous-schema-1>',
},
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-name': 'channelMessage',
'x-parser-message-parsed': true,
'x-parser-original-traits': [
traits: [
{
headers: {
properties: {
'some-common-header': {
type: 'string',
'x-parser-schema-id': '<anonymous-schema-7>'
'x-parser-schema-id': '<anonymous-schema-7>',
},
},
type: 'object',
'x-parser-schema-id': '<anonymous-schema-6>'
'x-parser-schema-id': '<anonymous-schema-6>',
},
'x-some-extension': 'some extension',
},
],
'x-parser-message-name': 'channelMessage',
'x-some-extension': 'some extension',
},
},
Expand All @@ -89,24 +87,22 @@ export const diffOutput = [
type: 'object',
'x-parser-schema-id': '<anonymous-schema-1>',
},
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-name': 'channelMessage',
'x-parser-message-parsed': true,
'x-parser-original-traits': [
traits: [
{
headers: {
properties: {
'some-common-header': {
type: 'string',
'x-parser-schema-id': '<anonymous-schema-7>'
'x-parser-schema-id': '<anonymous-schema-7>',
},
},
type: 'object',
'x-parser-schema-id': '<anonymous-schema-6>'
'x-parser-schema-id': '<anonymous-schema-6>',
},
'x-some-extension': 'some extension',
},
],
'x-parser-message-name': 'channelMessage',
'x-some-extension': 'some extension',
},
},
Expand Down
24 changes: 6 additions & 18 deletions test/fixtures/main.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ export const breakingChanges = [
type: 'object',
'x-parser-schema-id': '<anonymous-schema-1>',
},
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-name': 'channelMessage',
'x-parser-message-parsed': true,
'x-parser-original-traits': [
traits: [
{
headers: {
properties: {
Expand Down Expand Up @@ -67,10 +65,8 @@ export const nonBreakingChanges = [
type: 'object',
'x-parser-schema-id': '<anonymous-schema-1>',
},
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-name': 'channelMessage',
'x-parser-message-parsed': true,
'x-parser-original-traits': [
traits: [
{
headers: {
properties: {
Expand Down Expand Up @@ -111,10 +107,8 @@ export const diffOutput = {
type: 'object',
'x-parser-schema-id': '<anonymous-schema-1>',
},
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-name': 'channelMessage',
'x-parser-message-parsed': true,
'x-parser-original-traits': [
traits: [
{
headers: {
properties: {
Expand Down Expand Up @@ -151,10 +145,8 @@ export const diffOutput = {
type: 'object',
'x-parser-schema-id': '<anonymous-schema-1>',
},
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-name': 'channelMessage',
'x-parser-message-parsed': true,
'x-parser-original-traits': [
traits: [
{
headers: {
properties: {
Expand Down Expand Up @@ -216,10 +208,8 @@ export const changesWithOverrides = {
type: 'object',
'x-parser-schema-id': '<anonymous-schema-1>',
},
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-name': 'channelMessage',
'x-parser-message-parsed': true,
'x-parser-original-traits': [
traits: [
{
headers: {
properties: {
Expand Down Expand Up @@ -256,10 +246,8 @@ export const changesWithOverrides = {
type: 'object',
'x-parser-schema-id': '<anonymous-schema-1>',
},
schemaFormat: 'application/vnd.aai.asyncapi;version=2.0.0',
'x-parser-message-name': 'channelMessage',
'x-parser-message-parsed': true,
'x-parser-original-traits': [
traits: [
{
headers: {
properties: {
Expand Down
20 changes: 14 additions & 6 deletions test/generateDiff.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse } from '@asyncapi/parser';
import { Parser } from '@asyncapi/parser';
import { readFileSync } from 'fs';
import { resolve } from 'path';

Expand All @@ -11,6 +11,8 @@ import {
diffOutput,
} from './fixtures/diff.fixtures';

const parser = new Parser();

describe('Diff', () => {
test('Check if diff is an empty array for same inputs', () => {
expect(generateDiff(firstDocument, firstDocument)).toStrictEqual([]);
Expand All @@ -27,9 +29,12 @@ describe('Diff', () => {
resolve('./test/spec/asyncapi.yml'),
'utf-8'
);
const firstDocument = await parse(specDocument);
const firstDocument = await parser.parse(specDocument);
expect(
generateDiff(firstDocument.json(), firstDocument.json())
generateDiff(
firstDocument.document?.json(),
firstDocument.document?.json()
)
).toStrictEqual([]);
});

Expand All @@ -42,10 +47,13 @@ describe('Diff', () => {
resolve('./test/spec/diffSpec.yml'),
'utf-8'
);
const firstDocument = await parse(firstSpecDocument);
const secondDocument = await parse(secondSpecDocument);
const firstDocument = await parser.parse(firstSpecDocument);
const secondDocument = await parser.parse(secondSpecDocument);
expect(
generateDiff(firstDocument.json(), secondDocument.json())
generateDiff(
firstDocument.document?.json(),
secondDocument.document?.json()
)
).toStrictEqual(diffOutput);
});
});
43 changes: 27 additions & 16 deletions test/main.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {parse} from '@asyncapi/parser';
import {readFileSync} from 'fs';
import {resolve} from 'path';
import { Parser } from '@asyncapi/parser';
import { readFileSync } from 'fs';
import { resolve } from 'path';

import AsyncAPIDiff from '../src/asyncapidiff';
import {diff} from '../src';
import {OverrideObject} from '../src';
import { diff } from '../src';
import { OverrideObject } from '../src';

import {
diffOutput,
Expand All @@ -16,9 +16,11 @@ import {
specDocument2,
arrayChanges,
YAMLArrayChanges,
MarkdownArrayChanges
MarkdownArrayChanges,
} from './fixtures/main.fixtures';

const parser = new Parser();

describe('main function', () => {
test('runs the diff function', async () => {
const firstSpecDocument = readFileSync(
Expand All @@ -29,9 +31,12 @@ describe('main function', () => {
resolve('./test/spec/diffSpec.yml'),
'utf-8'
);
const firstDocument = await parse(firstSpecDocument);
const secondDocument = await parse(secondSpecDocument);
const output = diff(firstDocument.json(), secondDocument.json());
const firstDocument = await parser.parse(firstSpecDocument);
const secondDocument = await parser.parse(secondSpecDocument);
const output = diff(
firstDocument.document?.json(),
secondDocument.document?.json()
);
expect(output).toBeInstanceOf(AsyncAPIDiff);
expect(output.getOutput()).toEqual(diffOutput);
expect(output.breaking()).toEqual(breakingChanges);
Expand All @@ -55,11 +60,15 @@ describe('main function', () => {
resolve('./test/spec/diffSpec.yml'),
'utf-8'
);
const firstDocument = await parse(firstSpecDocument);
const secondDocument = await parse(secondSpecDocument);
const output = diff(firstDocument.json(), secondDocument.json(), {
override: overrides as OverrideObject,
});
const firstDocument = await parser.parse(firstSpecDocument);
const secondDocument = await parser.parse(secondSpecDocument);
const output = diff(
firstDocument.document?.json(),
secondDocument.document?.json(),
{
override: overrides as OverrideObject,
}
);
expect(output.getOutput()).toEqual(changesWithOverrides);
});

Expand All @@ -69,12 +78,14 @@ describe('main function', () => {
});

test('YAML: checks output with array changes', () => {
const output = diff(specDocument1, specDocument2, {outputType: 'yaml'});
const output = diff(specDocument1, specDocument2, { outputType: 'yaml' });
expect(output.getOutput()).toEqual(YAMLArrayChanges);
});

test('Markdown: checks output with array changes', () => {
const output = diff(specDocument1, specDocument2, {outputType: 'markdown'});
const output = diff(specDocument1, specDocument2, {
outputType: 'markdown',
});
expect(output.getOutput()).toEqual(MarkdownArrayChanges);
});
});

0 comments on commit 1030ee4

Please sign in to comment.