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: add spec v3 support #160

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Disable specific duplicate code since it would introduce more complexity to reduce it.
sonar.cpd.exclusions=src/standard.ts
sonar.cpd.exclusions=src/standards/v2.ts, src/standards/v3.ts, test/fixtures/main.fixtures.ts
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# For more details, read the following article on GitHub: https://help.github.com/articles/about-codeowners/.

# The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
* @aayushmau5 @vinitshahdeo @onbit-uchenik @magicmatatjahu @derberg @asyncapi-bot-eve
* @aayushmau5 @magicmatatjahu @derberg @asyncapi-bot-eve
17 changes: 17 additions & 0 deletions src/helpers/DiffHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ export function formatDiffOutput(
}
return output;
}

export function getDocumentMajorVersion(document: any): string {
const asyncapiVersion: string = document.asyncapi;
return asyncapiVersion.split('.')[0];
}

export function incompatibleDocuments(
firstDocument: any,
secondDocument: any
): boolean {
const firstDocumentMajorVersion = getDocumentMajorVersion(firstDocument);
const secondDocumentMajorVersion = getDocumentMajorVersion(secondDocument);
if (firstDocumentMajorVersion !== secondDocumentMajorVersion) {
return true;
}
return false;
}
13 changes: 10 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Config, OverrideStandard } from './types';
import generateDiff from './generateDiff';
import { standard } from './standard';
import { getStandardFromVersion } from './standard';
import categorizeChanges from './categorizeChanges';
import AsyncAPIDiff from './asyncapidiff';
import { mergeStandard } from './mergeStandard';
import { incompatibleDocuments } from './helpers/DiffHelpers';

/**
* Generates diff between two AsyncAPI documents
Expand Down Expand Up @@ -33,6 +34,12 @@ export function diff(
secondDocument: any,
config: Config = {}
): AsyncAPIDiff {
if (incompatibleDocuments(firstDocument, secondDocument)) {
throw new TypeError('diff between different AsyncAPI version is not allowed');
}

const standard = getStandardFromVersion(firstDocument);

if (config.override) {
if (typeof config.override !== 'object') {
throw new TypeError('Override data must be an object');
Expand All @@ -43,7 +50,7 @@ export function diff(
const diffOutput = generateDiff(firstDocument, secondDocument);
const output = categorizeChanges(standard as OverrideStandard, diffOutput);
return new AsyncAPIDiff(JSON.stringify(output), {
outputType: config.outputType || 'json',
markdownSubtype: config.markdownSubtype || 'json'
outputType: config.outputType ?? 'json',
markdownSubtype: config.markdownSubtype ?? 'json',
});
}
Loading
Loading