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 7 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
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] as string;
}

export function incompatibleDocuments(
firstDocument: any,
secondDocument: any
): boolean {
const firstDocumentMajorVersion = getDocumentMajorVersion(firstDocument);
const secondDocumentMajorVersion = getDocumentMajorVersion(secondDocument);
if (firstDocumentMajorVersion !== secondDocumentMajorVersion) {
return true;
}
return false;
}
11 changes: 9 additions & 2 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 @@ -44,6 +51,6 @@ export function diff(
const output = categorizeChanges(standard as OverrideStandard, diffOutput);
return new AsyncAPIDiff(JSON.stringify(output), {
outputType: config.outputType || 'json',
markdownSubtype: config.markdownSubtype || 'json'
markdownSubtype: config.markdownSubtype || 'json',
});
}
Loading
Loading