-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(reference): add location tests for OpenAPI 2.0 dereference
Refs #3102
- Loading branch information
Showing
15 changed files
with
367 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...ference/strategies/openapi-2/parameter-object/fixtures/operation-object/dereferenced.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
] |
21 changes: 21 additions & 0 deletions
21
...est/dereference/strategies/openapi-2/parameter-object/fixtures/operation-object/root.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ference/strategies/openapi-2/parameter-object/fixtures/path-item-object/dereferenced.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
] |
19 changes: 19 additions & 0 deletions
19
...est/dereference/strategies/openapi-2/parameter-object/fixtures/path-item-object/root.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
packages/apidom-reference/test/dereference/strategies/openapi-2/parameter-object/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
...eference/strategies/openapi-2/response-object/fixtures/responses-object/dereferenced.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
] |
25 changes: 25 additions & 0 deletions
25
...test/dereference/strategies/openapi-2/response-object/fixtures/responses-object/root.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/apidom-reference/test/dereference/strategies/openapi-2/response-object/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
...est/dereference/strategies/openapi-2/schema-object/fixtures/definitions/dereferenced.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
] |
11 changes: 11 additions & 0 deletions
11
...erence/test/dereference/strategies/openapi-2/schema-object/fixtures/definitions/root.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ereference/strategies/openapi-2/schema-object/fixtures/parameter-object/dereferenced.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
] |
15 changes: 15 additions & 0 deletions
15
...e/test/dereference/strategies/openapi-2/schema-object/fixtures/parameter-object/root.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...dereference/strategies/openapi-2/schema-object/fixtures/response-object/dereferenced.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} | ||
] |
17 changes: 17 additions & 0 deletions
17
...ce/test/dereference/strategies/openapi-2/schema-object/fixtures/response-object/root.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
packages/apidom-reference/test/dereference/strategies/openapi-2/schema-object/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |