Skip to content

Commit

Permalink
test(reference): add location tests for OpenAPI 2.0 dereference
Browse files Browse the repository at this point in the history
Refs #3102
  • Loading branch information
char0n committed Nov 23, 2023
1 parent e048041 commit d81fb00
Show file tree
Hide file tree
Showing 15 changed files with 367 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"swagger": "2.0",
"paths": {
"/path": {
"get": {
"parameters": [
{
"$ref": "#/parameters/param1"
}
]
}
}
},
"parameters": {
"param1": {
"name": "offset",
"in": "query",
"required": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"swagger": "2.0",
"paths": {
"/path": {
"parameters": [
{
"name": "offset",
"in": "query",
"required": true
}
]
}
},
"parameters": {
"param1": {
"name": "offset",
"in": "query",
"required": true
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"swagger": "2.0",
"paths": {
"/path": {
"parameters": [
{
"$ref": "#/parameters/param1"
}
]
}
},
"parameters": {
"param1": {
"name": "offset",
"in": "query",
"required": true
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
]
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"swagger": "2.0",
"definitions": {
"schema1": {
"title": "title of schema 1"
},
"schema2": {
"title": "title of schema 1"
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"swagger": "2.0",
"definitions": {
"schema1": {
"title": "title of schema 1"
},
"schema2": {
"$ref": "#/definitions/schema1"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[
{
"swagger": "2.0",
"parameters": {
"parameter1": {
"schema": {
"title": "parameter1 schema title"
}
},
"parameter2": {
"schema": {
"title": "parameter1 schema title"
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"swagger": "2.0",
"parameters": {
"parameter1": {
"schema": {
"title": "parameter1 schema title"
}
},
"parameter2": {
"schema": {
"$ref": "#/parameters/parameter1/schema"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"swagger": "2.0",
"responses": {
"response1": {
"description": "response1 description",
"schema": {
"type": "string"
}
},
"response2": {
"description": "response2 description",
"schema": {
"type": "string"
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"swagger": "2.0",
"responses": {
"response1": {
"description": "response1 description",
"schema": {
"type": "string"
}
},
"response2": {
"description": "response2 description",
"schema": {
"$ref": "#/responses/response1/schema"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});
});
});

0 comments on commit d81fb00

Please sign in to comment.