diff --git a/packages/apidom-reference/src/parse/parsers/Parser.ts b/packages/apidom-reference/src/parse/parsers/Parser.ts index 1185f6ad56..997602e96e 100644 --- a/packages/apidom-reference/src/parse/parsers/Parser.ts +++ b/packages/apidom-reference/src/parse/parsers/Parser.ts @@ -4,7 +4,7 @@ import { ParseResultElement } from '@swagger-api/apidom-core'; import { Parser as IParser } from '../../types'; import { NotImplementedError } from '../../util/errors'; -const Parser = stampit({ +const Parser: stampit.Stamp = stampit({ props: { name: '', /** diff --git a/packages/apidom-reference/src/types.ts b/packages/apidom-reference/src/types.ts index 7fa7a63050..6fc1a45b97 100644 --- a/packages/apidom-reference/src/types.ts +++ b/packages/apidom-reference/src/types.ts @@ -76,24 +76,24 @@ export interface ReferenceSet { } export interface ReferenceParserOptions { - readonly mediaType: string; - readonly parsers: Array; - readonly parserOpts: Record; + mediaType: string; + parsers: Array; + parserOpts: Record; } export interface ReferenceResolveOptions { baseURI: string; - readonly resolvers: Array; - readonly resolverOpts: Record; - readonly strategies: Array; - readonly external: boolean; - readonly maxDepth: number; + resolvers: Array; + resolverOpts: Record; + strategies: Array; + external: boolean; + maxDepth: number; } export interface ReferenceDereferenceOptions { - readonly strategies: Array; - readonly refSet: null | ReferenceSet; - readonly maxDepth: number; + strategies: Array; + refSet: null | ReferenceSet; + maxDepth: number; } export interface ReferenceOptions { diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/bootstrap.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/bootstrap.ts new file mode 100644 index 0000000000..32b10e58ad --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/bootstrap.ts @@ -0,0 +1,51 @@ +// @ts-ignore +import SwaggerClient from 'swagger-client'; + +import options from '../../../../src/options'; +import JsonParser from './helpers/parsers/json'; +import YamlParser from './helpers/parsers/yaml1-2'; +import OpenApiJson3_1Parser from './helpers/parsers/openapi-json-3-1'; +import OpenApiYaml3_1Parser from './helpers/parsers/openapi-yaml-3-1'; +import HttpResolverSwaggerClient from '../../../../src/resolve/resolvers/HttpResolverSwaggerClient'; + +const originalParsers = [...options.parse.parsers]; +const originalResolvers = [...options.resolve.resolvers]; + +export const before = () => { + // configure custom parser plugins globally + options.parse.parsers = options.parse.parsers.map((parser) => { + // @ts-ignore + if (parser.name === 'json') { + return JsonParser({ allowEmpty: true, sourceMap: false }); + } + // @ts-ignore + if (parser.name === 'yaml-1-2') { + return YamlParser({ allowEmpty: true, sourceMap: false }); + } + // @ts-ignore + if (parser.name === 'openapi-json-3-1') { + return OpenApiJson3_1Parser({ allowEmpty: true, sourceMap: false }); + } + // @ts-ignore + if (parser.name === 'openapi-yaml-3-1') { + return OpenApiYaml3_1Parser({ allowEmpty: true, sourceMap: false }); + } + + return parser; + }); + + // configure custom resolver plugins globally + options.resolve.resolvers = options.resolve.resolvers.map((resolver) => { + // @ts-ignore + if (resolver.name === 'http-axios') { + return HttpResolverSwaggerClient({ swaggerHTTPClient: SwaggerClient.http }); + } + + return resolver; + }); +}; + +export const after = () => { + options.parse.parsers = originalParsers; + options.resolve.resolvers = originalResolvers; +}; diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/components-callbacks/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/components-callbacks/dereferenced.json new file mode 100644 index 0000000000..4c753eb15c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/components-callbacks/dereferenced.json @@ -0,0 +1,19 @@ +[ + { + "openapi": "3.1.0", + "components": { + "callbacks": { + "callback1": { + "{$method}": { + "description": "description of callback2" + } + }, + "callback2": { + "{$method}": { + "description": "description of callback2" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/components-callbacks/root.yaml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/components-callbacks/root.yaml new file mode 100644 index 0000000000..93fff754fe --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/components-callbacks/root.yaml @@ -0,0 +1,9 @@ +--- +openapi: 3.1.0 +components: + callbacks: + callback1: + "$ref": "#/components/callbacks/callback2" + callback2: + "{$method}": + description: description of callback2 diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/operation-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/operation-object/dereferenced.json new file mode 100644 index 0000000000..9bdc71acaf --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/operation-object/dereferenced.json @@ -0,0 +1,27 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "callbacks": { + "callback": { + "{$method}": { + "description": "description of callback2" + } + } + } + } + } + }, + "components": { + "callbacks": { + "callback": { + "{$method}": { + "description": "description of callback2" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/operation-object/root.yaml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/operation-object/root.yaml new file mode 100644 index 0000000000..0c9162d0f1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/fixtures/operation-object/root.yaml @@ -0,0 +1,13 @@ +--- +openapi: 3.1.0 +paths: + "/path": + get: + callbacks: + callback: + "$ref": "#/components/callbacks/callback" +components: + callbacks: + callback: + "{$method}": + description: description of callback2 diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/index.ts new file mode 100644 index 0000000000..2161c13d59 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-object/index.ts @@ -0,0 +1,54 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Callback Object', function () { + context('given in components/callbacks field', function () { + const fixturePath = path.join(rootFixturePath, 'components-callbacks'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.yaml'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('yaml') }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given in Operation Object', function () { + const fixturePath = path.join(rootFixturePath, 'operation-object'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.yaml'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('yaml') }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/dereference-apidom.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/dereference-apidom.ts new file mode 100644 index 0000000000..54d1b2e84c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/dereference-apidom.ts @@ -0,0 +1,67 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { + mediaTypes, + ExampleElement, + isExampleElement, + OpenApi3_1Element, +} from '@swagger-api/apidom-ns-openapi-3-1'; +import { evaluate } from '@swagger-api/apidom-json-pointer'; + +import * as bootstrap from '../bootstrap'; +import { parse, dereferenceApiDOM } from '../../../../../src'; + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Example Object', function () { + context('given single ExampleElement passed to dereferenceApiDOM', function () { + const fixturePath = path.join(__dirname, 'fixtures', 'external-value-json', 'root.json'); + + specify('should dereference', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const exampleElement = evaluate( + '/components/examples/example1', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(exampleElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + }); + + assert.isTrue(isExampleElement(dereferenced)); + }); + + specify('should dereference and contain metadata about origin', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const exampleElement = evaluate( + '/components/examples/example1', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = (await dereferenceApiDOM(exampleElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + })) as ExampleElement; + + assert.match( + dereferenced.value?.meta.get('ref-origin').toValue(), + /external-value-json\/ex\.json$/, + ); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/components-examples/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/components-examples/dereferenced.json new file mode 100644 index 0000000000..810362c752 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/components-examples/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "value": 1 + }, + "example2": { + "description": "example1 description", + "value": 1 + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/components-examples/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/components-examples/root.json new file mode 100644 index 0000000000..d7f47b7b3a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/components-examples/root.json @@ -0,0 +1,14 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "value": 1 + }, + "example2": { + "$ref": "#/components/examples/example1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/dereferenced.json new file mode 100644 index 0000000000..6390964608 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/dereferenced.json @@ -0,0 +1,14 @@ +[ + { + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "value": "AAABAAMAEBAAAAEAIABoBAAANgAAACAgAAABACAAKBEAAJ4EAAAwMAAAAQAgAGgmAADGFQAAKAAAABAAAAAgAAAAAQAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOPj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/9PT0/+np6f/rq6u/+Pj4//j4+P/zMzM/8vLy//g4OD/4+Pj/+Pj4//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+Pj4/+0tLT/NTU1/0tLS//j4+P/4+P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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==", + "externalValue": "./favicon.ico" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/favicon.ico b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/favicon.ico new file mode 100644 index 0000000000..4ffa222883 Binary files /dev/null and b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/favicon.ico differ diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/root.json new file mode 100644 index 0000000000..8179437c62 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "externalValue": "./favicon.ico" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/dereferenced.json new file mode 100644 index 0000000000..c04d231350 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/dereferenced.json @@ -0,0 +1,13 @@ +[ + { + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "externalValue": "./ex.json" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/ex.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/ex.json @@ -0,0 +1 @@ +{} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/root.json new file mode 100644 index 0000000000..2c2d58d639 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "externalValue": "./ex.json" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/dereferenced.json new file mode 100644 index 0000000000..a5cff2bc14 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "value": { + "prop1": "value1", + "prop2": "value2" + }, + "externalValue": "./ex.json" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/ex.json new file mode 100644 index 0000000000..6fb8855f8a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/ex.json @@ -0,0 +1,4 @@ +{ + "prop1": "value1", + "prop2": "value2" +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/root.json new file mode 100644 index 0000000000..2c2d58d639 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "externalValue": "./ex.json" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/dereferenced.json new file mode 100644 index 0000000000..eae84b99b7 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "value": { + "prop1": "value1", + "prop2": "value2" + }, + "externalValue": "./ex.json#/json/pointer" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/ex.json new file mode 100644 index 0000000000..6fb8855f8a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/ex.json @@ -0,0 +1,4 @@ +{ + "prop1": "value1", + "prop2": "value2" +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/root.json new file mode 100644 index 0000000000..e5e5883e48 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-pointer/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "externalValue": "./ex.json#/json/pointer" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/dereferenced.json new file mode 100644 index 0000000000..ce48fb16f1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/dereferenced.json @@ -0,0 +1,14 @@ +[ + { + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "value": "dmFsMTt2YWwyO3ZhbDMK", + "externalValue": "./ex.csv" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/ex.csv b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/ex.csv new file mode 100644 index 0000000000..afd194d0e1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/ex.csv @@ -0,0 +1 @@ +val1;val2;val3 diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/root.json new file mode 100644 index 0000000000..fb347a7767 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-text/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "externalValue": "./ex.csv" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-unresolvable/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-unresolvable/root.json new file mode 100644 index 0000000000..2c2d58d639 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-unresolvable/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "externalValue": "./ex.json" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-value-both-defined/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-value-both-defined/ex.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-value-both-defined/ex.json @@ -0,0 +1 @@ +{} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-value-both-defined/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-value-both-defined/root.json new file mode 100644 index 0000000000..a63d5e606f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-value-both-defined/root.json @@ -0,0 +1,12 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "value": "sample value", + "externalValue": "./ex.json" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/dereferenced.json new file mode 100644 index 0000000000..1ad8645745 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "value": { + "prop1": "value1", + "prop2": "value2" + }, + "externalValue": "./ex.yaml" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/ex.yaml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/ex.yaml new file mode 100644 index 0000000000..95d4e79f9c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/ex.yaml @@ -0,0 +1,3 @@ +--- +prop1: value1 +prop2: value2 diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/root.json new file mode 100644 index 0000000000..54aa18bb2f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-yaml/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "examples": { + "example1": { + "description": "example1 description", + "externalValue": "./ex.yaml" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/media-type-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/media-type-object/dereferenced.json new file mode 100644 index 0000000000..393ed725de --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/media-type-object/dereferenced.json @@ -0,0 +1,31 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "responses": { + "201": { + "content": { + "application/json": { + "examples": { + "example1": { + "description": "example 2 description" + } + } + } + } + } + } + } + } + }, + "components": { + "examples": { + "example2": { + "description": "example 2 description" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/media-type-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/media-type-object/root.json new file mode 100644 index 0000000000..d1b8222953 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/media-type-object/root.json @@ -0,0 +1,29 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "responses": { + "201": { + "content": { + "application/json": { + "examples": { + "example1": { + "$ref": "#/components/examples/example2" + } + } + } + } + } + } + } + } + }, + "components": { + "examples": { + "example2": { + "description": "example 2 description" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/parameter-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/parameter-object/dereferenced.json new file mode 100644 index 0000000000..27d46beaae --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/parameter-object/dereferenced.json @@ -0,0 +1,24 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true, + "examples": { + "example1": { + "description": "example 2 description" + } + } + } + }, + "examples": { + "example2": { + "description": "example 2 description" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/parameter-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/parameter-object/root.json new file mode 100644 index 0000000000..1ba502d046 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/fixtures/parameter-object/root.json @@ -0,0 +1,22 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true, + "examples": { + "example1": { + "$ref": "#/components/examples/example2" + } + } + } + }, + "examples": { + "example2": { + "description": "example 2 description" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/index.ts new file mode 100644 index 0000000000..b713dcd2a4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/example-object/index.ts @@ -0,0 +1,194 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import { DereferenceError } from '../../../../../src/util/errors'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Example Object', function () { + context('given in components/examples field', function () { + const fixturePath = path.join(rootFixturePath, 'components-examples'); + + 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 Parameter Object', function () { + const fixturePath = path.join(rootFixturePath, 'parameter-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 Media Type Object', function () { + const fixturePath = path.join(rootFixturePath, 'media-type-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 externalValue field', function () { + context('and pointing to a JSON file', function () { + const fixturePath = path.join(rootFixturePath, 'external-value-json'); + + 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('and pointing to a JSON file and having JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'external-value-pointer'); + + 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('and pointing to a YAML file', function () { + const fixturePath = path.join(rootFixturePath, 'external-value-yaml'); + + 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('and pointing to a text file', function () { + const fixturePath = path.join(rootFixturePath, 'external-value-text'); + + 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('and pointing to a binary file', function () { + const fixturePath = path.join(rootFixturePath, 'external-value-binary'); + + 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('and with unresolvable URI', function () { + const fixturePath = path.join(rootFixturePath, 'external-value-unresolvable'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('with external resolution disabled', function () { + const fixturePath = path.join(rootFixturePath, 'external-value-ignore-external'); + + specify('should not dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { external: false }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given both value and externalValue fields are defined', function () { + const fixturePath = path.join(rootFixturePath, 'external-value-value-both-defined'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (error: any) { + assert.strictEqual( + error.cause.cause.message, + 'ExampleElement value and externalValue fields are mutually exclusive.', + ); + assert.instanceOf(error, DereferenceError); + } + }); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/components-headers/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/components-headers/dereferenced.json new file mode 100644 index 0000000000..83fecb62ce --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/components-headers/dereferenced.json @@ -0,0 +1,15 @@ +[ + { + "openapi": "3.1.0", + "components": { + "headers": { + "content-type": { + "description": "content type header description" + }, + "x-custom-header": { + "description": "content type header description" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/components-headers/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/components-headers/root.json new file mode 100644 index 0000000000..fe69f04fea --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/components-headers/root.json @@ -0,0 +1,13 @@ +{ + "openapi": "3.1.0", + "components": { + "headers": { + "content-type": { + "description": "content type header description" + }, + "x-custom-header": { + "$ref": "#/components/headers/content-type" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/encoding-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/encoding-object/dereferenced.json new file mode 100644 index 0000000000..33a788b7fe --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/encoding-object/dereferenced.json @@ -0,0 +1,32 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true, + "content": { + "encoding": { + "Encoding": { + "headers": { + "content-type": { + "$ref": "#/components/headers/content-type" + } + } + } + } + } + } + }, + "components": { + "headers": { + "content-type": { + "description": "content type header description" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/encoding-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/encoding-object/root.json new file mode 100644 index 0000000000..e3d771e9e6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/encoding-object/root.json @@ -0,0 +1,30 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true, + "content": { + "encoding": { + "Encoding": { + "headers": { + "content-type": { + "$ref": "#/components/headers/content-type" + } + } + } + } + } + } + }, + "components": { + "headers": { + "content-type": { + "description": "content type header description" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/response-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/response-object/dereferenced.json new file mode 100644 index 0000000000..ddf6b31709 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/response-object/dereferenced.json @@ -0,0 +1,21 @@ +[ + { + "openapi": "3.1.0", + "components": { + "responses": { + "default": { + "headers": { + "content-type": { + "description": "content type header description" + } + } + } + }, + "headers": { + "content-type": { + "description": "content type header description" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/response-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/response-object/root.json new file mode 100644 index 0000000000..c41ada395a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/fixtures/response-object/root.json @@ -0,0 +1,19 @@ +{ + "openapi": "3.1.0", + "components": { + "responses": { + "default": { + "headers": { + "content-type": { + "$ref": "#/components/headers/content-type" + } + } + } + }, + "headers": { + "content-type": { + "description": "content type header description" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/index.ts new file mode 100644 index 0000000000..e9659ff70b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/header-object/index.ts @@ -0,0 +1,68 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Header Object', function () { + context('given in components/headers field', function () { + const fixturePath = path.join(rootFixturePath, 'components-headers'); + + 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 Encoding Object', function () { + const fixturePath = path.join(rootFixturePath, 'encoding-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 Response Object', function () { + const fixturePath = path.join(rootFixturePath, 'response-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); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/json/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/json/index.ts index d1fdfdb7a5..844cce4f68 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/json/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/json/index.ts @@ -31,6 +31,11 @@ const JsonParser: stampit.Stamp = stampit(Parser, { return false; }, async parse(file: IFile): Promise { + if (this.sourceMap) { + // eslint-disable-next-line no-console + console.warn("json-swagger-client parser plugin doesn't support sourceMaps option"); + } + const source = file.toString(); try { diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/openapi-json-3-1/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/openapi-json-3-1/index.ts index 0070650dd5..fcaf0cce26 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/openapi-json-3-1/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/openapi-json-3-1/index.ts @@ -34,6 +34,13 @@ const OpenApiJson3_1Parser: stampit.Stamp = stampit(Parser, { return false; }, async parse(file: IFile): Promise { + if (this.sourceMap) { + // eslint-disable-next-line no-console + console.warn( + "openapi-json-3-1-swagger-client parser plugin doesn't support sourceMaps option", + ); + } + const source = file.toString(); try { diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/openapi-yaml-3-1/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/openapi-yaml-3-1/index.ts index 511480dc73..6670a289c7 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/openapi-yaml-3-1/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/openapi-yaml-3-1/index.ts @@ -36,6 +36,13 @@ const OpenApiYaml3_1Parser: stampit.Stamp = stampit(Parser, { return false; }, async parse(file: IFile): Promise { + if (this.sourceMap) { + // eslint-disable-next-line no-console + console.warn( + "openapi-yaml-3-1-swagger-client parser plugin doesn't support sourceMaps option", + ); + } + const source = file.toString(); try { diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/yaml1-2/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/yaml1-2/index.ts index 0b06b3caa9..f9c555c4ee 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/yaml1-2/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/helpers/parsers/yaml1-2/index.ts @@ -33,6 +33,11 @@ const YamlParser: stampit.Stamp = stampit(Parser, { return false; }, async parse(file: IFile): Promise { + if (this.sourceMap) { + // eslint-disable-next-line no-console + console.warn("yaml-1-2-swagger-client parser plugin doesn't support sourceMaps option"); + } + const source = file.toString(); try { diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/dereference-apidom.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/dereference-apidom.ts new file mode 100644 index 0000000000..8e48a272d0 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/dereference-apidom.ts @@ -0,0 +1,65 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { + mediaTypes, + isLinkElement, + LinkElement, + isOperationElement, + OpenApi3_1Element, +} from '@swagger-api/apidom-ns-openapi-3-1'; +import { evaluate } from '@swagger-api/apidom-json-pointer'; + +import { parse, dereferenceApiDOM } from '../../../../../src'; + +describe('dereference', function () { + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Link Object', function () { + context('given single LinkElement passed to dereferenceApiDOM', function () { + const fixturePath = path.join( + __dirname, + 'fixtures', + 'operation-ref-external', + 'root.json', + ); + + specify('should dereference', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const linkElement = evaluate( + '/components/links/link1', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = (await dereferenceApiDOM(linkElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + })) as LinkElement; + + assert.isTrue(isLinkElement(dereferenced)); + assert.isTrue(isOperationElement(dereferenced.operationRef?.meta.get('operation'))); + }); + + specify('should dereference and contain metadata about origin', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const linkElement = evaluate( + '/components/links/link1', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = (await dereferenceApiDOM(linkElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + })) as LinkElement; + + assert.match( + dereferenced.operationRef?.meta.get('operation').meta.get('ref-origin').toValue(), + /operation-ref-external\/ex\.json$/, + ); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/components-links/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/components-links/dereferenced.json new file mode 100644 index 0000000000..15e6146695 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/components-links/dereferenced.json @@ -0,0 +1,22 @@ +[ + { + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationId": "op1" + }, + "link2": { + "operationId": "op1" + } + }, + "pathItems": { + "pathItem1": { + "get": { + "operationId": "op1" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/components-links/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/components-links/root.json new file mode 100644 index 0000000000..1503044b06 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/components-links/root.json @@ -0,0 +1,20 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationId": "op1" + }, + "link2": { + "$ref": "#/components/links/link1" + } + }, + "pathItems": { + "pathItem1": { + "get": { + "operationId": "op1" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id-non-existent/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id-non-existent/root.json new file mode 100644 index 0000000000..3d24df3526 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id-non-existent/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationId": "op1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id/dereferenced.json new file mode 100644 index 0000000000..54b33ce516 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id/dereferenced.json @@ -0,0 +1,20 @@ +[ + { + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationId": "op1" + } + }, + "pathItems": { + "pathItem1": { + "get": { + "operationId": "op1", + "description": "description of operation" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id/root.json new file mode 100644 index 0000000000..45a7f2b541 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-id/root.json @@ -0,0 +1,18 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationId": "op1" + } + }, + "pathItems": { + "pathItem1": { + "get": { + "operationId": "op1", + "description": "description of operation" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/dereferenced.json new file mode 100644 index 0000000000..c8ccfd0370 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/dereferenced.json @@ -0,0 +1,12 @@ +[ + { + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "./ex.json#/operation" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/ex.json new file mode 100644 index 0000000000..3d6eb5ad85 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/ex.json @@ -0,0 +1,5 @@ +{ + "operation": { + "description": "description of operation" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/root.json new file mode 100644 index 0000000000..76e6167168 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-external/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "./ex.json#/operation" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-id-both-defined/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-id-both-defined/root.json new file mode 100644 index 0000000000..78b2af181a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-id-both-defined/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "#/components/pathItems/pathItem1/get", + "operationId": "op1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/dereferenced.json new file mode 100644 index 0000000000..c8ccfd0370 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/dereferenced.json @@ -0,0 +1,12 @@ +[ + { + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "./ex.json#/operation" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/ex.json new file mode 100644 index 0000000000..3d6eb5ad85 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/ex.json @@ -0,0 +1,5 @@ +{ + "operation": { + "description": "description of operation" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/root.json new file mode 100644 index 0000000000..76e6167168 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-ignore-external/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "./ex.json#/operation" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-internal/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-internal/dereferenced.json new file mode 100644 index 0000000000..11d3b1a74f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-internal/dereferenced.json @@ -0,0 +1,19 @@ +[ + { + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "#/components/pathItems/pathItem1/get" + } + }, + "pathItems": { + "pathItem1": { + "get": { + "description": "description of operation" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-internal/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-internal/root.json new file mode 100644 index 0000000000..e91b65104d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-internal/root.json @@ -0,0 +1,17 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "#/components/pathItems/pathItem1/get" + } + }, + "pathItems": { + "pathItem1": { + "get": { + "description": "description of operation" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-invalid-pointer/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-invalid-pointer/root.json new file mode 100644 index 0000000000..2da69bb325 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-invalid-pointer/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "invalid-pointer" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-unresolvable/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-unresolvable/root.json new file mode 100644 index 0000000000..3b24ce87df --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/operation-ref-unresolvable/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "links": { + "link1": { + "operationRef": "#/components/invalid-pointer" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/response-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/response-object/dereferenced.json new file mode 100644 index 0000000000..de73b5e73c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/response-object/dereferenced.json @@ -0,0 +1,29 @@ +[ + { + "openapi": "3.1.0", + "components": { + "responses": { + "201": { + "description": "201 description", + "links": { + "link": { + "operationId": "op1" + } + } + } + }, + "links": { + "link1": { + "operationId": "op1" + } + }, + "pathItems": { + "pathItem1": { + "get": { + "operationId": "op1" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/response-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/response-object/root.json new file mode 100644 index 0000000000..40cebbda47 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/fixtures/response-object/root.json @@ -0,0 +1,27 @@ +{ + "openapi": "3.1.0", + "components": { + "responses": { + "201": { + "description": "201 description", + "links": { + "link": { + "$ref": "#/components/links/link1" + } + } + } + }, + "links": { + "link1": { + "operationId": "op1" + } + }, + "pathItems": { + "pathItem1": { + "get": { + "operationId": "op1" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/index.ts new file mode 100644 index 0000000000..88667108d7 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/link-object/index.ts @@ -0,0 +1,270 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { isOperationElement, LinkElement, mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; +import { evaluate } from '@swagger-api/apidom-json-pointer'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import { DereferenceError } from '../../../../../src/util/errors'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Link Object', function () { + context('given in components/links field', function () { + const fixturePath = path.join(rootFixturePath, 'components-links'); + + 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); + }); + + specify( + 'should set Operation Object as metadata of Link.operationId field', + async function () { + 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) as LinkElement; + const link2 = evaluate('/0/components/links/link2', dereferenced) as LinkElement; + + assert.isTrue(isOperationElement(link1.operationId?.meta.get('operation'))); + assert.isTrue(isOperationElement(link2.operationId?.meta.get('operation'))); + }, + ); + }); + + context('given in Response Object', function () { + const fixturePath = path.join(rootFixturePath, 'response-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); + }); + + specify( + 'should set Operation Object as metadata of Link.operationId field', + async function () { + 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, + ) as LinkElement; + const link2 = evaluate('/0/components/links/link1', dereferenced) as LinkElement; + + assert.isTrue(isOperationElement(link1.operationId?.meta.get('operation'))); + assert.isTrue(isOperationElement(link2.operationId?.meta.get('operation'))); + }, + ); + }); + + context('given operationRef field', function () { + context('and with internal JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'operation-ref-internal'); + + 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); + }); + + specify( + 'should set Operation Object as metadata of Link.operationRef field', + async function () { + 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) as LinkElement; + + assert.isTrue(isOperationElement(link1.operationRef?.meta.get('operation'))); + }, + ); + }); + + context('and with external JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'operation-ref-external'); + const rootFilePath = path.join(fixturePath, 'root.json'); + + specify('should dereference', async function () { + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + + specify('should apply semantics to external fragment', async function () { + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + + assert.isTrue( + // @ts-ignore + isOperationElement(dereferenced.api.components.links.get('link1').operation), + ); + }); + + specify( + 'should set Operation Object as metadata of Link.operationRef field', + async function () { + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const link1 = evaluate('/0/components/links/link1', dereferenced) as LinkElement; + + assert.isTrue(isOperationElement(link1.operationRef?.meta.get('operation'))); + }, + ); + }); + + context('with external resolution disabled', function () { + const fixturePath = path.join(rootFixturePath, 'operation-ref-ignore-external'); + + specify('should not dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { external: false }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('and with invalid JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'operation-ref-invalid-pointer'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('and with unresolvable JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'operation-ref-unresolvable'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + }); + + context('given operationId field', function () { + context('and OperationElement with operationId exists', async function () { + const fixturePath = path.join(rootFixturePath, 'operation-id'); + const rootFilePath = path.join(fixturePath, 'root.json'); + + specify('should dereference', async function () { + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + + specify( + 'should set Operation Object as metadata of Link.operationId field', + async function () { + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const link1 = evaluate('/0/components/links/link1', dereferenced) as LinkElement; + + assert.isTrue(isOperationElement(link1.operationId?.meta.get('operation'))); + }, + ); + }); + + context("and OperationElement with operationId doesn't exist", async function () { + const fixturePath = path.join(rootFixturePath, 'operation-id-non-existent'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + }); + + context('given both operationRef and operationId fields are defined', function () { + const fixturePath = path.join(rootFixturePath, 'operation-ref-id-both-defined'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (error: any) { + assert.strictEqual( + error.cause.cause.message, + 'LinkElement operationRef and operationId fields are mutually exclusive.', + ); + assert.instanceOf(error, DereferenceError); + } + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/components-parameters/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/components-parameters/dereferenced.json new file mode 100644 index 0000000000..2c916faa64 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/components-parameters/dereferenced.json @@ -0,0 +1,19 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + }, + "param2": { + "name": "offset", + "in": "query", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/components-parameters/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/components-parameters/root.json new file mode 100644 index 0000000000..e6601b6f18 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/components-parameters/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + }, + "param2": { + "$ref": "#/components/parameters/param1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/operation-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/operation-object/dereferenced.json new file mode 100644 index 0000000000..e9fe33b1bf --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/operation-object/dereferenced.json @@ -0,0 +1,27 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "parameters": [ + { + "name": "offset", + "in": "query", + "required": true + } + ] + } + } + }, + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/operation-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/operation-object/root.json new file mode 100644 index 0000000000..f17d04e46b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/operation-object/root.json @@ -0,0 +1,23 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "parameters": [ + { + "$ref": "#/components/parameters/param1" + } + ] + } + } + }, + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/path-item-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/path-item-object/dereferenced.json new file mode 100644 index 0000000000..7258f817b0 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/path-item-object/dereferenced.json @@ -0,0 +1,25 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path": { + "parameters": [ + { + "name": "offset", + "in": "query", + "required": true + } + ] + } + }, + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/path-item-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/path-item-object/root.json new file mode 100644 index 0000000000..280da6ecde --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/fixtures/path-item-object/root.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path": { + "parameters": [ + { + "$ref": "#/components/parameters/param1" + } + ] + } + }, + "components": { + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/index.ts new file mode 100644 index 0000000000..d071b7b6cc --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/parameter-object/index.ts @@ -0,0 +1,68 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Parameter Object', function () { + context('given in components/parameters field', function () { + const fixturePath = path.join(rootFixturePath, 'components-parameters'); + + 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 Path Item Object', function () { + const fixturePath = path.join(rootFixturePath, 'path-item-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 Operation Object', function () { + const fixturePath = path.join(rootFixturePath, 'operation-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); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/dereference-apidom.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/dereference-apidom.ts new file mode 100644 index 0000000000..0fc25a4656 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/dereference-apidom.ts @@ -0,0 +1,63 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { + mediaTypes, + isPathItemElement, + OpenApi3_1Element, +} from '@swagger-api/apidom-ns-openapi-3-1'; +import { evaluate, compile } from '@swagger-api/apidom-json-pointer'; + +import { parse, dereferenceApiDOM } from '../../../../../src'; +import * as bootstrap from '../bootstrap'; + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Path Item Object', function () { + context('given single PathItemElement passed to dereferenceApiDOM', function () { + const fixturePath = path.join(__dirname, 'fixtures', 'external-only', 'root.json'); + + specify('should dereference', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const pathItemElement = evaluate( + compile(['paths', '/path1']), + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(pathItemElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + }); + + assert.isTrue(isPathItemElement(dereferenced)); + }); + + specify('should dereference and contain metadata about origin', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const pathItemElement = evaluate( + compile(['paths', '/path1']), + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(pathItemElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + }); + + assert.match(dereferenced.meta.get('ref-origin').toValue(), /external-only\/ex\.json$/); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/additional-fields/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/additional-fields/dereferenced.json new file mode 100644 index 0000000000..3d0e6b4ed1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/additional-fields/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path1": { + "summary": "path1 item summary", + "description": "path item description", + "get": {} + }, + "/path2": { + "summary": "path2 item summary", + "description": "path item description", + "get": {} + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/additional-fields/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/additional-fields/root.json new file mode 100644 index 0000000000..a49cbf0e5f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/additional-fields/root.json @@ -0,0 +1,14 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "#/paths/~1path2", + "summary": "path1 item summary" + }, + "/path2": { + "summary": "path2 item summary", + "description": "path item description", + "get": {} + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/callback-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/callback-object/dereferenced.json new file mode 100644 index 0000000000..4c753eb15c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/callback-object/dereferenced.json @@ -0,0 +1,19 @@ +[ + { + "openapi": "3.1.0", + "components": { + "callbacks": { + "callback1": { + "{$method}": { + "description": "description of callback2" + } + }, + "callback2": { + "{$method}": { + "description": "description of callback2" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/callback-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/callback-object/root.json new file mode 100644 index 0000000000..20b09ffb6b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/callback-object/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "components": { + "callbacks": { + "callback1": { + "$ref": "#/components/callbacks/callback2" + }, + "callback2": { + "{$method}": { + "description": "description of callback2" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/components-path-items/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/components-path-items/dereferenced.json new file mode 100644 index 0000000000..b254953a38 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/components-path-items/dereferenced.json @@ -0,0 +1,15 @@ +[ + { + "openapi": "3.1.0", + "components": { + "pathItems": { + "pathItem1": { + "description": "description of path item 1" + }, + "pathItem2": { + "description": "description of path item 1" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/components-path-items/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/components-path-items/root.json new file mode 100644 index 0000000000..6c51ddca2c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/components-path-items/root.json @@ -0,0 +1,13 @@ +{ + "openapi": "3.1.0", + "components": { + "pathItems": { + "pathItem1": { + "description": "description of path item 1" + }, + "pathItem2": { + "$ref": "#/components/pathItems/pathItem1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-external-circular/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-external-circular/ex.json new file mode 100644 index 0000000000..4d55709987 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-external-circular/ex.json @@ -0,0 +1,3 @@ +{ + "$ref": "./root.json#/paths/~1path1" +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-external-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-external-circular/root.json new file mode 100644 index 0000000000..7850ce66b6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-external-circular/root.json @@ -0,0 +1,8 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "./ex.json" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-internal-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-internal-circular/root.json new file mode 100644 index 0000000000..c727e272f0 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/direct-internal-circular/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "#/paths/~1path2" + }, + "/path2": { + "$ref": "#/paths/~1path1" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/dereferenced.json new file mode 100644 index 0000000000..8f02538ef6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/dereferenced.json @@ -0,0 +1,12 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path1": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/ex1.json new file mode 100644 index 0000000000..d7b3e3be55 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/ex1.json @@ -0,0 +1,3 @@ +{ + "$ref": "./ex2.json#/~1path3" +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/ex2.json new file mode 100644 index 0000000000..e6d9558407 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/ex2.json @@ -0,0 +1,7 @@ +{ + "/path3": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/root.json new file mode 100644 index 0000000000..5557004334 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-indirections/root.json @@ -0,0 +1,8 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "./ex1.json" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/dereferenced.json new file mode 100644 index 0000000000..8f02538ef6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/dereferenced.json @@ -0,0 +1,12 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path1": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/ex.json new file mode 100644 index 0000000000..da09224581 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/ex.json @@ -0,0 +1,7 @@ +{ + "/path2": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/root.json new file mode 100644 index 0000000000..5843b01245 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/external-only/root.json @@ -0,0 +1,8 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "./ex.json#/~1path2" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/dereferenced.json new file mode 100644 index 0000000000..dde8e5a6a8 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/dereferenced.json @@ -0,0 +1,10 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "./ex.json#/~1path2" + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/ex.json new file mode 100644 index 0000000000..da09224581 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/ex.json @@ -0,0 +1,7 @@ +{ + "/path2": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/root.json new file mode 100644 index 0000000000..5843b01245 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/ignore-external/root.json @@ -0,0 +1,8 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "./ex.json#/~1path2" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/ex1.json new file mode 100644 index 0000000000..8e49d4768f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/ex1.json @@ -0,0 +1,3 @@ +{ + "$ref": "./ex2.json" +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/ex2.json new file mode 100644 index 0000000000..4d55709987 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/ex2.json @@ -0,0 +1,3 @@ +{ + "$ref": "./root.json#/paths/~1path1" +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/root.json new file mode 100644 index 0000000000..5557004334 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-external-circular/root.json @@ -0,0 +1,8 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "./ex1.json" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-internal-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-internal-circular/root.json new file mode 100644 index 0000000000..16c0928aa1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/indirect-internal-circular/root.json @@ -0,0 +1,14 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "#/paths/~1path2" + }, + "/path2": { + "$ref": "#/paths/~1path3" + }, + "/path3": { + "$ref": "#/paths/~1path1" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/dereferenced.json new file mode 100644 index 0000000000..a84c3aa600 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/dereferenced.json @@ -0,0 +1,22 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path1": { + "summary": "path item summary", + "description": "path item description", + "get": {} + }, + "/path3": { + "summary": "path item summary", + "description": "path item description", + "get": {} + }, + "/path4": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/ex.json new file mode 100644 index 0000000000..da09224581 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/ex.json @@ -0,0 +1,7 @@ +{ + "/path2": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/root.json new file mode 100644 index 0000000000..71d688c0be --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-external/root.json @@ -0,0 +1,16 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "./ex.json#/~1path2" + }, + "/path3": { + "$ref": "#/paths/~1path4" + }, + "/path4": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-indirections/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-indirections/dereferenced.json new file mode 100644 index 0000000000..417a402ed3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-indirections/dereferenced.json @@ -0,0 +1,22 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path1": { + "summary": "path item summary", + "description": "path item description", + "get": {} + }, + "/path2": { + "summary": "path item summary", + "description": "path item description", + "get": {} + }, + "/path3": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-indirections/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-indirections/root.json new file mode 100644 index 0000000000..bf154cb3e5 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-indirections/root.json @@ -0,0 +1,16 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "#/paths/~1path2" + }, + "/path2": { + "$ref": "#/paths/~1path3" + }, + "/path3": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-only/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-only/dereferenced.json new file mode 100644 index 0000000000..f45de7e5c3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-only/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path1": { + "summary": "path item summary", + "description": "path item description", + "get": {} + }, + "/path2": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-only/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-only/root.json new file mode 100644 index 0000000000..12fe95541e --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/internal-only/root.json @@ -0,0 +1,13 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "#/paths/~1path2" + }, + "/path2": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/invalid-pointer/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/invalid-pointer/root.json new file mode 100644 index 0000000000..8d4df81c5d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/invalid-pointer/root.json @@ -0,0 +1,13 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "invalid-pointer" + }, + "/path2": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/ex1.json new file mode 100644 index 0000000000..d7b3e3be55 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/ex1.json @@ -0,0 +1,3 @@ +{ + "$ref": "./ex2.json#/~1path3" +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/ex2.json new file mode 100644 index 0000000000..e6d9558407 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/ex2.json @@ -0,0 +1,7 @@ +{ + "/path3": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/root.json new file mode 100644 index 0000000000..5557004334 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/max-depth/root.json @@ -0,0 +1,8 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "./ex1.json" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/unresolvable-path-item/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/unresolvable-path-item/root.json new file mode 100644 index 0000000000..1f7c6dcf9b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/unresolvable-path-item/root.json @@ -0,0 +1,13 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path1": { + "$ref": "#/paths/invalid-pointer" + }, + "/path2": { + "summary": "path item summary", + "description": "path item description", + "get": {} + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/webhooks/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/webhooks/dereferenced.json new file mode 100644 index 0000000000..bda44d5d11 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/webhooks/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "openapi": "3.1.0", + "webhooks": { + "hook": { + "description": "description of path item 1" + } + }, + "components": { + "pathItems": { + "pathItem1": { + "description": "description of path item 1" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/webhooks/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/webhooks/root.json new file mode 100644 index 0000000000..569afa66cc --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/fixtures/webhooks/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "webhooks": { + "hook": { + "$ref": "#/components/pathItems/pathItem1" + } + }, + "components": { + "pathItems": { + "pathItem1": { + "description": "description of path item 1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/index.ts new file mode 100644 index 0000000000..43f2def4c3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/path-item-object/index.ts @@ -0,0 +1,292 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import { DereferenceError, MaximumDereferenceDepthError } from '../../../../../src/util/errors'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Path Item Object', function () { + context('given in webhooks field', function () { + const fixturePath = path.join(rootFixturePath, 'webhooks'); + + 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/pathItems field', function () { + const fixturePath = path.join(rootFixturePath, 'components-path-items'); + + 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 Callback Object', function () { + const fixturePath = path.join(rootFixturePath, 'callback-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 Path Item Object $ref field', function () { + context('given $ref field pointing internally only', function () { + const fixturePath = path.join(rootFixturePath, 'internal-only'); + + 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 $ref field pointing externally only', function () { + const fixturePath = path.join(rootFixturePath, 'external-only'); + + 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 $ref field pointing internally and externally', function () { + const fixturePath = path.join(rootFixturePath, 'internal-external'); + + 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 $ref field + additional fields', function () { + const fixturePath = path.join(rootFixturePath, 'additional-fields'); + + 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 external resolution disabled', function () { + const fixturePath = path.join(rootFixturePath, 'ignore-external'); + + specify('should not dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { external: false }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given $ref field pointing to internal indirection', function () { + const fixturePath = path.join(rootFixturePath, 'internal-indirections'); + + 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 $ref field pointing to external indirections', function () { + const fixturePath = path.join(rootFixturePath, 'external-indirections'); + + 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 $ref field with invalid JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'invalid-pointer'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given $ref field and maxDepth of dereference', function () { + const fixturePath = path.join(rootFixturePath, 'max-depth'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + dereference: { maxDepth: 1 }, + }); + assert.fail('should throw MaximumDereferenceDepthError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, MaximumDereferenceDepthError); + assert.match(error.cause.cause.message, /fixtures\/max-depth\/ex1.json"$/); + } + }); + }); + + context('given $ref field with unresolvable JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'unresolvable-path-item'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given $ref field with with direct circular internal reference', function () { + const fixturePath = path.join(rootFixturePath, 'direct-internal-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given $ref field with with indirect circular internal reference', function () { + const fixturePath = path.join(rootFixturePath, 'indirect-internal-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given $ref field with with direct circular external reference', function () { + const fixturePath = path.join(rootFixturePath, 'direct-external-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given $ref field with with indirect circular external reference', function () { + const fixturePath = path.join(rootFixturePath, 'indirect-external-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/dereference-apidom.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/dereference-apidom.ts new file mode 100644 index 0000000000..7978ededdf --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/dereference-apidom.ts @@ -0,0 +1,168 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { + mediaTypes, + isParameterElement, + OpenApi3_1Element, +} from '@swagger-api/apidom-ns-openapi-3-1'; +import { evaluate } from '@swagger-api/apidom-json-pointer'; + +import { parse, dereferenceApiDOM } from '../../../../../src'; +import { ServerTerminable, createHTTPServer } from '../../../../helpers'; +import * as bootstrap from '../bootstrap'; + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Reference Object', function () { + context('given single ReferenceElement passed to dereferenceApiDOM', function () { + context('given dereferencing using local file system', function () { + const fixturePath = path.join(__dirname, 'fixtures', 'external-only', 'root.json'); + + specify('should dereference', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const referenceElement = evaluate( + '/components/parameters/externalRef', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(referenceElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + }); + + assert.isTrue(isParameterElement(dereferenced)); + }); + + specify('should dereference and contain metadata about origin', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const referenceElement = evaluate( + '/components/parameters/externalRef', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(referenceElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + }); + + assert.match( + dereferenced.meta.get('ref-origin').toValue(), + /external-only\/ex\.json$/, + ); + }); + }); + + context('given dereferencing using HTTP protocol', function () { + const fixturePath = path.join(__dirname, 'fixtures', 'external-only', 'root.json'); + const httpPort = 8123; + let httpServer: ServerTerminable; + + beforeEach(function () { + const cwd = path.join(__dirname, 'fixtures', 'external-only'); + httpServer = createHTTPServer({ port: httpPort, cwd }); + }); + + afterEach(async function () { + await httpServer.terminate(); + }); + + specify('should dereference', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const referenceElement = evaluate( + '/components/parameters/externalRef', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(referenceElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: `http://localhost:${httpPort}/root.json` }, + }); + + assert.isTrue(isParameterElement(dereferenced)); + }); + + specify('should dereference and contain metadata about origin', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const referenceElement = evaluate( + '/components/parameters/externalRef', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(referenceElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: `http://localhost:${httpPort}/root.json` }, + }); + + assert.match(dereferenced.meta.get('ref-origin').toValue(), /\/ex\.json$/); + }); + }); + + context('given dereferencing using HTTP protocol and absolute URLs', function () { + const fixturePath = path.join( + __dirname, + 'fixtures', + 'external-only-absolute-url', + 'root.json', + ); + const httpPort = 8123; + let httpServer: ServerTerminable; + + beforeEach(function () { + const cwd = path.join(__dirname, 'fixtures', 'external-only-absolute-url'); + httpServer = createHTTPServer({ port: httpPort, cwd }); + }); + + afterEach(async function () { + await httpServer.terminate(); + }); + + specify('should dereference', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const referenceElement = evaluate( + '/components/parameters/externalRef', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(referenceElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: `http://localhost:${httpPort}/root.json` }, + }); + + assert.isTrue(isParameterElement(dereferenced)); + }); + + specify('should dereference and contain metadata about origin', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const referenceElement = evaluate( + '/components/parameters/externalRef', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(referenceElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: `http://localhost:${httpPort}/root.json` }, + }); + + assert.match(dereferenced.meta.get('ref-origin').toValue(), /\/ex\.json$/); + }); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/dereferenced.json new file mode 100644 index 0000000000..0ef1ca9975 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/dereferenced.json @@ -0,0 +1,39 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "name": "userId", + "in": "query", + "description": "description 1", + "required": true + }, + "indirection1": { + "name": "userId", + "in": "query", + "description": "indirect description 1", + "required": true + }, + "indirection2": { + "name": "userId", + "in": "query", + "description": "indirect description 1", + "required": true + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "externalRef": { + "name": "externalParameter", + "in": "query", + "description": "pulled from external source", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/ex.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/ex.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/root.json new file mode 100644 index 0000000000..eba4e6f9aa --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-fields/root.json @@ -0,0 +1,30 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "$ref": "#/components/parameters/indirection1", + "description": "description 1" + }, + "indirection1": { + "$ref": "#/components/parameters/indirection2", + "summary": "indirect summary 1" + }, + "indirection2": { + "$ref": "#/components/parameters/userIdRef", + "description": "indirect description 1", + "summary": "indirect summary 2" + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "externalRef": { + "$ref": "./ex.json#/externalParameter", + "description": "pulled from external source" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/dereferenced.json new file mode 100644 index 0000000000..0ef1ca9975 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/dereferenced.json @@ -0,0 +1,39 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "name": "userId", + "in": "query", + "description": "description 1", + "required": true + }, + "indirection1": { + "name": "userId", + "in": "query", + "description": "indirect description 1", + "required": true + }, + "indirection2": { + "name": "userId", + "in": "query", + "description": "indirect description 1", + "required": true + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "externalRef": { + "name": "externalParameter", + "in": "query", + "description": "pulled from external source", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/ex.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/ex.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/root.json new file mode 100644 index 0000000000..87f3dcb727 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/additional-ignored-fields/root.json @@ -0,0 +1,38 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "$ref": "#/components/parameters/indirection1", + "description": "description 1", + "prop1": "value1", + "prop2": "value2" + }, + "indirection1": { + "$ref": "#/components/parameters/indirection2", + "summary": "indirect summary 1", + "prop1": "value1", + "prop2": "value2" + }, + "indirection2": { + "$ref": "#/components/parameters/userIdRef", + "description": "indirect description 1", + "summary": "indirect summary 2", + "prop1": "value1", + "prop2": "value2" + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "externalRef": { + "$ref": "./ex.json#/externalParameter", + "description": "pulled from external source", + "prop1": "value1", + "prop2": "value2" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/cycle-internal/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/cycle-internal/root.json new file mode 100644 index 0000000000..badb77703d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/cycle-internal/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "parent": { + "$ref": "#/components/schemas/User" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-external-circular/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-external-circular/ex.json new file mode 100644 index 0000000000..cec551870e --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-external-circular/ex.json @@ -0,0 +1,5 @@ +{ + "externalParameter": { + "$ref": "./root.json#/components/parameters/userId" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-external-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-external-circular/root.json new file mode 100644 index 0000000000..a71015f00b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-external-circular/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex.json#/externalParameter", + "description": "another ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-internal-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-internal-circular/root.json new file mode 100644 index 0000000000..020d39aef6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/direct-internal-circular/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "$ref": "#/components/parameters/userId", + "description": "description 1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/dereferenced.json new file mode 100644 index 0000000000..c494edf8b3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/dereferenced.json @@ -0,0 +1,21 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "name": "param2", + "in": "query" + }, + "param2": { + "name": "param2", + "in": "query" + }, + "param3": { + "name": "ex-param3", + "in": "query" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/ex.json new file mode 100644 index 0000000000..2ed2b2f3f2 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/ex.json @@ -0,0 +1,17 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "$ref": "./root.json#/components/parameters/param2" + }, + "param2": { + "$ref": "./root.json#/components/parameters/param2" + }, + "param3": { + "name": "ex-param3", + "in": "query" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/root.json new file mode 100644 index 0000000000..c95d70defd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-circular-dependency/root.json @@ -0,0 +1,17 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "param1": { + "$ref": "./ex.json#/components/parameters/param1" + }, + "param2": { + "name": "param2", + "in": "query" + }, + "param3": { + "$ref": "./ex.json#/components/parameters/param3" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/dereferenced.json new file mode 100644 index 0000000000..2e51b197ae --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/dereferenced.json @@ -0,0 +1,15 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "name": "externalParameter", + "in": "query", + "description": "external ref", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex1.json new file mode 100644 index 0000000000..f46bebc5f4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex1.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex2.json#/indirection" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex2.json new file mode 100644 index 0000000000..091689f702 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex2.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex3.json#/externalParameter" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex3.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex3.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/ex3.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/root.json new file mode 100644 index 0000000000..3614c32b3c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-indirections/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex1.json#/indirection", + "description": "external ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/dereferenced.json new file mode 100644 index 0000000000..2e51b197ae --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/dereferenced.json @@ -0,0 +1,15 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "name": "externalParameter", + "in": "query", + "description": "external ref", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/ex.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/ex.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/root.json new file mode 100644 index 0000000000..ccf0893718 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only-absolute-url/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "http://localhost:8123/ex.json#/externalParameter", + "description": "external ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/dereferenced.json new file mode 100644 index 0000000000..2e51b197ae --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/dereferenced.json @@ -0,0 +1,15 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "name": "externalParameter", + "in": "query", + "description": "external ref", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/ex.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/ex.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/root.json new file mode 100644 index 0000000000..a512c01553 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/external-only/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex.json#/externalParameter", + "description": "external ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/dereferenced.json new file mode 100644 index 0000000000..736c0a6798 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/dereferenced.json @@ -0,0 +1,14 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "a": { + "$ref": "#/three" + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/ex.json new file mode 100644 index 0000000000..2e53208cfc --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/ex.json @@ -0,0 +1,15 @@ +{ + "one": { + "$ref": "#/two" + }, + "two": { + "a": { + "$ref": "#/three" + } + }, + "three": { + "b": { + "$ref": "#/two" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/root.json new file mode 100644 index 0000000000..d2127a757b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-arbitrary-$refs/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex.json#/one" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/dereferenced.json new file mode 100644 index 0000000000..995356d521 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/dereferenced.json @@ -0,0 +1,37 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "name": "userId", + "in": "query", + "description": "override", + "required": true + }, + "indirection1": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "indirection2": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "externalRef": { + "$ref": "./ex.json#/externalParameter", + "description": "another ref" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/ex.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/ex.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/root.json new file mode 100644 index 0000000000..802a6c0b39 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/ignore-external/root.json @@ -0,0 +1,29 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "$ref": "#/components/parameters/indirection1", + "description": "override" + }, + "indirection1": { + "$ref": "#/components/parameters/indirection2", + "summary": "indirect summary" + }, + "indirection2": { + "$ref": "#/components/parameters/userIdRef", + "summary": "indirect summary" + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "externalRef": { + "$ref": "./ex.json#/externalParameter", + "description": "another ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex1.json new file mode 100644 index 0000000000..f46bebc5f4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex1.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex2.json#/indirection" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex2.json new file mode 100644 index 0000000000..d44c814227 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex2.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex3.json#/indirection" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex3.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex3.json new file mode 100644 index 0000000000..92be82752c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/ex3.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./root.json#/components/parameters/externalRef" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/root.json new file mode 100644 index 0000000000..6e1a722371 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-external-circular/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex1.json#/indirection", + "description": "another ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-internal-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-internal-circular/root.json new file mode 100644 index 0000000000..58cfa384b6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/indirect-internal-circular/root.json @@ -0,0 +1,23 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "$ref": "#/components/parameters/indirection1", + "description": "description 1" + }, + "indirection1": { + "$ref": "#/components/parameters/indirection2", + "description": "description 1" + }, + "indirection2": { + "$ref": "#/components/parameters/indirection3", + "description": "description 1" + }, + "indirection3": { + "$ref": "#/components/parameters/userId", + "description": "description 1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/dereferenced.json new file mode 100644 index 0000000000..4baa2dc952 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/dereferenced.json @@ -0,0 +1,39 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "name": "userId", + "in": "query", + "description": "override", + "required": true + }, + "indirection1": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "indirection2": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "externalRef": { + "name": "externalParameter", + "in": "query", + "description": "another ref", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/ex.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/ex.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/root.json new file mode 100644 index 0000000000..802a6c0b39 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-external/root.json @@ -0,0 +1,29 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "$ref": "#/components/parameters/indirection1", + "description": "override" + }, + "indirection1": { + "$ref": "#/components/parameters/indirection2", + "summary": "indirect summary" + }, + "indirection2": { + "$ref": "#/components/parameters/userIdRef", + "summary": "indirect summary" + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "externalRef": { + "$ref": "./ex.json#/externalParameter", + "description": "another ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-only/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-only/dereferenced.json new file mode 100644 index 0000000000..b50576d2ca --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-only/dereferenced.json @@ -0,0 +1,33 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "name": "userId", + "in": "query", + "description": "override", + "required": true + }, + "indirection1": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "indirection2": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-only/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-only/root.json new file mode 100644 index 0000000000..8f824a35ef --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/internal-only/root.json @@ -0,0 +1,25 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "$ref": "#/components/parameters/indirection1", + "description": "override" + }, + "indirection1": { + "$ref": "#/components/parameters/indirection2", + "summary": "indirect summary" + }, + "indirection2": { + "$ref": "#/components/parameters/userIdRef", + "summary": "indirect summary" + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/invalid-pointer/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/invalid-pointer/root.json new file mode 100644 index 0000000000..afde294f76 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/invalid-pointer/root.json @@ -0,0 +1,17 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "userId": { + "$ref": "invalid-pointer", + "description": "override" + }, + "userIdRef": { + "name": "userId", + "in": "query", + "description": "ID of the user", + "required": true + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex1.json new file mode 100644 index 0000000000..f46bebc5f4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex1.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex2.json#/indirection" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex2.json new file mode 100644 index 0000000000..091689f702 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex2.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex3.json#/externalParameter" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex3.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex3.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/ex3.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/root.json new file mode 100644 index 0000000000..3614c32b3c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/max-depth/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex1.json#/indirection", + "description": "external ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/dereferenced.json new file mode 100644 index 0000000000..2e51b197ae --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/dereferenced.json @@ -0,0 +1,15 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "name": "externalParameter", + "in": "query", + "description": "external ref", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex1.json new file mode 100644 index 0000000000..f46bebc5f4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex1.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex2.json#/indirection" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex2.json new file mode 100644 index 0000000000..091689f702 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex2.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex3.json#/externalParameter" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex3.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex3.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/ex3.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/root.json new file mode 100644 index 0000000000..3614c32b3c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/path-encoding/path with spaces/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex1.json#/indirection", + "description": "external ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/dereferenced.json new file mode 100644 index 0000000000..2e51b197ae --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/dereferenced.json @@ -0,0 +1,15 @@ +[ + { + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "name": "externalParameter", + "in": "query", + "description": "external ref", + "required": true + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex1.json new file mode 100644 index 0000000000..f46bebc5f4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex1.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex2.json#/indirection" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex2.json new file mode 100644 index 0000000000..091689f702 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex2.json @@ -0,0 +1,5 @@ +{ + "indirection": { + "$ref": "./ex3.json#/externalParameter" + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex3.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex3.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/ex3.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/root.json new file mode 100644 index 0000000000..3614c32b3c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/refset-as-option/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex1.json#/indirection", + "description": "external ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/unresolvable-reference/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/unresolvable-reference/root.json new file mode 100644 index 0000000000..44e42d9fe4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/fixtures/unresolvable-reference/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "parameters": { + "externalRef": { + "$ref": "./ex.json#/externalParameter", + "description": "external ref" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/index.ts new file mode 100644 index 0000000000..fe423a8c3a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/reference-object/index.ts @@ -0,0 +1,416 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { ParseResultElement, toValue } from '@swagger-api/apidom-core'; +import { isParameterElement, mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; +import { evaluate } from '@swagger-api/apidom-json-pointer'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference, dereferenceApiDOM, resolve, parse } from '../../../../../src'; +import { + DereferenceError, + MaximumDereferenceDepthError, + MaximumResolverDepthError, +} from '../../../../../src/util/errors'; +import Reference from '../../../../../src/Reference'; +import ReferenceSet from '../../../../../src/ReferenceSet'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Reference Object', function () { + context('given Reference Objects pointing internally and externally', function () { + const fixturePath = path.join(rootFixturePath, 'internal-external'); + + 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); + }); + + specify('should apply semantics to external fragment', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const fragment = evaluate('/0/components/parameters/externalRef', dereferenced); + + assert.isTrue(isParameterElement(fragment)); + }); + + specify( + 'should annotate transcluded element with additional metadata', + async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const fragment = evaluate('/0/components/parameters/userId', dereferenced); + + assert.strictEqual( + fragment.meta.get('ref-fields').get('$ref').toValue(), + '#/components/parameters/indirection1', + ); + assert.strictEqual( + fragment.meta.get('ref-fields').get('description').toValue(), + 'override', + ); + }, + ); + }); + + context('given Reference Objects pointing internally only', function () { + const fixturePath = path.join(rootFixturePath, 'internal-only'); + + 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 Reference Objects pointing externally only', function () { + const fixturePath = path.join(rootFixturePath, 'external-only'); + + 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 Reference Objects pointing to external indirections', function () { + const fixturePath = path.join(rootFixturePath, 'external-indirections'); + + 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); + }); + + specify('should apply semantics to eventual external fragment', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const fragment = evaluate('/0/components/parameters/externalRef', dereferenced); + + assert.isTrue(isParameterElement(fragment)); + }); + }); + + context('given Reference Objects with additional fields', function () { + const fixturePath = path.join(rootFixturePath, 'additional-fields'); + + 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 Reference Objects with additional ignored fields', function () { + const fixturePath = path.join(rootFixturePath, 'additional-ignored-fields'); + + 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 Reference Objects with internal cycles', function () { + const fixturePath = path.join(rootFixturePath, 'cycle-internal'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const parent = evaluate('/0/components/schemas/User/properties/parent', dereferenced); + const cyclicParent = evaluate( + '/0/components/schemas/User/properties/parent/properties/parent', + dereferenced, + ); + + assert.strictEqual(parent, cyclicParent); + }); + }); + + context('given Reference Objects with external resolution disabled', function () { + const fixturePath = path.join(rootFixturePath, 'ignore-external'); + + specify('should not dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { external: false }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given Reference Objects with direct circular internal reference', function () { + const fixturePath = path.join(rootFixturePath, 'direct-internal-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Reference Objects with indirect circular internal reference', function () { + const fixturePath = path.join(rootFixturePath, 'indirect-internal-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Reference Objects with direct circular external reference', function () { + const fixturePath = path.join(rootFixturePath, 'direct-external-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Reference Objects with indirect circular external reference', function () { + const fixturePath = path.join(rootFixturePath, 'indirect-external-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Reference Objects with unresolvable reference', function () { + const fixturePath = path.join(rootFixturePath, 'unresolvable-reference'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Reference Objects with invalid JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'invalid-pointer'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Reference Objects with arbitrary circular references', function () { + const fixturePath = path.join(rootFixturePath, 'ignore-arbitrary-$refs'); + + 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 Reference Objects with external circular dependency', function () { + const fixturePath = path.join(rootFixturePath, 'external-circular-dependency'); + + 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 Reference Objects and maxDepth of dereference', function () { + const fixturePath = path.join(rootFixturePath, 'max-depth'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + dereference: { maxDepth: 2 }, + }); + assert.fail('should throw MaximumDereferenceDepthError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, MaximumDereferenceDepthError); + assert.match(error.cause.cause.message, /fixtures\/max-depth\/ex2.json"$/); + } + }); + }); + + context('given Reference Objects and maxDepth of resolution', function () { + const fixturePath = path.join(rootFixturePath, 'max-depth'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { maxDepth: 2 }, + }); + assert.fail('should throw MaximumResolverDepthError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, MaximumResolverDepthError); + assert.match(error.cause.cause.message, /fixtures\/max-depth\/ex2.json"$/); + } + }); + }); + + context('given refSet is provided as an option', function () { + specify('should dereference without external resolution', async function () { + const fixturePath = path.join(__dirname, 'fixtures', 'refset-as-option'); + const uri = path.join(fixturePath, 'root.json'); + const refSet = await resolve(uri, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const actual = await dereference(uri, { dereference: { refSet } }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + + specify('should dereference single ApiDOM fragment', async function () { + const fixturePath = path.join(__dirname, 'fixtures', 'refset-as-option'); + const uri = path.join(fixturePath, 'root.json'); + const parseResult = await parse(uri, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + // @ts-ignore + const referenceElement = parseResult.api?.components.parameters.get('externalRef'); + const refSet = ReferenceSet(); + const rootFileReference = Reference({ uri, value: parseResult }); + const referenceElementReference = Reference({ + uri: `${uri}#/single-reference-object`, + value: new ParseResultElement([referenceElement]), + }); + // referenceElementReference needs to be added as first to create rootRef + refSet.add(referenceElementReference).add(rootFileReference); + + const actual = await dereferenceApiDOM(referenceElement, { + parse: { mediaType: mediaTypes.latest('generic') }, + resolve: { baseURI: uri }, + dereference: { refSet }, + }); + + const expected = { + name: 'externalParameter', + in: 'query', + description: 'external ref', + required: true, + }; + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given path with invalid URL characters - spaces', function () { + const fixturePath = path.join(rootFixturePath, 'path-encoding', 'path with spaces'); + + 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); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/components-request-bodies/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/components-request-bodies/dereferenced.json new file mode 100644 index 0000000000..6ad8f1d23b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/components-request-bodies/dereferenced.json @@ -0,0 +1,15 @@ +[ + { + "openapi": "3.1.0", + "components": { + "requestBodies": { + "requestBody1": { + "description": "example1 description" + }, + "requestBody2": { + "description": "example1 description" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/components-request-bodies/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/components-request-bodies/root.json new file mode 100644 index 0000000000..5ec8a98824 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/components-request-bodies/root.json @@ -0,0 +1,13 @@ +{ + "openapi": "3.1.0", + "components": { + "requestBodies": { + "requestBody1": { + "description": "example1 description" + }, + "requestBody2": { + "$ref": "#/components/requestBodies/requestBody1" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/operation-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/operation-object/dereferenced.json new file mode 100644 index 0000000000..8c50937f46 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/operation-object/dereferenced.json @@ -0,0 +1,21 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "requestBody": { + "description": "description of request body 2" + } + } + } + }, + "components": { + "requestBodies": { + "requestBody2": { + "description": "description of request body 2" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/operation-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/operation-object/root.json new file mode 100644 index 0000000000..5cb414e333 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/fixtures/operation-object/root.json @@ -0,0 +1,19 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "requestBody": { + "$ref": "#/components/requestBodies/requestBody2" + } + } + } + }, + "components": { + "requestBodies": { + "requestBody2": { + "description": "description of request body 2" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/index.ts new file mode 100644 index 0000000000..5fe1c4cba3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/request-body-object/index.ts @@ -0,0 +1,54 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Request Body Object', function () { + context('given in components/requestBodies field', function () { + const fixturePath = path.join(rootFixturePath, 'components-request-bodies'); + + 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 Operation Object', function () { + const fixturePath = path.join(rootFixturePath, 'operation-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); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/components-responses/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/components-responses/dereferenced.json new file mode 100644 index 0000000000..990f84fd2c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/components-responses/dereferenced.json @@ -0,0 +1,31 @@ +[ + { + "openapi": "3.1.0", + "components": { + "responses": { + "201": { + "description": "201 description", + "headers": { + "Content-Type": { + "description": "The number of allowed requests in the current period", + "schema": { + "type": "integer" + } + } + } + }, + "400": { + "description": "201 description", + "headers": { + "Content-Type": { + "description": "The number of allowed requests in the current period", + "schema": { + "type": "integer" + } + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/components-responses/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/components-responses/root.json new file mode 100644 index 0000000000..9b8fa923a3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/components-responses/root.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "components": { + "responses": { + "201": { + "description": "201 description", + "headers": { + "Content-Type": { + "description": "The number of allowed requests in the current period", + "schema": { + "type": "integer" + } + } + } + }, + "400": { + "$ref": "#/components/responses/201" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/responses-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/responses-object/dereferenced.json new file mode 100644 index 0000000000..8100dbd632 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/responses-object/dereferenced.json @@ -0,0 +1,29 @@ +[ + { + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "responses": { + "default": { + "description": "first response object" + }, + "200": { + "description": "second response object" + } + } + } + } + }, + "components": { + "responses": { + "default": { + "description": "first response object" + }, + "200": { + "description": "second response object" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/responses-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/responses-object/root.json new file mode 100644 index 0000000000..b16f8bfce3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/fixtures/responses-object/root.json @@ -0,0 +1,27 @@ +{ + "openapi": "3.1.0", + "paths": { + "/path": { + "get": { + "responses": { + "default": { + "$ref": "#/components/responses/default" + }, + "200": { + "$ref": "#/components/responses/200" + } + } + } + } + }, + "components": { + "responses": { + "default": { + "description": "first response object" + }, + "200": { + "description": "second response object" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/index.ts new file mode 100644 index 0000000000..f18146bc9f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/response-object/index.ts @@ -0,0 +1,54 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Response Object', function () { + context('given in components/responses field', function () { + const fixturePath = path.join(rootFixturePath, 'components-responses'); + + 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 Responses Object', function () { + const fixturePath = path.join(rootFixturePath, 'responses-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); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/dereference-apidom.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/dereference-apidom.ts new file mode 100644 index 0000000000..de03b48608 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/dereference-apidom.ts @@ -0,0 +1,59 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { mediaTypes, isSchemaElement, OpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1'; +import { evaluate } from '@swagger-api/apidom-json-pointer'; + +import { parse, dereferenceApiDOM } from '../../../../../src'; +import * as bootstrap from '../bootstrap'; + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Schema Object', function () { + context('given single SchemaElement passed to dereferenceApiDOM', function () { + const fixturePath = path.join(__dirname, 'fixtures', 'external-only', 'root.json'); + + specify('should dereference', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const schemaElement = evaluate( + '/components/schemas/User/properties/profile', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(schemaElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + }); + + assert.isTrue(isSchemaElement(dereferenced)); + }); + + specify('should dereference and contain metadata about origin', async function () { + const parseResult = await parse(fixturePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const pathItemElement = evaluate( + '/components/schemas/User/properties/profile', + parseResult.api as OpenApi3_1Element, + ); + const dereferenced = await dereferenceApiDOM(pathItemElement, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { baseURI: fixturePath }, + }); + + assert.match(dereferenced.meta.get('ref-origin').toValue(), /external-only\/ex\.json$/); + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/dereferenced.json new file mode 100644 index 0000000000..2fd205625d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/dereferenced.json @@ -0,0 +1,31 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$anchor": "user-profile", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/ex.json new file mode 100644 index 0000000000..b32830bdc4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/ex.json @@ -0,0 +1,15 @@ +{ + "$defs": { + "UserProfile": { + "$anchor": "user-profile", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/root.json new file mode 100644 index 0000000000..5f55276688 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-external/root.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "./ex.json#user-profile" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-internal/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-internal/dereferenced.json new file mode 100644 index 0000000000..6c8fd1b7b6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-internal/dereferenced.json @@ -0,0 +1,42 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$anchor": "user-profile", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "$anchor": "user-profile", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-internal/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-internal/root.json new file mode 100644 index 0000000000..f9a30fb1ca --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-internal/root.json @@ -0,0 +1,32 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#user-profile" + } + } + }, + "UserProfile": { + "$anchor": "user-profile", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-not-found/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-not-found/root.json new file mode 100644 index 0000000000..f0f2dce912 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$anchor-not-found/root.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#user-profile" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-unresolvable/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-unresolvable/root.json new file mode 100644 index 0000000000..a8a8381127 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-unresolvable/root.json @@ -0,0 +1,23 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$id": "./schemas/", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$id": "./nested/", + "$ref": "./ex.json" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/dereferenced.json new file mode 100644 index 0000000000..8ffbd8fe73 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/dereferenced.json @@ -0,0 +1,29 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$id": "./nested/", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/nested/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/nested/ex.json new file mode 100644 index 0000000000..b7f7f6299c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/nested/ex.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/root.json new file mode 100644 index 0000000000..2c9fd869f7 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-direct/root.json @@ -0,0 +1,22 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$id": "./nested/", + "$ref": "./ex.json" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/dereferenced.json new file mode 100644 index 0000000000..52f96bfc49 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/dereferenced.json @@ -0,0 +1,29 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$id": "./nested/", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/nested/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/nested/ex.json new file mode 100644 index 0000000000..b7f7f6299c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/nested/ex.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/root.json new file mode 100644 index 0000000000..4c3fa339ca --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-enclosing/root.json @@ -0,0 +1,22 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$id": "./nested/", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "./ex.json" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/dereferenced.json new file mode 100644 index 0000000000..8ffbd8fe73 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/dereferenced.json @@ -0,0 +1,29 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$id": "./nested/", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/nested/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/nested/ex.json new file mode 100644 index 0000000000..d5a6ae02c1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/nested/ex.json @@ -0,0 +1,8 @@ +{ + "$defs": { + "UserProfile": { + "$id": "./nested/", + "$ref": "./ex.json" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/nested/nested/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/nested/nested/ex.json new file mode 100644 index 0000000000..b7f7f6299c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/nested/nested/ex.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/root.json new file mode 100644 index 0000000000..ede427d60e --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$id-uri-external/root.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "./nested/ex.json#/$defs/UserProfile" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-$anchor/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-$anchor/dereferenced.json new file mode 100644 index 0000000000..bdca4c2d4b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-$anchor/dereferenced.json @@ -0,0 +1,34 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$anchor": "avatar", + "type": "string" + } + } + }, + "UserProfile": { + "$id": "https://swagger.io/schemas/user-profile", + "type": "object", + "properties": { + "avatar": { + "$anchor": "avatar", + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-$anchor/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-$anchor/root.json new file mode 100644 index 0000000000..ab1df7012d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-$anchor/root.json @@ -0,0 +1,31 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "https://swagger.io/schemas/user-profile#avatar" + } + } + }, + "UserProfile": { + "$id": "https://swagger.io/schemas/user-profile", + "type": "object", + "properties": { + "avatar": { + "$anchor": "avatar", + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-pointer/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-pointer/dereferenced.json new file mode 100644 index 0000000000..e21296c93f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-pointer/dereferenced.json @@ -0,0 +1,32 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "type": "string" + } + } + }, + "UserProfile": { + "$id": "https://swagger.io/schemas/user-profile", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-pointer/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-pointer/root.json new file mode 100644 index 0000000000..89e31d3af1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-pointer/root.json @@ -0,0 +1,30 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "https://swagger.io/schemas/user-profile#/properties/avatar" + } + } + }, + "UserProfile": { + "$id": "https://swagger.io/schemas/user-profile", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/dereferenced.json new file mode 100644 index 0000000000..d79569c33d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/dereferenced.json @@ -0,0 +1,23 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/ex.json new file mode 100644 index 0000000000..b7f7f6299c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/ex.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/root.json new file mode 100644 index 0000000000..7e6dec92a2 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-resolvable/root.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "./ex.json#/properties/avatar" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-unresolvable/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-unresolvable/root.json new file mode 100644 index 0000000000..37f1a25cc3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url-unresolvable/root.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "./ex.json" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url/dereferenced.json new file mode 100644 index 0000000000..990e6b83a1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url/dereferenced.json @@ -0,0 +1,38 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$id": "https://swagger.io/schemas/user-profile", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "$id": "https://swagger.io/schemas/user-profile", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url/root.json new file mode 100644 index 0000000000..1b6485de39 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-url/root.json @@ -0,0 +1,30 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "https://swagger.io/schemas/user-profile" + } + } + }, + "UserProfile": { + "$id": "https://swagger.io/schemas/user-profile", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-$anchor/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-$anchor/dereferenced.json new file mode 100644 index 0000000000..ded6680a23 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-$anchor/dereferenced.json @@ -0,0 +1,34 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$anchor": "avatar", + "type": "string" + } + } + }, + "UserProfile": { + "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f", + "type": "object", + "properties": { + "avatar": { + "$anchor": "avatar", + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-$anchor/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-$anchor/root.json new file mode 100644 index 0000000000..c519c4e62d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-$anchor/root.json @@ -0,0 +1,31 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f#avatar" + } + } + }, + "UserProfile": { + "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f", + "type": "object", + "properties": { + "avatar": { + "$anchor": "avatar", + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-pointer/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-pointer/dereferenced.json new file mode 100644 index 0000000000..eb6bf72bfe --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-pointer/dereferenced.json @@ -0,0 +1,32 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "type": "string" + } + } + }, + "UserProfile": { + "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-pointer/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-pointer/root.json new file mode 100644 index 0000000000..c53665d5a4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-pointer/root.json @@ -0,0 +1,30 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f#/properties/avatar" + } + } + }, + "UserProfile": { + "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-unresolvable/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-unresolvable/root.json new file mode 100644 index 0000000000..f508f83e24 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn-unresolvable/root.json @@ -0,0 +1,21 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "urn:uuid:3" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn/dereferenced.json new file mode 100644 index 0000000000..61fb93c201 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn/dereferenced.json @@ -0,0 +1,38 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn/root.json new file mode 100644 index 0000000000..2c3a9eabd4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$ref-urn/root.json @@ -0,0 +1,30 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f" + } + } + }, + "UserProfile": { + "$id": "urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-defined/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-defined/dereferenced.json new file mode 100644 index 0000000000..f9bf74b20c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-defined/dereferenced.json @@ -0,0 +1,39 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-defined/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-defined/root.json new file mode 100644 index 0000000000..34af5e8ce4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-defined/root.json @@ -0,0 +1,31 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-enclosing/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-enclosing/dereferenced.json new file mode 100644 index 0000000000..aaba585ba1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-enclosing/dereferenced.json @@ -0,0 +1,37 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-enclosing/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-enclosing/root.json new file mode 100644 index 0000000000..2d4f976f0a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-enclosing/root.json @@ -0,0 +1,30 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-mixed/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-mixed/dereferenced.json new file mode 100644 index 0000000000..c422a7ef68 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-mixed/dereferenced.json @@ -0,0 +1,39 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-mixed/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-mixed/root.json new file mode 100644 index 0000000000..dd3b4c451b --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-mixed/root.json @@ -0,0 +1,31 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "$schema": "https://spec.openapis.org/oas/3.1/dialect/base", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-undefined/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-undefined/dereferenced.json new file mode 100644 index 0000000000..8070ecde7a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-undefined/dereferenced.json @@ -0,0 +1,36 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-undefined/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-undefined/root.json new file mode 100644 index 0000000000..0360dcac66 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-undefined/root.json @@ -0,0 +1,29 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-unrecognized/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-unrecognized/dereferenced.json new file mode 100644 index 0000000000..a721e07f86 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-unrecognized/dereferenced.json @@ -0,0 +1,39 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$schema": "https://www.google.com/", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$schema": "https://www.google.com/", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "$schema": "https://www.google.com/", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-unrecognized/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-unrecognized/root.json new file mode 100644 index 0000000000..2eb3753431 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/$schema-unrecognized/root.json @@ -0,0 +1,31 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$schema": "https://www.google.com/", + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "$schema": "https://www.google.com/", + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/boolean-json-schema/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/boolean-json-schema/dereferenced.json new file mode 100644 index 0000000000..848bdd22fc --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/boolean-json-schema/dereferenced.json @@ -0,0 +1,22 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": true + } + }, + "UserProfile": true + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/boolean-json-schema/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/boolean-json-schema/root.json new file mode 100644 index 0000000000..2e4b6a1feb --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/boolean-json-schema/root.json @@ -0,0 +1,22 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": true + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-external/ex.json new file mode 100644 index 0000000000..3867c3eeb0 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-external/ex.json @@ -0,0 +1,11 @@ +{ + "$defs": { + "UserProfile": { + "properties": { + "parent": { + "$ref": "#/$defs/UserProfile" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-external/root.json new file mode 100644 index 0000000000..15ee3edf1c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-external/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "$ref": "./ex.json#/$defs/UserProfile" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal-external/ex.json new file mode 100644 index 0000000000..9251c7a6f9 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal-external/ex.json @@ -0,0 +1,11 @@ +{ + "$defs": { + "UserProfile": { + "properties": { + "user": { + "$ref": "./root.json#/components/schemas/User" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal-external/root.json new file mode 100644 index 0000000000..00f24682e8 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal-external/root.json @@ -0,0 +1,16 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "x-track": "1", + "properties": { + "profile": { + "$ref": "./ex.json#/$defs/UserProfile" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal/root.json new file mode 100644 index 0000000000..badb77703d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/cycle-internal/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "parent": { + "$ref": "#/components/schemas/User" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-external-circular/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-external-circular/ex.json new file mode 100644 index 0000000000..33dfbc1e5d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-external-circular/ex.json @@ -0,0 +1,7 @@ +{ + "$defs": { + "User": { + "$ref": "./root.json#/components/schemas/User" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-external-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-external-circular/root.json new file mode 100644 index 0000000000..a5138ec7bc --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-external-circular/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$ref": "./ex.json#/$defs/User" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-internal-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-internal-circular/root.json new file mode 100644 index 0000000000..fedad74def --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/direct-internal-circular/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$ref": "#/components/schemas/User" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/dereferenced.json new file mode 100644 index 0000000000..b7064c600c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/dereferenced.json @@ -0,0 +1,38 @@ +[ + { + "info": { + "title": "Swagger Petstore", + "version": "1.0.0" + }, + "openapi": "3.1.0", + "paths": { + "/pets": { + "get": { + "operationId": "listPets", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "type": "number" + } + }, + "application/yaml": { + "schema": { + "$anchor": "Pet", + "type": "number" + } + } + } + } + } + } + } + }, + "servers": [ + { + "url": "http://petstore.swagger.io/v1" + } + ] + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def.yml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def.yml new file mode 100644 index 0000000000..3191624521 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def.yml @@ -0,0 +1,4 @@ +components: + schemas: + Pet: + $ref: "./def2.yml#/components/schemas/Pet" diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def2.yml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def2.yml new file mode 100644 index 0000000000..aa2244e3cf --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def2.yml @@ -0,0 +1,4 @@ +components: + schemas: + Pet: + type: number diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def3.yml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def3.yml new file mode 100644 index 0000000000..19c9ed597f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/def3.yml @@ -0,0 +1,4 @@ +$defs: + Pet: + $anchor: Pet + type: number diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/pets.yml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/pets.yml new file mode 100644 index 0000000000..bf25452e7a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/pets.yml @@ -0,0 +1,5 @@ +get: + operationId: listPets + responses: + "200": + $ref: "./response.yml" diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/response.yml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/response.yml new file mode 100644 index 0000000000..35c495a154 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/pets/response.yml @@ -0,0 +1,7 @@ +content: + application/json: + schema: + $ref: "./def.yml#/components/schemas/Pet" + application/yaml: + schema: + $ref: "./def3.yml#Pet" diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/root.yml b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/root.yml new file mode 100644 index 0000000000..9b879ef29d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/document-boundaries/root.yml @@ -0,0 +1,10 @@ +openapi: "3.1.0" +info: + version: 1.0.0 + title: Swagger Petstore +servers: + - url: http://petstore.swagger.io/v1 +paths: + /pets: + $ref: "./pets/pets.yml" + diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/dereferenced.json new file mode 100644 index 0000000000..a3a4d8956a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/dereferenced.json @@ -0,0 +1,18 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "schema1": { + "type": "object" + }, + "schema2": { + "type": "object" + }, + "schema3": { + "type": "string" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/ex.json new file mode 100644 index 0000000000..088123c177 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/ex.json @@ -0,0 +1,13 @@ +{ + "$defs": { + "schema1": { + "$ref": "./root.json#/components/schemas/schema2" + }, + "schema2": { + "$ref": "./root.json#/components/schemas/schema2" + }, + "schema3": { + "type": "string" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/root.json new file mode 100644 index 0000000000..cb923170f5 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-circular-dependency/root.json @@ -0,0 +1,16 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "schema1": { + "$ref": "./ex.json#/$defs/schema1" + }, + "schema2": { + "type": "object" + }, + "schema3": { + "$ref": "./ex.json#/$defs/schema3" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/dereferenced.json new file mode 100644 index 0000000000..fefdfe26ab --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "Indirection": { + "type": "object", + "properties": { + "prop1": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex1.json new file mode 100644 index 0000000000..b36a740b4a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex1.json @@ -0,0 +1,7 @@ +{ + "$defs": { + "Indirection": { + "$ref": "./ex2.json#/$defs/Indirection" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex2.json new file mode 100644 index 0000000000..fde1576500 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex2.json @@ -0,0 +1,7 @@ +{ + "$defs": { + "Indirection": { + "$ref": "./ex3.json" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex3.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex3.json new file mode 100644 index 0000000000..c27dc30383 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/ex3.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "properties": { + "prop1": { + "type": "string" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/root.json new file mode 100644 index 0000000000..c4b862d724 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-indirections/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "Indirection": { + "$ref": "./ex1.json#/$defs/Indirection" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/dereferenced.json new file mode 100644 index 0000000000..85fde7c64f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/dereferenced.json @@ -0,0 +1,25 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "type": "object", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/ex.json new file mode 100644 index 0000000000..c115310b05 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/ex.json @@ -0,0 +1,16 @@ +{ + "type": "object", + "$defs": { + "UserProfile": { + "type": "object", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/root.json new file mode 100644 index 0000000000..15ee3edf1c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/external-only/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "$ref": "./ex.json#/$defs/UserProfile" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/dereferenced.json new file mode 100644 index 0000000000..45494ad27c --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/dereferenced.json @@ -0,0 +1,33 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + }, + "Order": { + "$ref": "./ex.json" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/ex.json new file mode 100644 index 0000000000..fc8a07edcd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/ex.json @@ -0,0 +1,8 @@ +{ + "externalParameter": { + "name": "externalParameter", + "in": "query", + "description": "this is parameter stored in external file", + "required": true + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/root.json new file mode 100644 index 0000000000..b58b884fd6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/ignore-external/root.json @@ -0,0 +1,26 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + }, + "Order": { + "$ref": "./ex.json" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex1.json new file mode 100644 index 0000000000..cb58d6153f --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex1.json @@ -0,0 +1,7 @@ +{ + "$defs": { + "User": { + "$ref": "./ex2.json#/$defs/User" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex2.json new file mode 100644 index 0000000000..556373d11d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex2.json @@ -0,0 +1,7 @@ +{ + "$defs": { + "User": { + "$ref": "./ex3.json#/$defs/User" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex3.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex3.json new file mode 100644 index 0000000000..33dfbc1e5d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/ex3.json @@ -0,0 +1,7 @@ +{ + "$defs": { + "User": { + "$ref": "./root.json#/components/schemas/User" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/root.json new file mode 100644 index 0000000000..041b79aa73 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-external-circular/root.json @@ -0,0 +1,10 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$ref": "./ex1.json#/$defs/User" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-internal-circular/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-internal-circular/root.json new file mode 100644 index 0000000000..460612050d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/indirect-internal-circular/root.json @@ -0,0 +1,19 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "$ref": "#/components/schemas/Indirection1" + }, + "Indirection1": { + "$ref": "#/components/schemas/Indirection2" + }, + "Indirection3": { + "$ref": "#/components/schemas/Indirection3" + }, + "Indirection4": { + "$ref": "#/components/schemas/User" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/infinite-recursion/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/infinite-recursion/root.json new file mode 100644 index 0000000000..145ae4496d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/infinite-recursion/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "$ref": "#/components/schemas/UserProfile" + }, + "UserProfile": { + "type": "object", + "$ref": "#/components/schemas/User" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/dereferenced.json new file mode 100644 index 0000000000..149231aee5 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/dereferenced.json @@ -0,0 +1,44 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "type": "object", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + }, + "Order": { + "type": "object", + "properties": { + "orderId": { + "type": "number" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/ex.json new file mode 100644 index 0000000000..8386ec5706 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/ex.json @@ -0,0 +1,12 @@ +{ + "$defs": { + "Order": { + "type": "object", + "properties": { + "orderId": { + "type": "number" + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/root.json new file mode 100644 index 0000000000..24c9fa2471 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-external/root.json @@ -0,0 +1,29 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + }, + "Order": { + "$ref": "./ex.json#/$defs/Order" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-only/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-only/dereferenced.json new file mode 100644 index 0000000000..8070ecde7a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-only/dereferenced.json @@ -0,0 +1,36 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-only/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-only/root.json new file mode 100644 index 0000000000..0360dcac66 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/internal-only/root.json @@ -0,0 +1,29 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "login": { + "type": "string" + }, + "password": { + "type": "string" + }, + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "type": "object", + "properties": { + "avatar": { + "type": "string" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/invalid-pointer/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/invalid-pointer/root.json new file mode 100644 index 0000000000..4a8c563523 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/invalid-pointer/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "$ref": "#/components/schemas/invalid-pointer" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex1.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex1.json new file mode 100644 index 0000000000..7de8b6d855 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex1.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "$defs": { + "Indirection": { + "$ref": "./ex2.json#/$defs/Indirection" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex2.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex2.json new file mode 100644 index 0000000000..39ed0289dd --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex2.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "$defs": { + "Indirection": { + "$ref": "./ex3.json" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex3.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex3.json new file mode 100644 index 0000000000..e6307dc1c6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/ex3.json @@ -0,0 +1,3 @@ +{ + "type": "object" +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/root.json new file mode 100644 index 0000000000..c20c6b510d --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/max-depth/root.json @@ -0,0 +1,11 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "$ref": "./ex1.json#/$defs/Indirection" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/dereferenced.json new file mode 100644 index 0000000000..d0dd4b205a --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/dereferenced.json @@ -0,0 +1,44 @@ +[ + { + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "type": "object", + "description": "user profile", + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + } + } + }, + "UserProfile": { + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + }, + "Order": { + "type": "object", + "properties": { + "orderId": { + "type": "number" + } + } + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/ex.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/ex.json new file mode 100644 index 0000000000..bcdbb69541 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/ex.json @@ -0,0 +1,8 @@ +{ + "type": "object", + "properties": { + "orderId": { + "type": "number" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/root.json new file mode 100644 index 0000000000..63ac9e5bd2 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/merging-keywords/root.json @@ -0,0 +1,31 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "type": "object", + "properties": { + "profile": { + "type": "object", + "description": "user profile", + "$ref": "#/components/schemas/UserProfile" + } + } + }, + "UserProfile": { + "properties": { + "firstName": { + "type": "string" + }, + "lastName": { + "type": "string" + } + } + }, + "Order": { + "type": "object", + "$ref": "./ex.json" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/unresolvable-reference/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/unresolvable-reference/root.json new file mode 100644 index 0000000000..6269b86390 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/fixtures/unresolvable-reference/root.json @@ -0,0 +1,14 @@ +{ + "openapi": "3.1.0", + "components": { + "schemas": { + "User": { + "properties": { + "profile": { + "$ref": "#/components/schemas/UserProfile" + } + } + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/index.ts new file mode 100644 index 0000000000..dace965b45 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/schema-object/index.ts @@ -0,0 +1,809 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { isSchemaElement, mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; +import { evaluate } from '@swagger-api/apidom-json-pointer'; + +import { dereference } from '../../../../../src'; +import { + DereferenceError, + MaximumDereferenceDepthError, + MaximumResolverDepthError, + ResolverError, +} from '../../../../../src/util/errors'; +import { loadJsonFile } from '../../../../helpers'; +import { EvaluationJsonSchema$anchorError } from '../../../../../src/dereference/strategies/openapi-3-1/selectors/$anchor/errors'; +import { EvaluationJsonSchemaUriError } from '../../../../../src/dereference/strategies/openapi-3-1/selectors/uri/errors'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Schema Object - $ref keyword from core vocabulary', function () { + context('given Schema Objects pointing internally and externally', function () { + const fixturePath = path.join(rootFixturePath, 'internal-external'); + + 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); + }); + + specify('should apply semantics to external fragment', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const fragment = evaluate('/0/components/schemas/Order', dereferenced); + + assert.isTrue(isSchemaElement(fragment)); + }); + + specify( + 'should annotate transcluded element with additional metadata', + async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const fragment = evaluate( + '/0/components/schemas/User/properties/profile', + dereferenced, + ); + + assert.strictEqual( + fragment.meta.get('ref-fields').get('$ref').toValue(), + '#/components/schemas/UserProfile', + ); + }, + ); + }); + + context('given Schema Objects pointing internally only', function () { + const fixturePath = path.join(rootFixturePath, 'internal-only'); + + 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 Schema Objects with internal cycles', function () { + const fixturePath = path.join(rootFixturePath, 'cycle-internal'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const parent = evaluate('/0/components/schemas/User/properties/parent', dereferenced); + const cyclicParent = evaluate( + '/0/components/schemas/User/properties/parent/properties/parent', + dereferenced, + ); + + assert.strictEqual(parent, cyclicParent); + }); + }); + + context('given Schema Objects with external cycles', function () { + const fixturePath = path.join(rootFixturePath, 'cycle-external'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const parent = evaluate( + '/0/components/schemas/User/properties/profile/properties/parent', + dereferenced, + ); + const cyclicParent = evaluate( + '/0/components/schemas/User/properties/profile/properties/parent/properties/parent', + dereferenced, + ); + + assert.strictEqual(parent, cyclicParent); + }); + }); + + context('given Schema Objects with internal and external cycles', function () { + const fixturePath = path.join(rootFixturePath, 'cycle-internal-external'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const user = evaluate( + '/0/components/schemas/User/properties/profile/properties/user', + dereferenced, + ); + const cyclicUserInProfile = evaluate( + '/0/components/schemas/User/properties/profile/properties/user/properties/profile/properties/user', + dereferenced, + ); + + assert.strictEqual(user, cyclicUserInProfile); + }); + }); + + context('given Schema Objects with external circular dependency', function () { + const fixturePath = path.join(rootFixturePath, 'external-circular-dependency'); + + 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 Schema Objects with external resolution disabled', function () { + const fixturePath = path.join(rootFixturePath, 'ignore-external'); + + specify('should not dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { external: false }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given Schema Objects with overlapping keywords', function () { + const fixturePath = path.join(rootFixturePath, 'merging-keywords'); + + 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 Schema Objects pointing externally only', function () { + const fixturePath = path.join(rootFixturePath, 'external-only'); + + 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 Schema Objects pointing to external indirections', function () { + const fixturePath = path.join(rootFixturePath, 'external-indirections'); + + 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); + }); + + specify('should apply semantics to eventual external fragment', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + const dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + const fragment = evaluate('/0/components/schemas/Indirection', dereferenced); + + assert.isTrue(isSchemaElement(fragment)); + }); + }); + + context('given Schema Objects with $schema keyword defined', function () { + const fixturePath = path.join(rootFixturePath, '$schema-defined'); + + 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 Schema Objects with $schema keyword defined in enclosing Schema Object', + function () { + let dereferenced: any; + let expected: any; + + beforeEach(async function () { + const fixturePath = path.join(rootFixturePath, '$schema-enclosing'); + const rootFilePath = path.join(fixturePath, 'root.json'); + dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + }); + + specify('should dereference', async function () { + assert.deepEqual(toValue(dereferenced), expected); + }); + + specify('should retain $schema before dereferencing', function () { + const profile = evaluate( + '/0/components/schemas/User/properties/profile', + dereferenced, + ); + + assert.strictEqual( + profile.meta.get('inherited$schema').toValue(), + 'https://spec.openapis.org/oas/3.1/dialect/base', + ); + }); + }, + ); + + context('given Schema Objects with mixed $schema keyword defined', function () { + const fixturePath = path.join(rootFixturePath, '$schema-mixed'); + + 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 Schema Objects with undefined $schema keyword', function () { + let dereferenced: any; + let expected: any; + + beforeEach(async function () { + const fixturePath = path.join(rootFixturePath, '$schema-undefined'); + const rootFilePath = path.join(fixturePath, 'root.json'); + dereferenced = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + }); + + specify('should dereference', async function () { + assert.deepEqual(toValue(dereferenced), expected); + }); + + specify('should inherit default $schema dialect for User', function () { + const user = evaluate('/0/components/schemas/User', dereferenced); + + assert.strictEqual( + user.meta.get('inherited$schema').toValue(), + 'https://spec.openapis.org/oas/3.1/dialect/base', + ); + }); + + specify('should inherit default $schema dialect for User.login', function () { + const user = evaluate('/0/components/schemas/User/properties/login', dereferenced); + + assert.strictEqual( + user.meta.get('inherited$schema').toValue(), + 'https://spec.openapis.org/oas/3.1/dialect/base', + ); + }); + + specify('should inherit default $schema dialect for UserProfile', function () { + const user = evaluate('/0/components/schemas/UserProfile', dereferenced); + + assert.strictEqual( + user.meta.get('inherited$schema').toValue(), + 'https://spec.openapis.org/oas/3.1/dialect/base', + ); + }); + + specify('should inherit default $schema dialect for UserProfile.login', function () { + const user = evaluate( + '/0/components/schemas/UserProfile/properties/avatar', + dereferenced, + ); + + assert.strictEqual( + user.meta.get('inherited$schema').toValue(), + 'https://spec.openapis.org/oas/3.1/dialect/base', + ); + }); + }); + + context('given Schema Objects with unrecognized $schema keyword defined', function () { + const fixturePath = path.join(rootFixturePath, '$schema-unrecognized'); + + 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 Schema Objects with $id keyword defined directly in referencing Schema Object', + function () { + const fixturePath = path.join(rootFixturePath, '$id-uri-direct'); + + 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 Schema Objects with $id keyword defined in enclosing Schema Object', + function () { + const fixturePath = path.join(rootFixturePath, '$id-uri-enclosing'); + + 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 Schema Objects with $id keyword pointing to external files', function () { + const fixturePath = path.join(rootFixturePath, '$id-uri-external'); + + 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 Schema Objects with unresolvable $id values', function () { + const fixturePath = path.join(rootFixturePath, '$id-unresolvable'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, ResolverError); + assert.match(error.cause.cause.message, /\/schemas\/nested\/ex\.json"$/); + } + }); + }); + + context('given Schema Objects with $ref keyword containing URL', function () { + const fixturePath = path.join(rootFixturePath, '$ref-url'); + + 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 Schema Objects with $ref keyword containing URL and JSON Pointer fragment', + function () { + const fixturePath = path.join(rootFixturePath, '$ref-url-pointer'); + + 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 Schema Objects with $ref keyword containing URL and $anchor', function () { + const fixturePath = path.join(rootFixturePath, '$ref-url-$anchor'); + + 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 Schema Objects with $ref keyword containing resolvable URL', function () { + const fixturePath = path.join(rootFixturePath, '$ref-url-resolvable'); + + 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 Schema Objects with $ref keyword containing unresolvable URL', function () { + const fixturePath = path.join(rootFixturePath, '$ref-url-unresolvable'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, ResolverError); + } + }); + }); + + context( + 'given Schema Objects with $ref keyword containing Uniform Resource Name', + function () { + const fixturePath = path.join(rootFixturePath, '$ref-urn'); + + 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 Schema Objects with $ref keyword containing Uniform Resource Name and JSON Pointer fragment', + function () { + const fixturePath = path.join(rootFixturePath, '$ref-urn-pointer'); + + 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 Schema Objects with $ref keyword containing Uniform Resource Name and $anchor', + function () { + const fixturePath = path.join(rootFixturePath, '$ref-urn-$anchor'); + + 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 Schema Objects with $ref keyword containing unresolvable Uniform Resource Name', + function () { + const fixturePath = path.join(rootFixturePath, '$ref-urn-unresolvable'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, EvaluationJsonSchemaUriError); + } + }); + }, + ); + + context( + 'given Schema Objects with $anchor keyword pointing to internal schema', + function () { + const fixturePath = path.join(rootFixturePath, '$anchor-internal'); + + 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 Schema Objects with $anchor keyword pointing to external schema', + function () { + const fixturePath = path.join(rootFixturePath, '$anchor-external'); + + 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 Schema Objects with various document boundaries', function () { + const fixturePath = path.join(rootFixturePath, 'document-boundaries'); + + specify('should dereference', async function () { + const rootFilePath = path.join(fixturePath, 'root.yml'); + const actual = await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('yaml') }, + }); + const expected = loadJsonFile(path.join(fixturePath, 'dereferenced.json')); + + assert.deepEqual(toValue(actual), expected); + }); + }); + + context('given Schema Objects with not found $anchor', function () { + const fixturePath = path.join(rootFixturePath, '$anchor-not-found'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, EvaluationJsonSchema$anchorError); + } + }); + }); + + context('given Boolean JSON Schemas', function () { + const fixturePath = path.join(rootFixturePath, 'boolean-json-schema'); + + 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 Schema Objects and maxDepth of dereference', function () { + const fixturePath = path.join(rootFixturePath, 'max-depth'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + dereference: { maxDepth: 2 }, + }); + assert.fail('should throw MaximumDereferenceDepthError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, MaximumDereferenceDepthError); + assert.match(error.cause.cause.message, /fixtures\/max-depth\/ex2.json"$/); + } + }); + }); + + context('given Schema Objects and maxDepth of resolution', function () { + const fixturePath = path.join(rootFixturePath, 'max-depth'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + resolve: { maxDepth: 2 }, + }); + assert.fail('should throw MaximumResolverDepthError'); + } catch (error: any) { + assert.instanceOf(error, DereferenceError); + assert.instanceOf(error.cause.cause, MaximumResolverDepthError); + assert.match(error.cause.cause.message, /fixtures\/max-depth\/ex2.json"$/); + } + }); + }); + + context('given Schema Objects with unresolvable reference', function () { + const fixturePath = path.join(rootFixturePath, 'unresolvable-reference'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Schema Objects with invalid JSON Pointer', function () { + const fixturePath = path.join(rootFixturePath, 'invalid-pointer'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Schema Objects with infinite recursion', function () { + const fixturePath = path.join(rootFixturePath, 'infinite-recursion'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Schema Objects with direct circular external reference', function () { + const fixturePath = path.join(rootFixturePath, 'direct-external-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Schema Objects with direct circular internal reference', function () { + const fixturePath = path.join(rootFixturePath, 'direct-internal-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Schema Objects with indirect circular external reference', function () { + const fixturePath = path.join(rootFixturePath, 'indirect-external-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + + context('given Schema Objects with indirect circular internal reference', function () { + const fixturePath = path.join(rootFixturePath, 'indirect-internal-circular'); + + specify('should throw error', async function () { + const rootFilePath = path.join(fixturePath, 'root.json'); + try { + await dereference(rootFilePath, { + parse: { mediaType: mediaTypes.latest('json') }, + }); + assert.fail('should throw DereferenceError'); + } catch (e) { + assert.instanceOf(e, DereferenceError); + } + }); + }); + }); + }); + }); +}); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/fixtures/components-security-schemes/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/fixtures/components-security-schemes/dereferenced.json new file mode 100644 index 0000000000..26efe25eb3 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/fixtures/components-security-schemes/dereferenced.json @@ -0,0 +1,19 @@ +[ + { + "openapi": "3.1.0", + "components": { + "securitySchemes": { + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "header" + }, + "api_key2": { + "type": "apiKey", + "name": "api_key", + "in": "header" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/fixtures/components-security-schemes/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/fixtures/components-security-schemes/root.json new file mode 100644 index 0000000000..4addc45cac --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/fixtures/components-security-schemes/root.json @@ -0,0 +1,15 @@ +{ + "openapi": "3.1.0", + "components": { + "securitySchemes": { + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "header" + }, + "api_key2": { + "$ref": "#/components/securitySchemes/api_key" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/index.ts new file mode 100644 index 0000000000..8b9960ffc7 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/security-schemes-object/index.ts @@ -0,0 +1,40 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; +import * as bootstrap from '../bootstrap'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + before(function () { + bootstrap.before(); + }); + + after(function () { + bootstrap.after(); + }); + + context('strategies', function () { + context('openapi-3-1swagger-client', function () { + context('Security Scheme Object', function () { + context('given in components/securitySchemes field', function () { + const fixturePath = path.join(rootFixturePath, 'components-security-schemes'); + + 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); + }); + }); + }); + }); + }); +});