diff --git a/packages/apidom-core/src/index.ts b/packages/apidom-core/src/index.ts index d47d2fcb92..3cd88c8fad 100644 --- a/packages/apidom-core/src/index.ts +++ b/packages/apidom-core/src/index.ts @@ -7,6 +7,7 @@ import defaultNamespaceInstance from './namespace'; export { default as refractorPluginElementIdentity } from './refractor/plugins/element-identity'; export { default as refractorPluginSemanticElementIdentity } from './refractor/plugins/semantic-element-identity'; +export { default as MediaTypes } from './media-types'; export { Element, diff --git a/packages/apidom-core/src/media-types.ts b/packages/apidom-core/src/media-types.ts new file mode 100644 index 0000000000..17eacf6047 --- /dev/null +++ b/packages/apidom-core/src/media-types.ts @@ -0,0 +1,13 @@ +class MediaTypes extends Array { + // eslint-disable-next-line class-methods-use-this + forFormat() { + throw new Error('Not implemented!'); + } + + // eslint-disable-next-line class-methods-use-this + latest() { + throw new Error('Not implemented!'); + } +} + +export default MediaTypes; diff --git a/packages/apidom-ns-asyncapi-2/src/index.ts b/packages/apidom-ns-asyncapi-2/src/index.ts index 054c628f65..23f38277d5 100644 --- a/packages/apidom-ns-asyncapi-2/src/index.ts +++ b/packages/apidom-ns-asyncapi-2/src/index.ts @@ -13,6 +13,8 @@ export { isStringElement, } from '@swagger-api/apidom-core'; +export { default as mediaTypes, AsyncAPIMediaTypes } from './media-types'; + // eslint-disable-next-line no-restricted-exports export { default } from './namespace'; diff --git a/packages/apidom-ns-asyncapi-2/src/media-types.ts b/packages/apidom-ns-asyncapi-2/src/media-types.ts new file mode 100644 index 0000000000..e860739acf --- /dev/null +++ b/packages/apidom-ns-asyncapi-2/src/media-types.ts @@ -0,0 +1,33 @@ +import { MediaTypes } from '@swagger-api/apidom-core'; + +export class AsyncAPIMediaTypes extends MediaTypes { + forFormat(format = 'generic') { + const effectiveFormat = format === 'generic' ? 'asyncapi;version' : format; + return this.filter((mediaType) => mediaType.includes(effectiveFormat)); + } + + latest(format = 'generic') { + if (format === 'json') { + return this[7]; + } + if (format === 'yaml') { + return this[8]; + } + + return this[6]; + } +} + +const mediaTypes = new AsyncAPIMediaTypes( + 'application/vnd.aai.asyncapi;version=2.0.0', + 'application/vnd.aai.asyncapi+json;version=2.0.0', + 'application/vnd.aai.asyncapi+yaml;version=2.0.0', + 'application/vnd.aai.asyncapi;version=2.1.0', + 'application/vnd.aai.asyncapi+json;version=2.1.0', + 'application/vnd.aai.asyncapi+yaml;version=2.1.0', + 'application/vnd.aai.asyncapi;version=2.2.0', + 'application/vnd.aai.asyncapi+json;version=2.2.0', + 'application/vnd.aai.asyncapi+yaml;version=2.2.0', +); + +export default mediaTypes; diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts index 2d67eda2ca..d679557cd0 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts @@ -9,6 +9,7 @@ import { isArrayElement, } from '@swagger-api/apidom-core'; +import mediaTypes from '../../media-types'; /** * AsyncApi 2.0.0 | 2.1.0 | 2.2.0 specification elements. */ @@ -261,23 +262,9 @@ const schema = { payload(...args: any[]) { // @ts-ignore const { context: messageElement } = this; - const supportedSchemaFormats = [ - 'application/vnd.aai.asyncapi;version=2.0.0', - 'application/vnd.aai.asyncapi+json;version=2.0.0', - 'application/vnd.aai.asyncapi+yaml;version=2.0.0', - 'application/vnd.aai.asyncapi;version=2.1.0', - 'application/vnd.aai.asyncapi+json;version=2.1.0', - 'application/vnd.aai.asyncapi+yaml;version=2.1.0', - 'application/vnd.aai.asyncapi;version=2.2.0', - 'application/vnd.aai.asyncapi+json;version=2.2.0', - 'application/vnd.aai.asyncapi+yaml;version=2.2.0', - ]; - const schemaFormat = defaultTo( - 'application/vnd.aai.asyncapi;version=2.2.0', - messageElement.schemaFormat?.toValue(), - ); + const schemaFormat = defaultTo(mediaTypes.latest(), messageElement.schemaFormat?.toValue()); - if (supportedSchemaFormats.includes(schemaFormat)) { + if (mediaTypes.includes(schemaFormat)) { return new SchemaElement(...args); } diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/message/index.ts b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/message/index.ts index 8427cddbd5..62b3838300 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/message/index.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/message/index.ts @@ -2,6 +2,7 @@ import stampit from 'stampit'; import { always, defaultTo } from 'ramda'; import { ObjectElement, isObjectElement, Element } from '@swagger-api/apidom-core'; +import mediaTypes from '../../../../media-types'; import MessageElement from '../../../../elements/Message'; import FallbackVisitor from '../../FallbackVisitor'; import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; @@ -17,20 +18,7 @@ const MessageVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { }, methods: { refractPayload(schemaFormat: string, payload: Element) { - if ( - [ - 'application/vnd.aai.asyncapi;version=2.0.0', - 'application/vnd.aai.asyncapi+json;version=2.0.0', - 'application/vnd.aai.asyncapi+yaml;version=2.0.0', - 'application/vnd.aai.asyncapi;version=2.1.0', - 'application/vnd.aai.asyncapi+json;version=2.1.0', - 'application/vnd.aai.asyncapi+yaml;version=2.1.0', - 'application/vnd.aai.asyncapi;version=2.2.0', - 'application/vnd.aai.asyncapi+json;version=2.2.0', - 'application/vnd.aai.asyncapi+yaml;version=2.2.0', - ].includes(schemaFormat) && - isObjectElement(payload) - ) { + if (isObjectElement(payload) && mediaTypes.includes(schemaFormat)) { this.element.payload = this.toRefractedElement(['document', 'objects', 'Schema'], payload); } }, @@ -49,7 +37,7 @@ const MessageVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { } else { // refract payload according to `schemaFormat` const schemaFormat = defaultTo( - 'application/vnd.aai.asyncapi;version=2.2.0', + mediaTypes.latest(), objectElement.get('schemaFormat')?.toValue(), ); this.refractPayload(schemaFormat, payload); diff --git a/packages/apidom-ns-asyncapi-2/test/refractor/__snapshots__/index.ts.snap b/packages/apidom-ns-asyncapi-2/test/refractor/__snapshots__/index.ts.snap index b2017091a2..44173e3830 100644 --- a/packages/apidom-ns-asyncapi-2/test/refractor/__snapshots__/index.ts.snap +++ b/packages/apidom-ns-asyncapi-2/test/refractor/__snapshots__/index.ts.snap @@ -11497,7 +11497,7 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.1.0 shape should re }, "value": { "element": "string", - "content": "application/vnd.aai.asyncapi;version=2.0.0" + "content": "application/vnd.aai.asyncapi;version=2.1.0" } } }, @@ -12397,7 +12397,7 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.1.0 shape should re }, "value": { "element": "string", - "content": "application/vnd.aai.asyncapi;version=2.0.0" + "content": "application/vnd.aai.asyncapi;version=2.1.0" } } }, @@ -19647,7 +19647,7 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.2.0 shape should re }, "value": { "element": "string", - "content": "application/vnd.aai.asyncapi;version=2.0.0" + "content": "application/vnd.aai.asyncapi;version=2.2.0" } } }, @@ -20630,7 +20630,7 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.2.0 shape should re }, "value": { "element": "string", - "content": "application/vnd.aai.asyncapi;version=2.0.0" + "content": "application/vnd.aai.asyncapi;version=2.2.0" } } }, diff --git a/packages/apidom-ns-asyncapi-2/test/refractor/fixtures/asyncapi-2-1-0.json b/packages/apidom-ns-asyncapi-2/test/refractor/fixtures/asyncapi-2-1-0.json index 829dac8cd6..0c58034440 100644 --- a/packages/apidom-ns-asyncapi-2/test/refractor/fixtures/asyncapi-2-1-0.json +++ b/packages/apidom-ns-asyncapi-2/test/refractor/fixtures/asyncapi-2-1-0.json @@ -127,7 +127,7 @@ "description": "correlation id description", "location": "http://asyncapi.com/" }, - "schemaFormat": "application/vnd.aai.asyncapi;version=2.0.0", + "schemaFormat": "application/vnd.aai.asyncapi;version=2.1.0", "contentType": "application/json", "name": "name of the message", "title": "title of the message", @@ -176,7 +176,7 @@ "description": "correlation id description", "location": "http://asyncapi.com/" }, - "schemaFormat": "application/vnd.aai.asyncapi;version=2.0.0", + "schemaFormat": "application/vnd.aai.asyncapi;version=2.1.0", "contentType": "application/json", "name": "name of the message trait", "title": "title of the message trait", diff --git a/packages/apidom-ns-asyncapi-2/test/refractor/fixtures/asyncapi-2-2-0.json b/packages/apidom-ns-asyncapi-2/test/refractor/fixtures/asyncapi-2-2-0.json index a3a5894833..036ab0af66 100644 --- a/packages/apidom-ns-asyncapi-2/test/refractor/fixtures/asyncapi-2-2-0.json +++ b/packages/apidom-ns-asyncapi-2/test/refractor/fixtures/asyncapi-2-2-0.json @@ -130,7 +130,7 @@ "description": "correlation id description", "location": "http://asyncapi.com/" }, - "schemaFormat": "application/vnd.aai.asyncapi;version=2.0.0", + "schemaFormat": "application/vnd.aai.asyncapi;version=2.2.0", "contentType": "application/json", "name": "name of the message", "title": "title of the message", @@ -183,7 +183,7 @@ "description": "correlation id description", "location": "http://asyncapi.com/" }, - "schemaFormat": "application/vnd.aai.asyncapi;version=2.0.0", + "schemaFormat": "application/vnd.aai.asyncapi;version=2.2.0", "contentType": "application/json", "name": "name of the message trait", "title": "title of the message trait", diff --git a/packages/apidom-parser-adapter-asyncapi-json-2/src/adapter.ts b/packages/apidom-parser-adapter-asyncapi-json-2/src/adapter.ts index 1be8f5c48c..5b8f21badb 100644 --- a/packages/apidom-parser-adapter-asyncapi-json-2/src/adapter.ts +++ b/packages/apidom-parser-adapter-asyncapi-json-2/src/adapter.ts @@ -2,16 +2,18 @@ import { propOr, omit } from 'ramda'; import { isNotUndefined } from 'ramda-adjunct'; import { ParseResultElement, createNamespace } from '@swagger-api/apidom-core'; import { parse as parseJson } from '@swagger-api/apidom-parser-adapter-json'; -import asyncApiNamespace, { AsyncApi2Element } from '@swagger-api/apidom-ns-asyncapi-2'; +import asyncApiNamespace, { + AsyncApi2Element, + mediaTypes, + AsyncAPIMediaTypes, +} from '@swagger-api/apidom-ns-asyncapi-2'; -export const mediaTypes = [ - 'application/vnd.aai.asyncapi;version=2.0.0', - 'application/vnd.aai.asyncapi+json;version=2.0.0', - 'application/vnd.aai.asyncapi;version=2.1.0', - 'application/vnd.aai.asyncapi+json;version=2.1.0', - 'application/vnd.aai.asyncapi;version=2.2.0', - 'application/vnd.aai.asyncapi+json;version=2.2.0', -]; +const jsonMediaTypes = new AsyncAPIMediaTypes( + ...mediaTypes.forFormat('generic'), + ...mediaTypes.forFormat('json'), +); + +export { jsonMediaTypes as mediaTypes }; export const detect = (source: string): boolean => !!source.match(/(["']?)asyncapi\1\s*:\s*(["']?)2\.\d+\.\d+\2/g); diff --git a/packages/apidom-parser-adapter-asyncapi-yaml-2/src/adapter.ts b/packages/apidom-parser-adapter-asyncapi-yaml-2/src/adapter.ts index e932cbc12f..5214750cf5 100644 --- a/packages/apidom-parser-adapter-asyncapi-yaml-2/src/adapter.ts +++ b/packages/apidom-parser-adapter-asyncapi-yaml-2/src/adapter.ts @@ -2,16 +2,18 @@ import { omit, propOr } from 'ramda'; import { isNotUndefined } from 'ramda-adjunct'; import { ParseResultElement, createNamespace } from '@swagger-api/apidom-core'; import { parse as parseYaml } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; -import asyncApiNamespace, { AsyncApi2Element } from '@swagger-api/apidom-ns-asyncapi-2'; +import asyncApiNamespace, { + AsyncApi2Element, + mediaTypes, + AsyncAPIMediaTypes, +} from '@swagger-api/apidom-ns-asyncapi-2'; -export const mediaTypes = [ - 'application/vnd.aai.asyncapi;version=2.0.0', - 'application/vnd.aai.asyncapi+yaml;version=2.0.0', - 'application/vnd.aai.asyncapi;version=2.1.0', - 'application/vnd.aai.asyncapi+yaml;version=2.1.0', - 'application/vnd.aai.asyncapi;version=2.2.0', - 'application/vnd.aai.asyncapi+yaml;version=2.2.0', -]; +const yamlMediaTypes = new AsyncAPIMediaTypes( + ...mediaTypes.forFormat('generic'), + ...mediaTypes.forFormat('yaml'), +); + +export { yamlMediaTypes as mediaTypes }; export const detect = (source: string): boolean => !!source.match(/(["']?)asyncapi\1\s*:\s*(["']?)2\.\d+\.\d+\2/g); diff --git a/packages/apidom-playground/src/playground/components/left-pane/EditorControls.jsx b/packages/apidom-playground/src/playground/components/left-pane/EditorControls.jsx index e39e7ae800..c4d1bea8c4 100644 --- a/packages/apidom-playground/src/playground/components/left-pane/EditorControls.jsx +++ b/packages/apidom-playground/src/playground/components/left-pane/EditorControls.jsx @@ -33,6 +33,7 @@ const EditorControls = () => { const canDereference = useSystemSelector('playground', 'selectCanDereference'); const source = useSystemSelector('playground', 'selectSource'); const apiDOM = useSystemSelector('playground', 'selectApiDOM'); + const mediaTypes = useSystemSelector('playground', 'selectMediaTypes'); const setMediaType = useSystemActionCreatorBound('playground', 'setMediaType'); const setBaseURI = useSystemActionCreatorBound('playground', 'setBaseURI'); const parseSource = useSystemActionCreatorBound('playground', 'parseSource'); @@ -103,33 +104,11 @@ const EditorControls = () => { application/vnd.oai.openapi+yaml;version=3.1.0 - - application/vnd.aai.asyncapi;version=2.0.0 - - - application/vnd.aai.asyncapi+json;version=2.0.0 - - - application/vnd.aai.asyncapi+yaml;version=2.0.0 - - - application/vnd.aai.asyncapi;version=2.1.0 - - - application/vnd.aai.asyncapi+json;version=2.1.0 - - - application/vnd.aai.asyncapi+yaml;version=2.1.0 - - - application/vnd.aai.asyncapi;version=2.2.0 - - - application/vnd.aai.asyncapi+json;version=2.2.0 - - - application/vnd.aai.asyncapi+yaml;version=2.2.0 - + {mediaTypes.map((medType) => ( + + {medType} + + ))} diff --git a/packages/apidom-playground/src/playground/plugin.js b/packages/apidom-playground/src/playground/plugin.js index 00599028c4..2014e67c3b 100644 --- a/packages/apidom-playground/src/playground/plugin.js +++ b/packages/apidom-playground/src/playground/plugin.js @@ -28,6 +28,7 @@ import { selectCanParse, selectCanResolve, selectCanDereference, + selectMediaTypes, } from './selectors.js'; import AppBar from './components/AppBar.jsx'; import Backdrop from './components/Backdrop.jsx'; @@ -97,6 +98,7 @@ const ApiDOMPlaygroundPlugin = () => ({ selectCanParse, selectCanResolve, selectCanDereference, + selectMediaTypes, }, }, }, diff --git a/packages/apidom-playground/src/playground/selectors.js b/packages/apidom-playground/src/playground/selectors.js index 2827ab2044..b445444de8 100644 --- a/packages/apidom-playground/src/playground/selectors.js +++ b/packages/apidom-playground/src/playground/selectors.js @@ -4,7 +4,9 @@ import { from, traverse, createNamespace, sexprs, toValue } from '@swagger-api/a /* eslint-disable camelcase */ import openApi3_1NsPlugin from '@swagger-api/apidom-ns-openapi-3-1'; /* eslint-enable */ -import asyncApi2NsPlugin from '@swagger-api/apidom-ns-asyncapi-2'; +import asyncApi2NsPlugin, { + mediaTypes as asyncApi2MediaTypes, +} from '@swagger-api/apidom-ns-asyncapi-2'; export const selectSource = (state) => state.source; @@ -31,7 +33,7 @@ export const selectApiDOMNamespace = createSelector(selectMediaType, (mediaType) if (mediaType.includes('vnd.oai.openapi')) { return createNamespace(openApi3_1NsPlugin); } - if (mediaType.includes('vnd.aai.asyncapi')) { + if (asyncApi2MediaTypes.includes(mediaType)) { return createNamespace(asyncApi2NsPlugin); } return createNamespace(); @@ -99,3 +101,8 @@ export const selectCanDereference = createSelector( (baseURI, apiDOM, mediaType) => isNonEmptyString(baseURI) && isNonEmptyString(apiDOM) && isNonEmptyString(mediaType) ); + +export const selectMediaTypes = (() => { + const allMediaTypes = [...asyncApi2MediaTypes]; + return () => allMediaTypes; +})(); diff --git a/packages/apidom-reference/src/dereference/strategies/asyncapi-2/index.ts b/packages/apidom-reference/src/dereference/strategies/asyncapi-2/index.ts index 805f40ea90..18d344e60f 100644 --- a/packages/apidom-reference/src/dereference/strategies/asyncapi-2/index.ts +++ b/packages/apidom-reference/src/dereference/strategies/asyncapi-2/index.ts @@ -5,6 +5,7 @@ import asyncApi2Namespace, { getNodeType, isAsyncApi2Element, keyMap, + mediaTypes, } from '@swagger-api/apidom-ns-asyncapi-2'; import DereferenceStrategy from '../DereferenceStrategy'; @@ -30,17 +31,7 @@ const AsyncApi2DereferenceStrategy: stampit.Stamp = stampi canDereference(file: IFile): boolean { // assert by media type if (file.mediaType !== 'text/plain') { - return [ - 'application/vnd.aai.asyncapi;version=2.0.0', - 'application/vnd.aai.asyncapi+json;version=2.0.0', - 'application/vnd.aai.asyncapi+yaml;version=2.0.0', - 'application/vnd.aai.asyncapi;version=2.1.0', - 'application/vnd.aai.asyncapi+json;version=2.1.0', - 'application/vnd.aai.asyncapi+yaml;version=2.1.0', - 'application/vnd.aai.asyncapi;version=2.2.0', - 'application/vnd.aai.asyncapi+json;version=2.2.0', - 'application/vnd.aai.asyncapi+yaml;version=2.2.0', - ].includes(file.mediaType); + return mediaTypes.includes(file.mediaType); } // assert by inspecting ApiDOM diff --git a/packages/apidom-reference/src/resolve/strategies/asyncapi-2/index.ts b/packages/apidom-reference/src/resolve/strategies/asyncapi-2/index.ts index 8ec2c1aeed..2f30783f76 100644 --- a/packages/apidom-reference/src/resolve/strategies/asyncapi-2/index.ts +++ b/packages/apidom-reference/src/resolve/strategies/asyncapi-2/index.ts @@ -4,6 +4,7 @@ import asyncApi2Namespace, { getNodeType, isAsyncApi2Element, keyMap, + mediaTypes, } from '@swagger-api/apidom-ns-asyncapi-2'; import ResolveStrategy from '../ResolveStrategy'; @@ -27,17 +28,7 @@ const AsyncApi2ResolveStrategy: stampit.Stamp = stampit(Resolv canResolve(file: IFile) { // assert by media type if (file.mediaType !== 'text/plain') { - return [ - 'application/vnd.aai.asyncapi;version=2.0.0', - 'application/vnd.aai.asyncapi+json;version=2.0.0', - 'application/vnd.aai.asyncapi+yaml;version=2.0.0', - 'application/vnd.aai.asyncapi;version=2.1.0', - 'application/vnd.aai.asyncapi+json;version=2.1.0', - 'application/vnd.aai.asyncapi+yaml;version=2.1.0', - 'application/vnd.aai.asyncapi;version=2.2.0', - 'application/vnd.aai.asyncapi+json;version=2.2.0', - 'application/vnd.aai.asyncapi+yaml;version=2.2.0', - ].includes(file.mediaType); + return mediaTypes.includes(file.mediaType); } // assert by inspecting ApiDOM diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/channel-item-object/index.ts b/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/channel-item-object/index.ts index 08fe9df791..727b5d16bc 100644 --- a/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/channel-item-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/channel-item-object/index.ts @@ -1,6 +1,7 @@ import path from 'path'; import { assert } from 'chai'; import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; @@ -19,7 +20,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -33,7 +34,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -47,7 +48,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -61,7 +62,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -75,7 +76,7 @@ describe('dereference', function () { specify('should not dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, resolve: { external: false }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -90,7 +91,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -104,7 +105,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -120,7 +121,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw DereferenceError'); } catch (e) { @@ -137,7 +138,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, dereference: { maxDepth: 1 }, }); assert.fail('should throw MaximumDereferenceDepthError'); @@ -157,7 +158,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw DereferenceError'); } catch (e) { @@ -174,7 +175,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw DereferenceError'); } catch (e) { @@ -191,7 +192,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw DereferenceError'); } catch (e) { @@ -208,7 +209,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw DereferenceError'); } catch (e) { @@ -225,7 +226,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw DereferenceError'); } catch (e) { diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/message-object/index.ts b/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/message-object/index.ts index 477cc9ce57..62da21cccc 100644 --- a/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/message-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/message-object/index.ts @@ -1,6 +1,7 @@ import path from 'path'; import { assert } from 'chai'; import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; @@ -17,7 +18,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/reference-object/index.ts b/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/reference-object/index.ts index 272a1bdd89..c4b1e8fe7d 100644 --- a/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/reference-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-2-0/reference-object/index.ts @@ -1,7 +1,7 @@ import path from 'path'; import { assert } from 'chai'; import { toValue } from '@swagger-api/apidom-core'; -import { isParameterElement } from '@swagger-api/apidom-ns-asyncapi-2'; +import { isParameterElement, mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import { loadJsonFile } from '../../../../helpers'; import { dereference, resolve } from '../../../../../src'; @@ -24,7 +24,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -34,7 +34,7 @@ describe('dereference', function () { specify('should apply semantics to external fragment', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const fragment = evaluate('/0/components/parameters/externalRef', dereferenced); @@ -46,7 +46,7 @@ describe('dereference', function () { async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const fragment = evaluate('/0/components/parameters/userId', dereferenced); @@ -64,7 +64,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -78,7 +78,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -92,7 +92,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -102,7 +102,7 @@ describe('dereference', function () { specify('should apply semantics to eventual external fragment', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const fragment = evaluate('/0/components/parameters/externalRef', dereferenced); @@ -116,7 +116,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -130,7 +130,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const parent = evaluate('/0/components/schemas/User/properties/parent', dereferenced); const cyclicParent = evaluate( @@ -148,7 +148,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, resolve: { external: false }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -164,7 +164,7 @@ describe('dereference', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, DereferenceError); @@ -179,7 +179,7 @@ describe('dereference', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, DereferenceError); @@ -194,7 +194,7 @@ describe('dereference', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, DereferenceError); @@ -209,7 +209,7 @@ describe('dereference', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, DereferenceError); @@ -224,7 +224,7 @@ describe('dereference', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, DereferenceError); @@ -239,7 +239,7 @@ describe('dereference', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, DereferenceError); @@ -253,7 +253,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -267,7 +267,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -281,7 +281,7 @@ describe('dereference', function () { specify('should dereference', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const actual = await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); @@ -297,7 +297,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, dereference: { maxDepth: 2 }, }); assert.fail('should throw MaximumDereferenceDepthError'); @@ -317,7 +317,7 @@ describe('dereference', function () { try { await dereference(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, resolve: { maxDepth: 2 }, }); assert.fail('should throw MaximumResolverDepthError'); @@ -334,7 +334,7 @@ describe('dereference', function () { const fixturePath = path.join(__dirname, 'fixtures', 'refset-as-option'); const uri = path.join(fixturePath, 'root.json'); const refSet = await resolve(uri, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); const actual = await dereference(uri, { dereference: { refSet } }); const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); diff --git a/packages/apidom-reference/test/parse/parsers/apidom-reference-parser-asyncapi-json-2-0/index.ts b/packages/apidom-reference/test/parse/parsers/apidom-reference-parser-asyncapi-json-2-0/index.ts index f38ed5451b..47eca42ce9 100644 --- a/packages/apidom-reference/test/parse/parsers/apidom-reference-parser-asyncapi-json-2-0/index.ts +++ b/packages/apidom-reference/test/parse/parsers/apidom-reference-parser-asyncapi-json-2-0/index.ts @@ -2,6 +2,7 @@ import fs from 'fs'; import path from 'path'; import { assert } from 'chai'; import { isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import File from '../../../../src/util/File'; import AsyncApiJson2Parser from '../../../../src/parse/parsers/apidom-reference-parser-asyncapi-json-2'; @@ -15,11 +16,11 @@ describe('parsers', function () { specify('should return true', function () { const file1 = File({ uri: '/path/to/asyncapi.json', - mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0', + mediaType: mediaTypes.latest('json'), }); const file2 = File({ uri: '/path/to/asyncapi.json', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiJson2Parser(); @@ -45,7 +46,7 @@ describe('parsers', function () { specify('should return false', function () { const file = File({ uri: '/path/to/asyncapi.yaml', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiJson2Parser(); @@ -57,7 +58,7 @@ describe('parsers', function () { specify('should return false', function () { const file = File({ uri: '/path/to/asyncapi', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiJson2Parser(); @@ -74,7 +75,7 @@ describe('parsers', function () { const file = File({ url, data, - mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0', + mediaType: mediaTypes.latest('json'), }); const parser = AsyncApiJson2Parser(); const parseResult = await parser.parse(file); @@ -90,7 +91,7 @@ describe('parsers', function () { const file = File({ url, data, - mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0', + mediaType: mediaTypes.latest('json'), }); const parser = AsyncApiJson2Parser(); const parseResult = await parser.parse(file); @@ -105,7 +106,7 @@ describe('parsers', function () { const file = File({ uri: '/path/to/file.json', data: 1, - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiJson2Parser(); await parser.parse(file); @@ -123,7 +124,7 @@ describe('parsers', function () { const file = File({ uri: '/path/to/file.json', data: '', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiJson2Parser(); const parseResult = await parser.parse(file); @@ -141,7 +142,7 @@ describe('parsers', function () { const file = File({ url, data, - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiJson2Parser({ sourceMap: true }); const parseResult = await parser.parse(file); @@ -157,7 +158,7 @@ describe('parsers', function () { const file = File({ url, data, - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiJson2Parser({ sourceMap: false }); const parseResult = await parser.parse(file); diff --git a/packages/apidom-reference/test/parse/parsers/apidom-reference-parser-asyncapi-yaml-2-0/index.ts b/packages/apidom-reference/test/parse/parsers/apidom-reference-parser-asyncapi-yaml-2-0/index.ts index 29ba66341a..b6d2590c04 100644 --- a/packages/apidom-reference/test/parse/parsers/apidom-reference-parser-asyncapi-yaml-2-0/index.ts +++ b/packages/apidom-reference/test/parse/parsers/apidom-reference-parser-asyncapi-yaml-2-0/index.ts @@ -2,6 +2,7 @@ import fs from 'fs'; import path from 'path'; import { assert } from 'chai'; import { isParseResultElement, isSourceMapElement } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import File from '../../../../src/util/File'; import AsyncApiYaml2Parser from '../../../../src/parse/parsers/apidom-reference-parser-asyncapi-yaml-2'; @@ -15,11 +16,11 @@ describe('parsers', function () { specify('should return true', function () { const file1 = File({ uri: '/path/to/asyncapi.yaml', - mediaType: 'application/vnd.aai.asyncapi+yaml;version=2.2.0', + mediaType: mediaTypes.latest('yaml'), }); const file2 = File({ uri: '/path/to/asyncapi.yaml', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiYaml2Parser(); @@ -46,11 +47,11 @@ describe('parsers', function () { specify('should return true', function () { const file1 = File({ uri: '/path/to/asyncapi.yml', - mediaType: 'application/vnd.aai.asyncapi+yaml;version=2.2.0', + mediaType: mediaTypes.latest('yaml'), }); const file2 = File({ uri: '/path/to/asyncapi.yml', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiYaml2Parser(); @@ -76,7 +77,7 @@ describe('parsers', function () { specify('should return false', function () { const file = File({ uri: '/path/to/asyncapi.txt', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiYaml2Parser(); @@ -88,7 +89,7 @@ describe('parsers', function () { specify('should return false', function () { const file = File({ uri: '/path/to/asyncapi', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiYaml2Parser(); @@ -102,7 +103,7 @@ describe('parsers', function () { specify('should return parse result', async function () { const url = path.join(__dirname, 'fixtures', 'sample-api.yaml'); const data = fs.readFileSync(url).toString(); - const file = File({ url, data, mediaType: 'application/vnd.aai.asyncapi;version=2.2.0' }); + const file = File({ url, data, mediaType: mediaTypes.latest() }); const parser = AsyncApiYaml2Parser(); const parseResult = await parser.parse(file); @@ -114,7 +115,7 @@ describe('parsers', function () { specify('should return parse result', async function () { const url = path.join(__dirname, 'fixtures', 'sample-api.yaml'); const data = fs.readFileSync(url); - const file = File({ url, data, mediaType: 'application/vnd.aai.asyncapi;version=2.2.0' }); + const file = File({ url, data, mediaType: mediaTypes.latest() }); const parser = AsyncApiYaml2Parser(); const parseResult = await parser.parse(file); @@ -128,7 +129,7 @@ describe('parsers', function () { const file = File({ uri: '/path/to/file.yaml', data: 1, - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiYaml2Parser(); await parser.parse(file); @@ -146,7 +147,7 @@ describe('parsers', function () { const file = File({ uri: '/path/to/file.yaml', data: '', - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiYaml2Parser(); const parsceResult = await parser.parse(file); @@ -164,7 +165,7 @@ describe('parsers', function () { const file = File({ url, data, - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiYaml2Parser({ sourceMap: true }); const parseResult = await parser.parse(file); @@ -180,7 +181,7 @@ describe('parsers', function () { const file = File({ url, data, - mediaType: 'application/vnd.aai.asyncapi;version=2.2.0', + mediaType: mediaTypes.latest(), }); const parser = AsyncApiYaml2Parser({ sourceMap: false }); const parseResult = await parser.parse(file); diff --git a/packages/apidom-reference/test/resolve/strategies/asyncapi-2-0/channel-item-object/index.ts b/packages/apidom-reference/test/resolve/strategies/asyncapi-2-0/channel-item-object/index.ts index be5dee1c40..d3c277d3ae 100644 --- a/packages/apidom-reference/test/resolve/strategies/asyncapi-2-0/channel-item-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/asyncapi-2-0/channel-item-object/index.ts @@ -1,5 +1,6 @@ import path from 'path'; import { assert } from 'chai'; +import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import { resolve } from '../../../../../src'; import { ResolverError, MaximumDereferenceDepthError } from '../../../../../src/util/errors'; @@ -17,7 +18,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 2); @@ -30,7 +31,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 2); @@ -43,7 +44,7 @@ describe('resolve', function () { specify('should not resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, resolve: { external: false }, }); @@ -57,7 +58,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 3); @@ -72,7 +73,7 @@ describe('resolve', function () { try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw ResolverError'); } catch (e) { @@ -89,7 +90,7 @@ describe('resolve', function () { try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, dereference: { maxDepth: 1 }, }); assert.fail('should throw MaximumDereferenceDepthError'); @@ -109,7 +110,7 @@ describe('resolve', function () { try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw ResolverError'); } catch (e) { @@ -126,7 +127,7 @@ describe('resolve', function () { try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw ResolverError'); } catch (e) { @@ -143,7 +144,7 @@ describe('resolve', function () { try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.fail('should throw ResolverError'); } catch (e) { diff --git a/packages/apidom-reference/test/resolve/strategies/asyncapi-2-0/reference-object/index.ts b/packages/apidom-reference/test/resolve/strategies/asyncapi-2-0/reference-object/index.ts index 8b291f2236..ea11d91e83 100644 --- a/packages/apidom-reference/test/resolve/strategies/asyncapi-2-0/reference-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/asyncapi-2-0/reference-object/index.ts @@ -1,5 +1,6 @@ import path from 'path'; import { assert } from 'chai'; +import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import { resolve } from '../../../../../src'; import { @@ -20,7 +21,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 2); @@ -33,7 +34,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 1); @@ -46,7 +47,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 2); @@ -59,7 +60,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 4); @@ -72,7 +73,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, resolve: { external: false }, }); @@ -87,7 +88,7 @@ describe('resolve', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, ResolverError); @@ -102,7 +103,7 @@ describe('resolve', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, ResolverError); @@ -117,7 +118,7 @@ describe('resolve', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, ResolverError); @@ -132,7 +133,7 @@ describe('resolve', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, ResolverError); @@ -147,7 +148,7 @@ describe('resolve', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, ResolverError); @@ -162,7 +163,7 @@ describe('resolve', function () { const rootFilePath = path.join(fixturePath, 'root.json'); try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); } catch (e) { assert.instanceOf(e, ResolverError); @@ -176,7 +177,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 2); @@ -189,7 +190,7 @@ describe('resolve', function () { specify('should resolve', async function () { const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, }); assert.strictEqual(refSet.size, 2); @@ -204,7 +205,7 @@ describe('resolve', function () { try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, dereference: { maxDepth: 2 }, }); assert.fail('should throw MaximumDereferenceDepthError'); @@ -224,7 +225,7 @@ describe('resolve', function () { try { await resolve(rootFilePath, { - parse: { mediaType: 'application/vnd.aai.asyncapi+json;version=2.2.0' }, + parse: { mediaType: mediaTypes.latest('json') }, resolve: { maxDepth: 2 }, }); assert.fail('should throw MaximumResolverDepthError');