diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/operation-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/operation-object/dereferenced.json new file mode 100644 index 0000000000..a33525bcbe --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/operation-object/dereferenced.json @@ -0,0 +1,25 @@ +[ + { + "swagger": "2.0", + "paths": { + "/path": { + "get": { + "parameters": [ + { + "name": "offset", + "in": "query", + "required": true + } + ] + } + } + }, + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/operation-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/operation-object/root.json new file mode 100644 index 0000000000..ea8cf9fef6 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/operation-object/root.json @@ -0,0 +1,21 @@ +{ + "swagger": "2.0", + "paths": { + "/path": { + "get": { + "parameters": [ + { + "$ref": "#/parameters/param1" + } + ] + } + } + }, + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/path-item-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/path-item-object/dereferenced.json new file mode 100644 index 0000000000..8c8c686872 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/path-item-object/dereferenced.json @@ -0,0 +1,23 @@ +[ + { + "swagger": "2.0", + "paths": { + "/path": { + "parameters": [ + { + "name": "offset", + "in": "query", + "required": true + } + ] + } + }, + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/path-item-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/path-item-object/root.json new file mode 100644 index 0000000000..d604821331 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/fixtures/path-item-object/root.json @@ -0,0 +1,19 @@ +{ + "swagger": "2.0", + "paths": { + "/path": { + "parameters": [ + { + "$ref": "#/parameters/param1" + } + ] + } + }, + "parameters": { + "param1": { + "name": "offset", + "in": "query", + "required": true + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/index.ts new file mode 100644 index 0000000000..3868d3be78 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/index.ts @@ -0,0 +1,45 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-2'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + context('strategies', function () { + context('openapi-2', function () { + context('Parameter Object', function () { + 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-2/response-object/fixtures/responses-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/fixtures/responses-object/dereferenced.json new file mode 100644 index 0000000000..89d59daea5 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/fixtures/responses-object/dereferenced.json @@ -0,0 +1,27 @@ +[ + { + "swagger": "2.0", + "paths": { + "/path": { + "get": { + "responses": { + "default": { + "description": "first response object" + }, + "200": { + "description": "second response object" + } + } + } + } + }, + "responses": { + "default": { + "description": "first response object" + }, + "200": { + "description": "second response object" + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/fixtures/responses-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/fixtures/responses-object/root.json new file mode 100644 index 0000000000..4031c15c75 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/fixtures/responses-object/root.json @@ -0,0 +1,25 @@ +{ + "swagger": "2.0", + "paths": { + "/path": { + "get": { + "responses": { + "default": { + "$ref": "#/responses/default" + }, + "200": { + "$ref": "#/responses/200" + } + } + } + } + }, + "responses": { + "default": { + "description": "first response object" + }, + "200": { + "description": "second response object" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/index.ts new file mode 100644 index 0000000000..6da753a434 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/index.ts @@ -0,0 +1,31 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-2'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + context('strategies', function () { + context('openapi-2', function () { + context('Response Object', function () { + 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-2/schema-object/fixtures/definitions/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/definitions/dereferenced.json new file mode 100644 index 0000000000..d15ac021e4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/definitions/dereferenced.json @@ -0,0 +1,13 @@ +[ + { + "swagger": "2.0", + "definitions": { + "schema1": { + "title": "title of schema 1" + }, + "schema2": { + "title": "title of schema 1" + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/definitions/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/definitions/root.json new file mode 100644 index 0000000000..f1cfd73296 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/definitions/root.json @@ -0,0 +1,11 @@ +{ + "swagger": "2.0", + "definitions": { + "schema1": { + "title": "title of schema 1" + }, + "schema2": { + "$ref": "#/definitions/schema1" + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/parameter-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/parameter-object/dereferenced.json new file mode 100644 index 0000000000..3269621be9 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/parameter-object/dereferenced.json @@ -0,0 +1,17 @@ +[ + { + "swagger": "2.0", + "parameters": { + "parameter1": { + "schema": { + "title": "parameter1 schema title" + } + }, + "parameter2": { + "schema": { + "title": "parameter1 schema title" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/parameter-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/parameter-object/root.json new file mode 100644 index 0000000000..689d1d78d4 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/parameter-object/root.json @@ -0,0 +1,15 @@ +{ + "swagger": "2.0", + "parameters": { + "parameter1": { + "schema": { + "title": "parameter1 schema title" + } + }, + "parameter2": { + "schema": { + "$ref": "#/parameters/parameter1/schema" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/response-object/dereferenced.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/response-object/dereferenced.json new file mode 100644 index 0000000000..f68a71fd52 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/response-object/dereferenced.json @@ -0,0 +1,19 @@ +[ + { + "swagger": "2.0", + "responses": { + "response1": { + "description": "response1 description", + "schema": { + "type": "string" + } + }, + "response2": { + "description": "response2 description", + "schema": { + "type": "string" + } + } + } + } +] diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/response-object/root.json b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/response-object/root.json new file mode 100644 index 0000000000..34da8a51f2 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/fixtures/response-object/root.json @@ -0,0 +1,17 @@ +{ + "swagger": "2.0", + "responses": { + "response1": { + "description": "response1 description", + "schema": { + "type": "string" + } + }, + "response2": { + "description": "response2 description", + "schema": { + "$ref": "#/responses/response1/schema" + } + } + } +} diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/index.ts new file mode 100644 index 0000000000..b45fc114d1 --- /dev/null +++ b/packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/index.ts @@ -0,0 +1,59 @@ +import path from 'node:path'; +import { assert } from 'chai'; +import { toValue } from '@swagger-api/apidom-core'; +import { mediaTypes } from '@swagger-api/apidom-ns-openapi-2'; + +import { loadJsonFile } from '../../../../helpers'; +import { dereference } from '../../../../../src'; + +const rootFixturePath = path.join(__dirname, 'fixtures'); + +describe('dereference', function () { + context('strategies', function () { + context('openapi-2', function () { + context('Schema Object', function () { + context('given in definitions field', function () { + const fixturePath = path.join(rootFixturePath, 'definitions'); + + 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 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); + }); + }); + }); + }); + }); +});