diff --git a/src/helpers/DiffHelpers.ts b/src/helpers/DiffHelpers.ts index 6084f71..c195345 100644 --- a/src/helpers/DiffHelpers.ts +++ b/src/helpers/DiffHelpers.ts @@ -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; +} diff --git a/src/main.ts b/src/main.ts index 09082b0..8997222 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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 @@ -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'); @@ -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', }); } diff --git a/src/standard.ts b/src/standard.ts index 14f3274..8f7a2ff 100644 --- a/src/standard.ts +++ b/src/standard.ts @@ -1,749 +1,12 @@ -import { breaking, nonBreaking, unclassified } from './constants'; +import { getDocumentMajorVersion } from 'helpers/DiffHelpers'; +import { standard as v2Standard } from './standards/v2'; +import { standard as v3Standard } from './standards/v3'; +import { StandardType } from 'types'; -/** - * The standard object - * - * @private - */ -export const standard = { - '/asyncapi': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/id': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/defaultContentType': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/info': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/info/version': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/info/termsOfService': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/info/license': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/info/license/name': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/info/license/url': { - add: breaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/info/title': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/info/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/info/contact': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/info/contact/name': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/info/contact/url': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/info/contact/email': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/servers': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/servers/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/url': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/servers/*/protocol': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/protocolVersion': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/variables': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/variables/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/variables/*/enum': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/variables/*/enum/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/variables/*/default': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/variables/*/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/servers/*/variables/*/examples': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/servers/*/variables/*/examples/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/servers/*/security': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/security/*': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/servers/*/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/subscribe': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/operationId': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/summary': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/tags/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/subscribe/traits': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/traits/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/traits/operationId': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/traits/summary': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/traits/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/traits/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/traits/tags/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/traits/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/traits/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/subscribe/message': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/headers': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/subscribe/message/correlationId': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/correlationId/location': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/correlationId/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/schemaFormat': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/contentType': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/name': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/title': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/summary': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/tags/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/subscribe/message/examples': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/examples/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/traits/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/traits/headers': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/subscribe/message/traits/correlationId': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/traits/correlationId/location': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/traits/correlationId/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits/schemaFormat': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/traits/contentType': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/subscribe/message/traits/name': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits/title': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits/summary': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits/tags/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/subscribe/message/traits/examples': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/traits/examples/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/subscribe/message/payload': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/publish': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/operationId': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/summary': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/tags/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/publish/traits': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/traits/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/traits/operationId': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/traits/summary': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/traits/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/traits/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/traits/tags/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/traits/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/traits/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/publish/message': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/headers': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/publish/message/correlationId': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/correlationId/location': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/correlationId/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/schemaFormat': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/contentType': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/name': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/title': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/summary': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/tags/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/publish/message/examples': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/examples/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/traits/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/traits/headers': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/publish/message/traits/correlationId': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/traits/correlationId/location': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/traits/correlationId/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits/schemaFormat': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/traits/contentType': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/publish/message/traits/name': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits/title': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits/summary': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits/tags/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits/bindings': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/publish/message/traits/examples': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/traits/examples/*': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/publish/message/payload': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/parameters': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/parameters/*': { - add: nonBreaking, - remove: breaking, - edit: breaking, - }, - '/channels/*/parameters/*/description': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/channels/*/parameters/*/schema': { - add: unclassified, - remove: unclassified, - edit: unclassified, - }, - '/channels/*/parameters/*/location': { - add: breaking, - remove: breaking, - edit: breaking, - }, - '/components': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/tags': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, - '/externalDocs': { - add: nonBreaking, - remove: nonBreaking, - edit: nonBreaking, - }, -}; +export function getStandardFromVersion(document: any): StandardType { + const majorVersion = getDocumentMajorVersion(document); + if (majorVersion === '2') { + return v2Standard; + } + return v3Standard; +} diff --git a/src/standards/v2.ts b/src/standards/v2.ts new file mode 100644 index 0000000..c59caa3 --- /dev/null +++ b/src/standards/v2.ts @@ -0,0 +1,749 @@ +import { breaking, nonBreaking, unclassified } from '../constants'; + +/** + * The standard object for AsyncAPI v2 + * + * @private + */ +export const standard = { + '/asyncapi': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/id': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/defaultContentType': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/info': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/info/version': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/info/termsOfService': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/info/license': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/info/license/name': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/info/license/url': { + add: breaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/info/title': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/info/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/info/contact': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/info/contact/name': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/info/contact/url': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/info/contact/email': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/servers': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/servers/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/url': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/servers/*/protocol': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/protocolVersion': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/variables': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/variables/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/variables/*/enum': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/variables/*/enum/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/variables/*/default': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/variables/*/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/servers/*/variables/*/examples': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/servers/*/variables/*/examples/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/servers/*/security': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/security/*': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/servers/*/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/subscribe': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/operationId': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/summary': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/tags/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/subscribe/traits': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/traits/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/traits/operationId': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/traits/summary': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/traits/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/traits/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/traits/tags/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/traits/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/traits/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/subscribe/message': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/headers': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/subscribe/message/correlationId': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/correlationId/location': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/correlationId/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/schemaFormat': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/contentType': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/name': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/title': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/summary': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/tags/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/subscribe/message/examples': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/examples/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/traits/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/traits/headers': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/subscribe/message/traits/correlationId': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/traits/correlationId/location': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/traits/correlationId/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits/schemaFormat': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/traits/contentType': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/subscribe/message/traits/name': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits/title': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits/summary': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits/tags/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/subscribe/message/traits/examples': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/traits/examples/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/subscribe/message/payload': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/publish': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/operationId': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/summary': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/tags/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/publish/traits': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/traits/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/traits/operationId': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/traits/summary': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/traits/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/traits/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/traits/tags/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/traits/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/traits/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/publish/message': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/headers': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/publish/message/correlationId': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/correlationId/location': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/correlationId/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/schemaFormat': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/contentType': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/name': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/title': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/summary': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/tags/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/publish/message/examples': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/examples/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/traits/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/traits/headers': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/publish/message/traits/correlationId': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/traits/correlationId/location': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/traits/correlationId/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits/schemaFormat': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/traits/contentType': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/publish/message/traits/name': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits/title': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits/summary': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits/tags/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits/bindings': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/publish/message/traits/examples': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/traits/examples/*': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/publish/message/payload': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/parameters': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/parameters/*': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, + '/channels/*/parameters/*/description': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/channels/*/parameters/*/schema': { + add: unclassified, + remove: unclassified, + edit: unclassified, + }, + '/channels/*/parameters/*/location': { + add: breaking, + remove: breaking, + edit: breaking, + }, + '/components': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/tags': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, + '/externalDocs': { + add: nonBreaking, + remove: nonBreaking, + edit: nonBreaking, + }, +}; diff --git a/src/standards/v3.ts b/src/standards/v3.ts new file mode 100644 index 0000000..a84def5 --- /dev/null +++ b/src/standards/v3.ts @@ -0,0 +1,16 @@ +import { breaking, nonBreaking, unclassified } from '../constants'; + +// TODO: check the new spec changes + +/** + * The standard object for AsyncAPI v3 + * + * @private + */ +export const standard = { + '/asyncapi': { + add: nonBreaking, + remove: breaking, + edit: breaking, + }, +}; diff --git a/src/types.ts b/src/types.ts index 9bc778b..3b1a1c0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,6 +1,7 @@ import {ReplaceOperation, AddOperation} from 'fast-json-patch'; -import {standard} from './standard'; +import {standard as v2Standard} from './standards/v2'; +import {standard as v3Standard} from './standards/v3'; import {breaking, nonBreaking, unclassified} from './constants'; export type ActionType = 'add' | 'remove' | 'edit'; @@ -38,7 +39,7 @@ export type Output = JSONOutput | string; export type ValueOperation = ReplaceOperation | AddOperation; -export type StandardType = typeof standard; +export type StandardType = typeof v2Standard | typeof v3Standard; export interface OverrideObject { [key: string]: Classifier;