Skip to content

Commit

Permalink
inital version of spec v3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushmau5 committed Sep 7, 2023
1 parent da016d3 commit 6b78e82
Show file tree
Hide file tree
Showing 6 changed files with 806 additions and 752 deletions.
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('.').at(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;
}
12 changes: 10 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,13 @@ export function diff(
secondDocument: any,
config: Config = {}
): AsyncAPIDiff {
if (incompatibleDocuments(firstDocument, secondDocument)) {
// TODO: decide how to show the errors
return 'Incompatible docs';
}

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 +52,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

0 comments on commit 6b78e82

Please sign in to comment.