-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the main
diff
function (#30)
- Loading branch information
1 parent
deaf355
commit 341081f
Showing
13 changed files
with
554 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
# Disable specific duplicate code since it would introduce more complexity to reduce it. | ||
sonar.cpd.exclusions=src/standard.ts | ||
sonar.exclusions=src/standard.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const breaking = 'breaking'; | ||
export const nonBreaking = 'non-breaking'; | ||
export const unclassified = 'unclassified'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export {}; | ||
export * from './main'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Config, OverrideStandard } from './types'; | ||
import generateDiff from './generateDiff'; | ||
import { standard } from './standard'; | ||
import categorizeChanges from './categorizeChanges'; | ||
import AsyncAPIDiff from './asyncapidiff'; | ||
import { mergeStandard } from './mergeStandard'; | ||
|
||
/** | ||
* Generates diff between two AsyncAPI documents | ||
* @param firstDocument The parsed AsyncAPI document | ||
* @param secondDocument The parsed AsyncAPI document | ||
* @param {Object} config Configuration options | ||
* @param {Object} [config.override] Object to override the standard | ||
* @returns {AsyncAPIDiff} The diff data | ||
* | ||
* @example | ||
* const output = diff(firstDocument, secondDocument, { | ||
* override: { | ||
* '/servers': { | ||
* add: 'non-breaking', // when a property has been added in the AsyncAPI document | ||
* remove: 'breaking', // when a property has been removed from the AsyncAPI document | ||
* edit: 'unclassified' // when a property has been edited in the AsyncAPI document | ||
* } | ||
* } | ||
* }) | ||
*/ | ||
export function diff( | ||
firstDocument: any, | ||
secondDocument: any, | ||
config: Config = {} | ||
): AsyncAPIDiff { | ||
if (config.override) { | ||
if (typeof config.override !== 'object') { | ||
throw new TypeError('Override data must be an object'); | ||
} | ||
mergeStandard(standard, config.override); | ||
} | ||
|
||
const diffOutput = generateDiff(firstDocument, secondDocument); | ||
const output = categorizeChanges(standard as OverrideStandard, diffOutput); | ||
return new AsyncAPIDiff(JSON.stringify(output)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.