-
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.
feat(reference): add swagger-client OpenAPI 3.1 dereferene strategy (#…
- Loading branch information
Showing
282 changed files
with
7,169 additions
and
12 deletions.
There are no files selected for viewing
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
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
51 changes: 51 additions & 0 deletions
51
...ages/apidom-reference/test/dereference/strategies/openapi-3-1-swagger-client/bootstrap.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,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; | ||
}; |
19 changes: 19 additions & 0 deletions
19
...penapi-3-1-swagger-client/callback-object/fixtures/components-callbacks/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 @@ | ||
[ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"callbacks": { | ||
"callback1": { | ||
"{$method}": { | ||
"description": "description of callback2" | ||
} | ||
}, | ||
"callback2": { | ||
"{$method}": { | ||
"description": "description of callback2" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
...tegies/openapi-3-1-swagger-client/callback-object/fixtures/components-callbacks/root.yaml
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,9 @@ | ||
--- | ||
openapi: 3.1.0 | ||
components: | ||
callbacks: | ||
callback1: | ||
"$ref": "#/components/callbacks/callback2" | ||
callback2: | ||
"{$method}": | ||
description: description of callback2 |
27 changes: 27 additions & 0 deletions
27
...es/openapi-3-1-swagger-client/callback-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,27 @@ | ||
[ | ||
{ | ||
"openapi": "3.1.0", | ||
"paths": { | ||
"/path": { | ||
"get": { | ||
"callbacks": { | ||
"callback": { | ||
"{$method}": { | ||
"description": "description of callback2" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"callbacks": { | ||
"callback": { | ||
"{$method}": { | ||
"description": "description of callback2" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
] |
13 changes: 13 additions & 0 deletions
13
...strategies/openapi-3-1-swagger-client/callback-object/fixtures/operation-object/root.yaml
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 @@ | ||
--- | ||
openapi: 3.1.0 | ||
paths: | ||
"/path": | ||
get: | ||
callbacks: | ||
callback: | ||
"$ref": "#/components/callbacks/callback" | ||
components: | ||
callbacks: | ||
callback: | ||
"{$method}": | ||
description: description of callback2 |
54 changes: 54 additions & 0 deletions
54
...reference/test/dereference/strategies/openapi-3-1-swagger-client/callback-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,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); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
...st/dereference/strategies/openapi-3-1-swagger-client/example-object/dereference-apidom.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,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$/, | ||
); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
.../openapi-3-1-swagger-client/example-object/fixtures/components-examples/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 @@ | ||
[ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"examples": { | ||
"example1": { | ||
"description": "example1 description", | ||
"value": 1 | ||
}, | ||
"example2": { | ||
"description": "example1 description", | ||
"value": 1 | ||
} | ||
} | ||
} | ||
} | ||
] |
14 changes: 14 additions & 0 deletions
14
...rategies/openapi-3-1-swagger-client/example-object/fixtures/components-examples/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,14 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"examples": { | ||
"example1": { | ||
"description": "example1 description", | ||
"value": 1 | ||
}, | ||
"example2": { | ||
"$ref": "#/components/examples/example1" | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...penapi-3-1-swagger-client/example-object/fixtures/external-value-binary/dereferenced.json
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+15 KB
...gies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/favicon.ico
Binary file not shown.
11 changes: 11 additions & 0 deletions
11
...tegies/openapi-3-1-swagger-client/example-object/fixtures/external-value-binary/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 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"examples": { | ||
"example1": { | ||
"description": "example1 description", | ||
"externalValue": "./favicon.ico" | ||
} | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...1-swagger-client/example-object/fixtures/external-value-ignore-external/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 @@ | ||
[ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"examples": { | ||
"example1": { | ||
"description": "example1 description", | ||
"externalValue": "./ex.json" | ||
} | ||
} | ||
} | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
...openapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/ex.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 changes: 11 additions & 0 deletions
11
...enapi-3-1-swagger-client/example-object/fixtures/external-value-ignore-external/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 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"examples": { | ||
"example1": { | ||
"description": "example1 description", | ||
"externalValue": "./ex.json" | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
.../openapi-3-1-swagger-client/example-object/fixtures/external-value-json/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 @@ | ||
[ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"examples": { | ||
"example1": { | ||
"description": "example1 description", | ||
"value": { | ||
"prop1": "value1", | ||
"prop2": "value2" | ||
}, | ||
"externalValue": "./ex.json" | ||
} | ||
} | ||
} | ||
} | ||
] |
4 changes: 4 additions & 0 deletions
4
...strategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/ex.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,4 @@ | ||
{ | ||
"prop1": "value1", | ||
"prop2": "value2" | ||
} |
11 changes: 11 additions & 0 deletions
11
...rategies/openapi-3-1-swagger-client/example-object/fixtures/external-value-json/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 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"components": { | ||
"examples": { | ||
"example1": { | ||
"description": "example1 description", | ||
"externalValue": "./ex.json" | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.