swagger-client 3.26.7 → 3.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/swagger-client.browser.js +567 -413
- package/dist/swagger-client.browser.min.js +1 -1
- package/dist/swagger-client.browser.min.js.map +1 -1
- package/es/execute/oas3/content-serializer.js +10 -1
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +35 -11
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +39 -30
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +322 -239
- package/es/resolver/strategies/openapi-3-1-apidom/resolve.js +18 -4
- package/lib/execute/oas3/content-serializer.js +10 -1
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +34 -10
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +37 -28
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +320 -237
- package/lib/resolver/strategies/openapi-3-1-apidom/resolve.js +17 -2
- package/package.json +5 -5
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
|
-
import { toValue, transclude,
|
|
2
|
+
import { ParseResultElement, ObjectElement, toValue, transclude, cloneDeep } from '@swagger-api/apidom-core';
|
|
3
3
|
import { compile as jsonPointerCompile, evaluate as jsonPointerEvaluate, EvaluationJsonPointerError, InvalidJsonPointerError } from '@swagger-api/apidom-json-pointer';
|
|
4
|
-
import {
|
|
5
|
-
import { dereferenceApiDOM, url, ReferenceSet, Reference } from '@swagger-api/apidom-reference/configuration/empty';
|
|
4
|
+
import { mediaTypes, OpenApi3_1Element } from '@swagger-api/apidom-ns-openapi-3-1';
|
|
5
|
+
import { dereferenceApiDOM, url, ReferenceSet, Reference, options as referenceOptions } from '@swagger-api/apidom-reference/configuration/empty';
|
|
6
6
|
import BinaryParser from '@swagger-api/apidom-reference/parse/parsers/binary';
|
|
7
7
|
import OpenApi3_1ResolveStrategy from '@swagger-api/apidom-reference/resolve/strategies/openapi-3-1';
|
|
8
8
|
import { DEFAULT_BASE_URL } from '../../../constants.js';
|
|
@@ -14,6 +14,18 @@ import YamlParser from '../../apidom/reference/parse/parsers/yaml-1-2/index.js';
|
|
|
14
14
|
import OpenApiJson3_1Parser from '../../apidom/reference/parse/parsers/openapi-json-3-1/index.js';
|
|
15
15
|
import OpenApiYaml3_1Parser from '../../apidom/reference/parse/parsers/openapi-yaml-3-1/index.js';
|
|
16
16
|
import OpenApi3_1SwaggerClientDereferenceStrategy from '../../apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js';
|
|
17
|
+
export const circularReplacer = refElement => {
|
|
18
|
+
const $refBaseURI = toValue(refElement.meta.get('baseURI'));
|
|
19
|
+
const referencingElement = refElement.meta.get('referencingElement');
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Removing semantics from the absolutified referencing element by
|
|
23
|
+
* using generic ObjectElement to represent the reference.
|
|
24
|
+
*/
|
|
25
|
+
return new ObjectElement({
|
|
26
|
+
$ref: $refBaseURI
|
|
27
|
+
}, cloneDeep(referencingElement.meta), cloneDeep(referencingElement.attributes));
|
|
28
|
+
};
|
|
17
29
|
const resolveOpenAPI31Strategy = async options => {
|
|
18
30
|
const {
|
|
19
31
|
spec,
|
|
@@ -122,7 +134,9 @@ const resolveOpenAPI31Strategy = async options => {
|
|
|
122
134
|
dereferenceOpts: {
|
|
123
135
|
errors
|
|
124
136
|
},
|
|
125
|
-
immutable: false
|
|
137
|
+
immutable: false,
|
|
138
|
+
circular: useCircularStructures ? 'ignore' : 'replace',
|
|
139
|
+
circularReplacer: useCircularStructures ? referenceOptions.dereference.circularReplacer : circularReplacer
|
|
126
140
|
}
|
|
127
141
|
});
|
|
128
142
|
const transcluded = transclude(fragmentElement, dereferenced, openApiElement);
|
|
@@ -13,7 +13,16 @@ function serialize(value, mediaType) {
|
|
|
13
13
|
// Assume the user has a JSON string
|
|
14
14
|
return value;
|
|
15
15
|
}
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
value = value.map(v => {
|
|
18
|
+
try {
|
|
19
|
+
return JSON.parse(v);
|
|
20
|
+
} catch (e) {
|
|
21
|
+
return v;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
16
25
|
return JSON.stringify(value);
|
|
17
26
|
}
|
|
18
|
-
return value
|
|
27
|
+
return String(value);
|
|
19
28
|
}
|
package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js
CHANGED
|
@@ -18,7 +18,6 @@ const visitAsync = _apidomCore.visit[Symbol.for('nodejs.util.promisify.custom')]
|
|
|
18
18
|
const mergeAllVisitorsAsync = _apidomCore.mergeAllVisitors[Symbol.for('nodejs.util.promisify.custom')];
|
|
19
19
|
const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
|
|
20
20
|
props: {
|
|
21
|
-
useCircularStructures: true,
|
|
22
21
|
allowMetaPatches: false,
|
|
23
22
|
parameterMacro: null,
|
|
24
23
|
modelPropertyMacro: null,
|
|
@@ -26,7 +25,6 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
|
|
|
26
25
|
ancestors: null
|
|
27
26
|
},
|
|
28
27
|
init({
|
|
29
|
-
useCircularStructures = this.useCircularStructures,
|
|
30
28
|
allowMetaPatches = this.allowMetaPatches,
|
|
31
29
|
parameterMacro = this.parameterMacro,
|
|
32
30
|
modelPropertyMacro = this.modelPropertyMacro,
|
|
@@ -34,7 +32,6 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
|
|
|
34
32
|
ancestors = []
|
|
35
33
|
} = {}) {
|
|
36
34
|
this.name = 'openapi-3-1-swagger-client';
|
|
37
|
-
this.useCircularStructures = useCircularStructures;
|
|
38
35
|
this.allowMetaPatches = allowMetaPatches;
|
|
39
36
|
this.parameterMacro = parameterMacro;
|
|
40
37
|
this.modelPropertyMacro = modelPropertyMacro;
|
|
@@ -46,17 +43,32 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
|
|
|
46
43
|
var _options$dereference$;
|
|
47
44
|
const visitors = [];
|
|
48
45
|
const namespace = (0, _apidomCore.createNamespace)(_apidomNsOpenapi.default);
|
|
49
|
-
const
|
|
46
|
+
const immutableRefSet = (_options$dereference$ = options.dereference.refSet) != null ? _options$dereference$ : (0, _empty.ReferenceSet)();
|
|
47
|
+
const mutableRefsSet = (0, _empty.ReferenceSet)();
|
|
48
|
+
let refSet = immutableRefSet;
|
|
50
49
|
let reference;
|
|
51
|
-
if (!
|
|
50
|
+
if (!immutableRefSet.has(file.uri)) {
|
|
52
51
|
reference = (0, _empty.Reference)({
|
|
53
52
|
uri: file.uri,
|
|
54
53
|
value: file.parseResult
|
|
55
54
|
});
|
|
56
|
-
|
|
55
|
+
immutableRefSet.add(reference);
|
|
57
56
|
} else {
|
|
58
57
|
// pre-computed refSet was provided as configuration option
|
|
59
|
-
reference =
|
|
58
|
+
reference = immutableRefSet.find(ref => ref.uri === file.uri);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Clone refSet due the dereferencing process being mutable.
|
|
63
|
+
* We don't want to mutate the original refSet and the references.
|
|
64
|
+
*/
|
|
65
|
+
if (options.dereference.immutable) {
|
|
66
|
+
immutableRefSet.refs.map(ref => (0, _empty.Reference)({
|
|
67
|
+
...ref,
|
|
68
|
+
value: (0, _apidomCore.cloneDeep)(ref.value)
|
|
69
|
+
})).forEach(ref => mutableRefsSet.add(ref));
|
|
70
|
+
reference = mutableRefsSet.find(ref => ref.uri === file.uri);
|
|
71
|
+
refSet = mutableRefsSet;
|
|
60
72
|
}
|
|
61
73
|
|
|
62
74
|
// create main dereference visitor
|
|
@@ -64,7 +76,6 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
|
|
|
64
76
|
reference,
|
|
65
77
|
namespace,
|
|
66
78
|
options,
|
|
67
|
-
useCircularStructures: this.useCircularStructures,
|
|
68
79
|
allowMetaPatches: this.allowMetaPatches,
|
|
69
80
|
ancestors: this.ancestors
|
|
70
81
|
});
|
|
@@ -106,12 +117,25 @@ const OpenApi3_1SwaggerClientDereferenceStrategy = _openapi.default.compose({
|
|
|
106
117
|
});
|
|
107
118
|
|
|
108
119
|
/**
|
|
109
|
-
*
|
|
120
|
+
* If immutable option is set, replay refs from the refSet.
|
|
121
|
+
*/
|
|
122
|
+
if (options.dereference.immutable) {
|
|
123
|
+
mutableRefsSet.refs.filter(ref => ref.uri.startsWith('immutable://')).map(ref => (0, _empty.Reference)({
|
|
124
|
+
...ref,
|
|
125
|
+
uri: ref.uri.replace(/^immutable:\/\//, '')
|
|
126
|
+
})).forEach(ref => immutableRefSet.add(ref));
|
|
127
|
+
reference = immutableRefSet.find(ref => ref.uri === file.uri);
|
|
128
|
+
refSet = immutableRefSet;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Release all memory if this refSet was not provided as an configuration option.
|
|
110
133
|
* If provided as configuration option, then provider is responsible for cleanup.
|
|
111
134
|
*/
|
|
112
135
|
if (options.dereference.refSet === null) {
|
|
113
|
-
|
|
136
|
+
immutableRefSet.clean();
|
|
114
137
|
}
|
|
138
|
+
mutableRefsSet.clean();
|
|
115
139
|
return dereferencedElement;
|
|
116
140
|
}
|
|
117
141
|
}
|
|
@@ -31,7 +31,8 @@ const AllOfVisitor = (0, _compose.default)({
|
|
|
31
31
|
|
|
32
32
|
// remove allOf keyword if empty
|
|
33
33
|
if (schemaElement.allOf.isEmpty) {
|
|
34
|
-
|
|
34
|
+
schemaElement.remove('allOf');
|
|
35
|
+
return undefined;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
// collect errors if allOf keyword contains anything else than Schema Object
|
|
@@ -43,37 +44,45 @@ const AllOfVisitor = (0, _compose.default)({
|
|
|
43
44
|
(_this$options$derefer2 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer2 = _this$options$derefer2.errors) == null || _this$options$derefer2.push == null || _this$options$derefer2.push(error);
|
|
44
45
|
return undefined;
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
+
while (schemaElement.hasKey('allOf')) {
|
|
48
|
+
const {
|
|
49
|
+
allOf
|
|
50
|
+
} = schemaElement;
|
|
51
|
+
schemaElement.remove('allOf');
|
|
52
|
+
const allOfMerged = _apidomCore.deepmerge.all([...allOf.content, schemaElement]);
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* If there was not an original $$ref value, make sure to remove
|
|
56
|
+
* any $$ref value that may exist from the result of `allOf` merges.
|
|
57
|
+
*/
|
|
58
|
+
if (!schemaElement.hasKey('$$ref')) {
|
|
59
|
+
allOfMerged.remove('$$ref');
|
|
60
|
+
}
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
/**
|
|
63
|
+
* If there was an example keyword in the original schema,
|
|
64
|
+
* keep it instead of merging with example from other schema.
|
|
65
|
+
*/
|
|
66
|
+
if (schemaElement.hasKey('example')) {
|
|
67
|
+
const member = allOfMerged.getMember('example');
|
|
68
|
+
if (member) {
|
|
69
|
+
member.value = schemaElement.get('example');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
64
72
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
/**
|
|
74
|
+
* If there was an examples keyword in the original schema,
|
|
75
|
+
* keep it instead of merging with examples from other schema.
|
|
76
|
+
*/
|
|
77
|
+
if (schemaElement.hasKey('examples')) {
|
|
78
|
+
const member = allOfMerged.getMember('examples');
|
|
79
|
+
if (member) {
|
|
80
|
+
member.value = schemaElement.get('examples');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
schemaElement.content = allOfMerged.content;
|
|
72
84
|
}
|
|
73
|
-
|
|
74
|
-
// remove allOf keyword after the merge
|
|
75
|
-
mergedSchemaElement.remove('allOf');
|
|
76
|
-
return mergedSchemaElement;
|
|
85
|
+
return undefined;
|
|
77
86
|
}
|
|
78
87
|
}
|
|
79
88
|
}
|