diff --git a/src/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js b/src/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js index d51f1eff2..c45cb02bc 100644 --- a/src/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +++ b/src/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js @@ -492,6 +492,14 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c // transclude referencing element with merged referenced element return mergedSchemaElement; }, + async LinkElement() { + /** + * OpenApi3_1DereferenceVisitor is doing lookup of Operation Objects + * and assigns them to Link Object metadata. This is not needed in + * swagger-client context, so we're disabling it here. + */ + return undefined; + }, }, }); diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id-non-existent/root.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id-non-existent/root.json deleted file mode 100644 index 3d24df352..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id-non-existent/root.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationId": "op1" - } - } - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id/dereferenced.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id/dereferenced.json deleted file mode 100644 index 54b33ce51..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id/dereferenced.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationId": "op1" - } - }, - "pathItems": { - "pathItem1": { - "get": { - "operationId": "op1", - "description": "description of operation" - } - } - } - } - } -] diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id/root.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id/root.json deleted file mode 100644 index 45a7f2b54..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-id/root.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationId": "op1" - } - }, - "pathItems": { - "pathItem1": { - "get": { - "operationId": "op1", - "description": "description of operation" - } - } - } - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/dereferenced.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/dereferenced.json deleted file mode 100644 index c8ccfd037..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/dereferenced.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "./ex.json#/operation" - } - } - } - } -] diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/ex.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/ex.json deleted file mode 100644 index 3d6eb5ad8..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/ex.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "operation": { - "description": "description of operation" - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/root.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/root.json deleted file mode 100644 index 76e616716..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-external/root.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "./ex.json#/operation" - } - } - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-id-both-defined/root.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-id-both-defined/root.json deleted file mode 100644 index 78b2af181..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-id-both-defined/root.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "#/components/pathItems/pathItem1/get", - "operationId": "op1" - } - } - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/dereferenced.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/dereferenced.json deleted file mode 100644 index c8ccfd037..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/dereferenced.json +++ /dev/null @@ -1,12 +0,0 @@ -[ - { - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "./ex.json#/operation" - } - } - } - } -] diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/ex.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/ex.json deleted file mode 100644 index 3d6eb5ad8..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/ex.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "operation": { - "description": "description of operation" - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/root.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/root.json deleted file mode 100644 index 76e616716..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-ignore-external/root.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "./ex.json#/operation" - } - } - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-internal/dereferenced.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-internal/dereferenced.json deleted file mode 100644 index 11d3b1a74..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-internal/dereferenced.json +++ /dev/null @@ -1,19 +0,0 @@ -[ - { - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "#/components/pathItems/pathItem1/get" - } - }, - "pathItems": { - "pathItem1": { - "get": { - "description": "description of operation" - } - } - } - } - } -] diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-internal/root.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-internal/root.json deleted file mode 100644 index e91b65104..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-internal/root.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "#/components/pathItems/pathItem1/get" - } - }, - "pathItems": { - "pathItem1": { - "get": { - "description": "description of operation" - } - } - } - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-invalid-pointer/root.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-invalid-pointer/root.json deleted file mode 100644 index 2da69bb32..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-invalid-pointer/root.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "invalid-pointer" - } - } - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-unresolvable/root.json b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-unresolvable/root.json deleted file mode 100644 index 3b24ce87d..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/__fixtures__/operation-ref-unresolvable/root.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "openapi": "3.1.0", - "components": { - "links": { - "link1": { - "operationRef": "#/components/invalid-pointer" - } - } - } -} diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/dereference-apidom.js b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/dereference-apidom.js deleted file mode 100644 index 12ca25a9d..000000000 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/dereference-apidom.js +++ /dev/null @@ -1,60 +0,0 @@ -import path from 'node:path'; -import { mediaTypes, isLinkElement, isOperationElement } from '@swagger-api/apidom-ns-openapi-3-1'; -import { evaluate } from '@swagger-api/apidom-json-pointer'; -import { parse, dereferenceApiDOM } from '@swagger-api/apidom-reference/configuration/empty'; - -import * as jestSetup from '../__utils__/jest.local.setup.js'; - -describe('dereference', () => { - beforeAll(() => { - jestSetup.beforeAll(); - }); - - afterAll(() => { - jestSetup.afterAll(); - }); - - describe('strategies', () => { - describe('openapi-3-1-swagger-client', () => { - describe('Link Object', () => { - describe('given single LinkElement passed to dereferenceApiDOM', () => { - const fixturePath = path.join( - __dirname, - '__fixtures__', - 'operation-ref-external', - 'root.json' - ); - - test('should dereference', async () => { - const parseResult = await parse(fixturePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const linkElement = evaluate('/components/links/link1', parseResult.api); - const dereferenced = await dereferenceApiDOM(linkElement, { - parse: { mediaType: mediaTypes.latest('json') }, - resolve: { baseURI: fixturePath }, - }); - - expect(isLinkElement(dereferenced)).toBe(true); - expect(isOperationElement(dereferenced.operationRef?.meta.get('operation'))).toBe(true); - }); - - test('should dereference and contain metadata about origin', async () => { - const parseResult = await parse(fixturePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const linkElement = evaluate('/components/links/link1', parseResult.api); - const dereferenced = await dereferenceApiDOM(linkElement, { - parse: { mediaType: mediaTypes.latest('json') }, - resolve: { baseURI: fixturePath }, - }); - - expect( - dereferenced.operationRef?.meta.get('operation').meta.get('ref-origin').toValue() - ).toEqual(expect.stringMatching(/operation-ref-external\/ex\.json$/)); - }); - }); - }); - }); - }); -}); diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/index.js b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/index.js index fbf65e41b..0b0fd37a4 100644 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/index.js +++ b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/link-object/index.js @@ -1,8 +1,7 @@ import path from 'node:path'; import { toValue } from '@swagger-api/apidom-core'; -import { isOperationElement, mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; -import { evaluate } from '@swagger-api/apidom-json-pointer'; -import { dereference, DereferenceError } from '@swagger-api/apidom-reference/configuration/empty'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; +import { dereference } from '@swagger-api/apidom-reference/configuration/empty'; import * as jestSetup from '../__utils__/jest.local.setup.js'; @@ -32,18 +31,6 @@ describe('dereference', () => { expect(toValue(actual)).toEqual(expected); }); - - test('should set Operation Object as metadata of Link.operationId field', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const link1 = evaluate('/0/components/links/link1', dereferenced); - const link2 = evaluate('/0/components/links/link2', dereferenced); - - expect(isOperationElement(link1.operationId?.meta.get('operation'))).toBe(true); - expect(isOperationElement(link2.operationId?.meta.get('operation'))).toBe(true); - }); }); describe('given in Response Object', () => { @@ -58,177 +45,6 @@ describe('dereference', () => { expect(toValue(actual)).toEqual(expected); }); - - test('should set Operation Object as metadata of Link.operationId field', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const link1 = evaluate('/0/components/responses/201/links/link', dereferenced); - const link2 = evaluate('/0/components/links/link1', dereferenced); - - expect(isOperationElement(link1.operationId?.meta.get('operation'))).toBe(true); - expect(isOperationElement(link2.operationId?.meta.get('operation'))).toBe(true); - }); - }); - - describe('given operationRef field', () => { - describe('and with internal JSON Pointer', () => { - const fixturePath = path.join(rootFixturePath, 'operation-ref-internal'); - - test('should dereference', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const actual = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const expected = globalThis.loadJsonFile(path.join(fixturePath, 'dereferenced.json')); - - expect(toValue(actual)).toEqual(expected); - }); - - test('should set Operation Object as metadata of Link.operationRef field', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const link1 = evaluate('/0/components/links/link1', dereferenced); - - expect(isOperationElement(link1.operationRef?.meta.get('operation'))).toBe(true); - }); - }); - - describe('and with external JSON Pointer', () => { - const fixturePath = path.join(rootFixturePath, 'operation-ref-external'); - const rootFilePath = path.join(fixturePath, 'root.json'); - - test('should dereference', async () => { - const actual = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const expected = globalThis.loadJsonFile(path.join(fixturePath, 'dereferenced.json')); - - expect(toValue(actual)).toEqual(expected); - }); - - test('should apply semantics to external fragment', async () => { - const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - - expect( - isOperationElement(dereferenced.api.components.links.get('link1').operation) - ).toBe(true); - }); - - test('should set Operation Object as metadata of Link.operationRef field', async () => { - const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const link1 = evaluate('/0/components/links/link1', dereferenced); - - expect(isOperationElement(link1.operationRef?.meta.get('operation'))).toBe(true); - }); - }); - - describe('with external resolution disabled', () => { - const fixturePath = path.join(rootFixturePath, 'operation-ref-ignore-external'); - - test('should not dereference', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const actual = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - resolve: { external: false }, - }); - const expected = globalThis.loadJsonFile(path.join(fixturePath, 'dereferenced.json')); - - expect(toValue(actual)).toEqual(expected); - }); - }); - - describe('and with invalid JSON Pointer', () => { - const fixturePath = path.join(rootFixturePath, 'operation-ref-invalid-pointer'); - - test('should throw error', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const dereferenceThunk = () => - dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - - await expect(dereferenceThunk()).rejects.toThrow(DereferenceError); - }); - }); - - describe('and with unresolvable JSON Pointer', () => { - const fixturePath = path.join(rootFixturePath, 'operation-ref-unresolvable'); - - test('should throw error', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const dereferenceThunk = () => - dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - - await expect(dereferenceThunk()).rejects.toThrow(DereferenceError); - }); - }); - }); - - describe('given operationId field', () => { - describe('and OperationElement with operationId exists', () => { - const fixturePath = path.join(rootFixturePath, 'operation-id'); - const rootFilePath = path.join(fixturePath, 'root.json'); - - test('should dereference', async () => { - const actual = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const expected = globalThis.loadJsonFile(path.join(fixturePath, 'dereferenced.json')); - - expect(toValue(actual)).toEqual(expected); - }); - - test('should set Operation Object as metadata of Link.operationId field', async () => { - const dereferenced = await dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - const link1 = evaluate('/0/components/links/link1', dereferenced); - - expect(isOperationElement(link1.operationId?.meta.get('operation'))).toBe(true); - }); - }); - - describe("and OperationElement with operationId doesn't exist", () => { - const fixturePath = path.join(rootFixturePath, 'operation-id-non-existent'); - - test('should throw error', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const dereferenceThunk = () => - dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - - await expect(dereferenceThunk()).rejects.toThrow(DereferenceError); - }); - }); - }); - - describe('given both operationRef and operationId fields are defined', () => { - const fixturePath = path.join(rootFixturePath, 'operation-ref-id-both-defined'); - - test('should throw error', async () => { - const rootFilePath = path.join(fixturePath, 'root.json'); - const dereferenceThunk = () => - dereference(rootFilePath, { - parse: { mediaType: mediaTypes.latest('json') }, - }); - - await expect(dereferenceThunk()).rejects.toThrow(DereferenceError); - await expect(dereferenceThunk()).rejects.toHaveProperty( - 'cause.cause.message', - 'LinkElement operationRef and operationId fields are mutually exclusive.' - ); - }); }); }); }); diff --git a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/schema-object/index.js b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/schema-object/index.js index 72d8d62de..b51182bd1 100644 --- a/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/schema-object/index.js +++ b/test/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/schema-object/index.js @@ -1050,7 +1050,7 @@ describe('dereference', () => { }); describe('and useCircularStructures=false', () => { - test.only('should dereference', async () => { + test('should dereference', async () => { const fixturePath = path.join(rootFixturePath, '$ref-urn-circular-structures'); const rootFilePath = path.join(fixturePath, 'root.json'); const refSet = await resolve(rootFilePath, {