From 4925466310f6f1997a64f824faf9214820392506 Mon Sep 17 00:00:00 2001 From: Oliwia Rogala Date: Fri, 19 Dec 2025 13:45:46 +0100 Subject: [PATCH] test(reference): add dereference tests for Multi Format Schema in AsyncAPI 3 --- .../components-schemas/dereferenced.json | 31 ++++++++++ .../fixtures/components-schemas/root.json | 21 +++++++ .../fixtures/message-object/dereferenced.json | 47 ++++++++++++++ .../fixtures/message-object/root.json | 34 +++++++++++ .../message-trait-object/dereferenced.json | 35 +++++++++++ .../fixtures/message-trait-object/root.json | 25 ++++++++ .../multi-format-schema-object/index.ts | 61 +++++++++++++++++++ 7 files changed, 254 insertions(+) create mode 100644 packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/components-schemas/dereferenced.json create mode 100644 packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/components-schemas/root.json create mode 100644 packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-object/dereferenced.json create mode 100644 packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-object/root.json create mode 100644 packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-trait-object/dereferenced.json create mode 100644 packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-trait-object/root.json create mode 100644 packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/index.ts diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/components-schemas/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/components-schemas/dereferenced.json new file mode 100644 index 000000000..ee374767e --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/components-schemas/dereferenced.json @@ -0,0 +1,31 @@ +[ + { + "asyncapi": "3.0.0", + "components": { + "schemas": { + "multiFormatSchema1": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + }, + "multiFormatSchema2": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/components-schemas/root.json b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/components-schemas/root.json new file mode 100644 index 000000000..24a801f57 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/components-schemas/root.json @@ -0,0 +1,21 @@ +{ + "asyncapi": "3.0.0", + "components": { + "schemas": { + "multiFormatSchema1": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + }, + "multiFormatSchema2": { + "$ref": "#/components/schemas/multiFormatSchema1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-object/dereferenced.json new file mode 100644 index 000000000..8b395c4fa --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-object/dereferenced.json @@ -0,0 +1,47 @@ +[ + { + "asyncapi": "3.0.0", + "components": { + "schemas": { + "multiFormatSchema1": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + }, + "multiFormatSchema2": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "string" + } + } + }, + "messages": { + "message1": { + "headers": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + }, + "payload": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-object/root.json b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-object/root.json new file mode 100644 index 000000000..3a2726619 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-object/root.json @@ -0,0 +1,34 @@ +{ + "asyncapi": "3.0.0", + "components": { + "schemas": { + "multiFormatSchema1": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + }, + "multiFormatSchema2": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "string" + } + } + }, + "messages": { + "message1": { + "headers": { + "$ref": "#/components/schemas/multiFormatSchema1" + }, + "payload": { + "$ref": "#/components/schemas/multiFormatSchema2" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-trait-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-trait-object/dereferenced.json new file mode 100644 index 000000000..b362dafd4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-trait-object/dereferenced.json @@ -0,0 +1,35 @@ +[ + { + "asyncapi": "3.0.0", + "components": { + "schemas": { + "multiFormatSchema1": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + } + }, + "messageTraits": { + "messageTrait1": { + "headers": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-trait-object/root.json b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-trait-object/root.json new file mode 100644 index 000000000..507285f0e --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/fixtures/message-trait-object/root.json @@ -0,0 +1,25 @@ +{ + "asyncapi": "3.0.0", + "components": { + "schemas": { + "multiFormatSchema1": { + "schemaFormat": "application/vnd.aai.asyncapi;version=3.0.0", + "schema": { + "type": "object", + "properties": { + "property1": { + "type": "string" + } + } + } + } + }, + "messageTraits": { + "messageTrait1": { + "headers": { + "$ref": "#/components/schemas/multiFormatSchema1" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/index.ts b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/index.ts new file mode 100644 index 000000000..ae1c92f98 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-3/multi-format-schema-object/index.ts @@ -0,0 +1,61 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-3'; +import { fileURLToPath } from 'node:url'; + +import { loadJsonFile } from '../../../../helpers.ts'; +import { dereference } from '../../../../../src/index.ts'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + context('strategies', function () { + context('asyncapi-3', function () { + context('Multi Format Schema Object', function () { + context('given in Message Object', function () { + const fixturePath = path.join(rootFixturePath, 'message-object'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given in Message Trait Object', function () { + const fixturePath = path.join(rootFixturePath, 'message-trait-object'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given in components/schemas field', function () { + const fixturePath = path.join(rootFixturePath, 'components-schemas'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + }); + }); + }); +});