Skip to content

Commit 6fcfb89

Browse files
authored
feat: add spec v3 support (#160)
1 parent ba23fd9 commit 6fcfb89

14 files changed

+2216
-759
lines changed

.sonarcloud.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Disable specific duplicate code since it would introduce more complexity to reduce it.
2-
sonar.cpd.exclusions=src/standard.ts
2+
sonar.cpd.exclusions=src/standards/v2.ts, src/standards/v3.ts, test/fixtures/main.fixtures.ts

CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.
66

77
# The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
8-
* @aayushmau5 @vinitshahdeo @onbit-uchenik @magicmatatjahu @derberg @asyncapi-bot-eve
8+
* @aayushmau5 @magicmatatjahu @derberg @asyncapi-bot-eve

src/helpers/DiffHelpers.ts

+17
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,20 @@ export function formatDiffOutput(
9999
}
100100
return output;
101101
}
102+
103+
export function getDocumentMajorVersion(document: any): string {
104+
const asyncapiVersion: string = document.asyncapi;
105+
return asyncapiVersion.split('.')[0];
106+
}
107+
108+
export function incompatibleDocuments(
109+
firstDocument: any,
110+
secondDocument: any
111+
): boolean {
112+
const firstDocumentMajorVersion = getDocumentMajorVersion(firstDocument);
113+
const secondDocumentMajorVersion = getDocumentMajorVersion(secondDocument);
114+
if (firstDocumentMajorVersion !== secondDocumentMajorVersion) {
115+
return true;
116+
}
117+
return false;
118+
}

src/main.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Config, OverrideStandard } from './types';
22
import generateDiff from './generateDiff';
3-
import { standard } from './standard';
3+
import { getStandardFromVersion } from './standard';
44
import categorizeChanges from './categorizeChanges';
55
import AsyncAPIDiff from './asyncapidiff';
66
import { mergeStandard } from './mergeStandard';
7+
import { incompatibleDocuments } from './helpers/DiffHelpers';
78

89
/**
910
* Generates diff between two AsyncAPI documents
@@ -33,6 +34,12 @@ export function diff(
3334
secondDocument: any,
3435
config: Config = {}
3536
): AsyncAPIDiff {
37+
if (incompatibleDocuments(firstDocument, secondDocument)) {
38+
throw new TypeError('diff between different AsyncAPI version is not allowed');
39+
}
40+
41+
const standard = getStandardFromVersion(firstDocument);
42+
3643
if (config.override) {
3744
if (typeof config.override !== 'object') {
3845
throw new TypeError('Override data must be an object');
@@ -43,7 +50,7 @@ export function diff(
4350
const diffOutput = generateDiff(firstDocument, secondDocument);
4451
const output = categorizeChanges(standard as OverrideStandard, diffOutput);
4552
return new AsyncAPIDiff(JSON.stringify(output), {
46-
outputType: config.outputType || 'json',
47-
markdownSubtype: config.markdownSubtype || 'json'
53+
outputType: config.outputType ?? 'json',
54+
markdownSubtype: config.markdownSubtype ?? 'json',
4855
});
4956
}

0 commit comments

Comments
 (0)