swagger-client 3.22.2 → 3.23.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 +1521 -2260
- package/dist/swagger-client.browser.min.js +1 -1
- package/dist/swagger-client.browser.min.js.map +1 -1
- package/es/constants.js +2 -2
- package/es/execute/index.js +2 -1
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/to-path.js +2 -2
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +2 -2
- package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +168 -146
- package/es/resolver/strategies/openapi-3-1-apidom/resolve.js +2 -1
- package/es/specmap/helpers.js +4 -3
- package/lib/constants.js +3 -4
- package/lib/execute/index.js +3 -3
- package/lib/execute/swagger2/parameter-builders.js +1 -2
- package/lib/helpers/btoa.browser.js +1 -2
- package/lib/helpers/btoa.node.js +1 -2
- package/lib/helpers/fetch-ponyfill-undici.node.js +1 -2
- package/lib/helpers/replace-special-chars-with-underscore.js +1 -2
- package/lib/http/index.js +1 -2
- package/lib/index.js +2 -3
- package/lib/interfaces.js +1 -2
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/errors/index.js +2 -3
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +2 -3
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/compose.js +2 -3
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/get-root-cause.js +1 -2
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/to-path.js +2 -3
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +2 -3
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +169 -148
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +1 -2
- package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +1 -2
- package/lib/resolver/apidom/reference/parse/parsers/json/index.js +1 -2
- package/lib/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js +2 -3
- package/lib/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +2 -3
- package/lib/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +1 -2
- package/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +1 -2
- package/lib/resolver/index.js +2 -3
- package/lib/resolver/strategies/generic/index.js +1 -2
- package/lib/resolver/strategies/openapi-2/index.js +1 -2
- package/lib/resolver/strategies/openapi-3-0/index.js +1 -2
- package/lib/resolver/strategies/openapi-3-1-apidom/index.js +1 -2
- package/lib/resolver/strategies/openapi-3-1-apidom/normalize.js +2 -3
- package/lib/resolver/strategies/openapi-3-1-apidom/resolve.js +4 -4
- package/lib/specmap/helpers.js +4 -3
- package/lib/specmap/index.js +2 -3
- package/lib/specmap/lib/all-of.js +2 -3
- package/lib/specmap/lib/index.js +1 -2
- package/lib/specmap/lib/parameters.js +2 -3
- package/lib/specmap/lib/properties.js +2 -3
- package/lib/specmap/lib/refs.js +1 -2
- package/lib/subtree-resolver/index.js +2 -3
- package/package.json +8 -8
|
@@ -37,53 +37,47 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
37
37
|
this.basePath = basePath;
|
|
38
38
|
},
|
|
39
39
|
methods: {
|
|
40
|
-
async ReferenceElement(
|
|
40
|
+
async ReferenceElement(referencingElement, key, parent, path, ancestors) {
|
|
41
41
|
try {
|
|
42
|
-
var _this$basePath
|
|
42
|
+
var _this$basePath;
|
|
43
43
|
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
|
|
44
44
|
|
|
45
|
-
// skip already identified cycled Path Item Objects
|
|
46
|
-
if ((0, _apidomCore.includesClasses)(['cycle'], referenceElement.$ref)) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
45
|
// detect possible cycle in traversal and avoid it
|
|
51
|
-
if (ancestorsLineage.
|
|
52
|
-
// skip processing this schema and all it's child schemas
|
|
46
|
+
if (ancestorsLineage.includesCycle(referencingElement)) {
|
|
53
47
|
return false;
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
// ignore resolving external Reference Objects
|
|
57
|
-
if (!this.options.resolve.external && (0, _apidomNsOpenapi.isReferenceElementExternal)(
|
|
51
|
+
if (!this.options.resolve.external && (0, _apidomNsOpenapi.isReferenceElementExternal)(referencingElement)) {
|
|
58
52
|
return false;
|
|
59
53
|
}
|
|
60
|
-
const reference = await this.toReference(
|
|
54
|
+
const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
|
|
61
55
|
const {
|
|
62
56
|
uri: retrievalURI
|
|
63
57
|
} = reference;
|
|
64
|
-
const $refBaseURI = _empty.url.resolve(retrievalURI,
|
|
65
|
-
this.indirections.push(
|
|
58
|
+
const $refBaseURI = _empty.url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
|
|
59
|
+
this.indirections.push(referencingElement);
|
|
66
60
|
const jsonPointer = (0, _apidomJsonPointer.uriToPointer)($refBaseURI);
|
|
67
61
|
|
|
68
62
|
// possibly non-semantic fragment
|
|
69
|
-
let
|
|
63
|
+
let referencedElement = (0, _apidomJsonPointer.evaluate)(jsonPointer, reference.value.result);
|
|
70
64
|
|
|
71
65
|
// applying semantics to a fragment
|
|
72
|
-
if ((0, _apidomCore.isPrimitiveElement)(
|
|
73
|
-
const referencedElementType =
|
|
74
|
-
if ((0, _apidomNsOpenapi.isReferenceLikeElement)(
|
|
66
|
+
if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
|
|
67
|
+
const referencedElementType = (0, _apidomCore.toValue)(referencingElement.meta.get('referenced-element'));
|
|
68
|
+
if ((0, _apidomNsOpenapi.isReferenceLikeElement)(referencedElement)) {
|
|
75
69
|
// handling indirect references
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
referencedElement = _apidomNsOpenapi.ReferenceElement.refract(referencedElement);
|
|
71
|
+
referencedElement.setMetaProperty('referenced-element', referencedElementType);
|
|
78
72
|
} else {
|
|
79
73
|
// handling direct references
|
|
80
74
|
const ElementClass = this.namespace.getElementClass(referencedElementType);
|
|
81
|
-
|
|
75
|
+
referencedElement = ElementClass.refract(referencedElement);
|
|
82
76
|
}
|
|
83
77
|
}
|
|
84
78
|
|
|
85
79
|
// detect direct or indirect reference
|
|
86
|
-
if (this.indirections.includes(
|
|
80
|
+
if (this.indirections.includes(referencedElement)) {
|
|
87
81
|
throw new Error('Recursive JSON Pointer detected');
|
|
88
82
|
}
|
|
89
83
|
|
|
@@ -92,23 +86,21 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
92
86
|
throw new _empty.MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
|
|
93
87
|
}
|
|
94
88
|
if (!this.useCircularStructures) {
|
|
95
|
-
const hasCycles = ancestorsLineage.
|
|
89
|
+
const hasCycles = ancestorsLineage.includes(referencedElement);
|
|
96
90
|
if (hasCycles) {
|
|
97
91
|
if (_empty.url.isHttpUrl(retrievalURI) || _empty.url.isFileSystemPath(retrievalURI)) {
|
|
98
92
|
// make the referencing URL or file system path absolute
|
|
99
|
-
|
|
93
|
+
return new _apidomNsOpenapi.ReferenceElement({
|
|
100
94
|
$ref: $refBaseURI
|
|
101
|
-
},
|
|
102
|
-
cycledReferenceElement.get('$ref').classes.push('cycle');
|
|
103
|
-
return cycledReferenceElement;
|
|
95
|
+
}, (0, _apidomCore.cloneDeep)(referencingElement.meta), (0, _apidomCore.cloneDeep)(referencingElement.attributes));
|
|
104
96
|
}
|
|
105
|
-
// skip processing this
|
|
97
|
+
// skip processing this reference
|
|
106
98
|
return false;
|
|
107
99
|
}
|
|
108
100
|
}
|
|
109
101
|
|
|
110
102
|
// append referencing schema to ancestors lineage
|
|
111
|
-
directAncestors.add(
|
|
103
|
+
directAncestors.add(referencingElement);
|
|
112
104
|
|
|
113
105
|
// dive deep into the fragment
|
|
114
106
|
const visitor = OpenApi3_1SwaggerClientDereferenceVisitor({
|
|
@@ -119,55 +111,78 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
119
111
|
ancestors: ancestorsLineage,
|
|
120
112
|
allowMetaPatches: this.allowMetaPatches,
|
|
121
113
|
useCircularStructures: this.useCircularStructures,
|
|
122
|
-
basePath: (_this$basePath = this.basePath) != null ? _this$basePath : [...(0, _toPath.default)([...ancestors, parent,
|
|
114
|
+
basePath: (_this$basePath = this.basePath) != null ? _this$basePath : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
|
|
123
115
|
});
|
|
124
|
-
|
|
116
|
+
referencedElement = await visitAsync(referencedElement, visitor, {
|
|
125
117
|
keyMap: _apidomNsOpenapi.keyMap,
|
|
126
118
|
nodeTypeGetter: _apidomNsOpenapi.getNodeType
|
|
127
119
|
});
|
|
128
120
|
|
|
129
121
|
// remove referencing schema from ancestors lineage
|
|
130
|
-
directAncestors.delete(
|
|
122
|
+
directAncestors.delete(referencingElement);
|
|
131
123
|
this.indirections.pop();
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
124
|
+
const mergeAndAnnotateReferencedElement = refedElement => {
|
|
125
|
+
const copy = (0, _apidomCore.cloneShallow)(refedElement);
|
|
126
|
+
|
|
127
|
+
// annotate fragment with info about original Reference element
|
|
128
|
+
copy.setMetaProperty('ref-fields', {
|
|
129
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref),
|
|
130
|
+
// @ts-ignore
|
|
131
|
+
description: (0, _apidomCore.toValue)(referencingElement.description),
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
summary: (0, _apidomCore.toValue)(referencingElement.summary)
|
|
134
|
+
});
|
|
135
|
+
// annotate fragment with info about origin
|
|
136
|
+
copy.setMetaProperty('ref-origin', reference.uri);
|
|
137
|
+
|
|
138
|
+
// override description and summary (outer has higher priority then inner)
|
|
139
|
+
if ((0, _apidomCore.isObjectElement)(refedElement)) {
|
|
140
|
+
if (referencingElement.hasKey('description') && 'description' in refedElement) {
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
copy.remove('description');
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
copy.set('description', referencingElement.get('description'));
|
|
145
|
+
}
|
|
146
|
+
if (referencingElement.hasKey('summary') && 'summary' in refedElement) {
|
|
147
|
+
// @ts-ignore
|
|
148
|
+
copy.remove('summary');
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
copy.set('summary', referencingElement.get('summary'));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
150
153
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
// apply meta patches
|
|
155
|
+
if (this.allowMetaPatches && (0, _apidomCore.isObjectElement)(copy)) {
|
|
156
|
+
// apply meta patch only when not already applied
|
|
157
|
+
if (!copy.hasKey('$$ref')) {
|
|
158
|
+
const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
|
|
159
|
+
copy.set('$$ref', baseURI);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return copy;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// attempting to create cycle
|
|
166
|
+
if (ancestorsLineage.includes(referencedElement)) {
|
|
167
|
+
if ((0, _apidomCore.isMemberElement)(parent)) {
|
|
168
|
+
parent.value = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
|
|
169
|
+
} else if (Array.isArray(parent)) {
|
|
170
|
+
parent[key] = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
|
|
158
171
|
}
|
|
172
|
+
|
|
173
|
+
return false;
|
|
159
174
|
}
|
|
160
175
|
|
|
161
176
|
// transclude the element for a fragment
|
|
162
|
-
return
|
|
177
|
+
return mergeAndAnnotateReferencedElement(referencedElement);
|
|
163
178
|
} catch (error) {
|
|
164
179
|
var _this$basePath2, _this$options$derefer;
|
|
165
180
|
const rootCause = (0, _getRootCause.default)(error);
|
|
166
181
|
const wrappedError = wrapError(rootCause, {
|
|
167
182
|
baseDoc: this.reference.uri,
|
|
168
|
-
$ref:
|
|
169
|
-
pointer: (0, _apidomJsonPointer.uriToPointer)(
|
|
170
|
-
fullPath: (_this$basePath2 = this.basePath) != null ? _this$basePath2 : [...(0, _toPath.default)([...ancestors, parent,
|
|
183
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref),
|
|
184
|
+
pointer: (0, _apidomJsonPointer.uriToPointer)((0, _apidomCore.toValue)(referencingElement.$ref)),
|
|
185
|
+
fullPath: (_this$basePath2 = this.basePath) != null ? _this$basePath2 : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
|
|
171
186
|
});
|
|
172
187
|
(_this$options$derefer = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer = _this$options$derefer.errors) == null || _this$options$derefer.push == null || _this$options$derefer.push(wrappedError);
|
|
173
188
|
return undefined;
|
|
@@ -175,7 +190,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
175
190
|
},
|
|
176
191
|
async PathItemElement(pathItemElement, key, parent, path, ancestors) {
|
|
177
192
|
try {
|
|
178
|
-
var _this$basePath3
|
|
193
|
+
var _this$basePath3;
|
|
179
194
|
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
|
|
180
195
|
|
|
181
196
|
// ignore PathItemElement without $ref field
|
|
@@ -183,14 +198,8 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
183
198
|
return undefined;
|
|
184
199
|
}
|
|
185
200
|
|
|
186
|
-
// skip already identified cycled Path Item Objects
|
|
187
|
-
if ((0, _apidomCore.includesClasses)(['cycle'], pathItemElement.$ref)) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
201
|
// detect possible cycle in traversal and avoid it
|
|
192
|
-
if (ancestorsLineage.
|
|
193
|
-
// skip processing this schema and all it's child schemas
|
|
202
|
+
if (ancestorsLineage.includesCycle(pathItemElement)) {
|
|
194
203
|
return false;
|
|
195
204
|
}
|
|
196
205
|
|
|
@@ -198,11 +207,11 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
198
207
|
if (!this.options.resolve.external && (0, _apidomNsOpenapi.isPathItemElementExternal)(pathItemElement)) {
|
|
199
208
|
return undefined;
|
|
200
209
|
}
|
|
201
|
-
const reference = await this.toReference(pathItemElement.$ref
|
|
210
|
+
const reference = await this.toReference((0, _apidomCore.toValue)(pathItemElement.$ref));
|
|
202
211
|
const {
|
|
203
212
|
uri: retrievalURI
|
|
204
213
|
} = reference;
|
|
205
|
-
const $refBaseURI = _empty.url.resolve(retrievalURI, pathItemElement.$ref
|
|
214
|
+
const $refBaseURI = _empty.url.resolve(retrievalURI, (0, _apidomCore.toValue)(pathItemElement.$ref));
|
|
206
215
|
this.indirections.push(pathItemElement);
|
|
207
216
|
const jsonPointer = (0, _apidomJsonPointer.uriToPointer)($refBaseURI);
|
|
208
217
|
|
|
@@ -224,17 +233,15 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
224
233
|
throw new _empty.MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
|
|
225
234
|
}
|
|
226
235
|
if (!this.useCircularStructures) {
|
|
227
|
-
const hasCycles = ancestorsLineage.
|
|
236
|
+
const hasCycles = ancestorsLineage.includes(referencedElement);
|
|
228
237
|
if (hasCycles) {
|
|
229
238
|
if (_empty.url.isHttpUrl(retrievalURI) || _empty.url.isFileSystemPath(retrievalURI)) {
|
|
230
239
|
// make the referencing URL or file system path absolute
|
|
231
|
-
|
|
240
|
+
return new _apidomNsOpenapi.PathItemElement({
|
|
232
241
|
$ref: $refBaseURI
|
|
233
|
-
}, pathItemElement.meta
|
|
234
|
-
cycledPathItemElement.get('$ref').classes.push('cycle');
|
|
235
|
-
return cycledPathItemElement;
|
|
242
|
+
}, (0, _apidomCore.cloneDeep)(pathItemElement.meta), (0, _apidomCore.cloneDeep)(pathItemElement.attributes));
|
|
236
243
|
}
|
|
237
|
-
// skip processing this
|
|
244
|
+
// skip processing this path item and all it's child elements
|
|
238
245
|
return false;
|
|
239
246
|
}
|
|
240
247
|
}
|
|
@@ -261,41 +268,54 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
261
268
|
// remove referencing schema from ancestors lineage
|
|
262
269
|
directAncestors.delete(pathItemElement);
|
|
263
270
|
this.indirections.pop();
|
|
271
|
+
const mergeAndAnnotateReferencedElement = refedElement => {
|
|
272
|
+
// merge fields from referenced Path Item with referencing one
|
|
273
|
+
const mergedElement = new _apidomNsOpenapi.PathItemElement([...refedElement.content], (0, _apidomCore.cloneDeep)(refedElement.meta), (0, _apidomCore.cloneDeep)(refedElement.attributes));
|
|
274
|
+
// existing keywords from referencing PathItemElement overrides ones from referenced element
|
|
275
|
+
pathItemElement.forEach((value, keyElement, item) => {
|
|
276
|
+
mergedElement.remove((0, _apidomCore.toValue)(keyElement));
|
|
277
|
+
mergedElement.content.push(item);
|
|
278
|
+
});
|
|
279
|
+
mergedElement.remove('$ref');
|
|
264
280
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
});
|
|
272
|
-
mergedPathItemElement.remove('$ref');
|
|
281
|
+
// annotate referenced element with info about original referencing element
|
|
282
|
+
mergedElement.setMetaProperty('ref-fields', {
|
|
283
|
+
$ref: (0, _apidomCore.toValue)(pathItemElement.$ref)
|
|
284
|
+
});
|
|
285
|
+
// annotate referenced element with info about origin
|
|
286
|
+
mergedElement.setMetaProperty('ref-origin', reference.uri);
|
|
273
287
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
288
|
+
// apply meta patches
|
|
289
|
+
if (this.allowMetaPatches) {
|
|
290
|
+
// apply meta patch only when not already applied
|
|
291
|
+
if (typeof mergedElement.get('$$ref') === 'undefined') {
|
|
292
|
+
const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
|
|
293
|
+
mergedElement.set('$$ref', baseURI);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return mergedElement;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// attempting to create cycle
|
|
300
|
+
if (ancestorsLineage.includes(referencedElement)) {
|
|
301
|
+
if ((0, _apidomCore.isMemberElement)(parent)) {
|
|
302
|
+
parent.value = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
|
|
303
|
+
} else if (Array.isArray(parent)) {
|
|
304
|
+
parent[key] = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
|
|
287
305
|
}
|
|
306
|
+
|
|
307
|
+
return false;
|
|
288
308
|
}
|
|
289
309
|
|
|
290
310
|
// transclude referencing element with merged referenced element
|
|
291
|
-
return
|
|
311
|
+
return mergeAndAnnotateReferencedElement(referencedElement);
|
|
292
312
|
} catch (error) {
|
|
293
313
|
var _this$basePath4, _this$options$derefer2;
|
|
294
314
|
const rootCause = (0, _getRootCause.default)(error);
|
|
295
315
|
const wrappedError = wrapError(rootCause, {
|
|
296
316
|
baseDoc: this.reference.uri,
|
|
297
|
-
$ref: pathItemElement.$ref
|
|
298
|
-
pointer: (0, _apidomJsonPointer.uriToPointer)(pathItemElement.$ref
|
|
317
|
+
$ref: (0, _apidomCore.toValue)(pathItemElement.$ref),
|
|
318
|
+
pointer: (0, _apidomJsonPointer.uriToPointer)((0, _apidomCore.toValue)(pathItemElement.$ref)),
|
|
299
319
|
fullPath: (_this$basePath4 = this.basePath) != null ? _this$basePath4 : [...(0, _toPath.default)([...ancestors, parent, pathItemElement]), '$ref']
|
|
300
320
|
});
|
|
301
321
|
(_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(wrappedError);
|
|
@@ -304,7 +324,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
304
324
|
},
|
|
305
325
|
async SchemaElement(referencingElement, key, parent, path, ancestors) {
|
|
306
326
|
try {
|
|
307
|
-
var _this$basePath5
|
|
327
|
+
var _this$basePath5;
|
|
308
328
|
const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
|
|
309
329
|
|
|
310
330
|
// skip current referencing schema as $ref keyword was not defined
|
|
@@ -313,14 +333,8 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
313
333
|
return undefined;
|
|
314
334
|
}
|
|
315
335
|
|
|
316
|
-
// skip already identified cycled schemas
|
|
317
|
-
if ((0, _apidomCore.includesClasses)(['cycle'], referencingElement.$ref)) {
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
336
|
// detect possible cycle in traversal and avoid it
|
|
322
|
-
if (ancestorsLineage.
|
|
323
|
-
// skip processing this schema and all it's child schemas
|
|
337
|
+
if (ancestorsLineage.includesCycle(referencingElement)) {
|
|
324
338
|
return false;
|
|
325
339
|
}
|
|
326
340
|
|
|
@@ -400,11 +414,9 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
400
414
|
if (_empty.url.isHttpUrl(retrievalURI) || _empty.url.isFileSystemPath(retrievalURI)) {
|
|
401
415
|
// make the referencing URL or file system path absolute
|
|
402
416
|
const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
|
|
403
|
-
|
|
417
|
+
return new _apidomNsOpenapi.SchemaElement({
|
|
404
418
|
$ref: baseURI
|
|
405
|
-
}, referencingElement.meta
|
|
406
|
-
cycledSchemaElement.get('$ref').classes.push('cycle');
|
|
407
|
-
return cycledSchemaElement;
|
|
419
|
+
}, (0, _apidomCore.cloneDeep)(referencingElement.meta), (0, _apidomCore.cloneDeep)(referencingElement.attributes));
|
|
408
420
|
}
|
|
409
421
|
// skip processing this schema and all it's child schemas
|
|
410
422
|
return false;
|
|
@@ -434,51 +446,61 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
434
446
|
directAncestors.delete(referencingElement);
|
|
435
447
|
this.indirections.pop();
|
|
436
448
|
if ((0, _apidomNsOpenapi.isBooleanJsonSchemaElement)(referencedElement)) {
|
|
437
|
-
|
|
438
|
-
// Boolean JSON Schema
|
|
439
|
-
const jsonSchemaBooleanElement = referencedElement.clone();
|
|
449
|
+
const booleanJsonSchemaElement = (0, _apidomCore.cloneDeep)(referencedElement);
|
|
440
450
|
// annotate referenced element with info about original referencing element
|
|
441
|
-
|
|
442
|
-
$ref: (
|
|
451
|
+
booleanJsonSchemaElement.setMetaProperty('ref-fields', {
|
|
452
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref)
|
|
443
453
|
});
|
|
444
454
|
// annotate referenced element with info about origin
|
|
445
|
-
|
|
446
|
-
return
|
|
455
|
+
booleanJsonSchemaElement.setMetaProperty('ref-origin', reference.uri);
|
|
456
|
+
return booleanJsonSchemaElement;
|
|
447
457
|
}
|
|
458
|
+
const mergeAndAnnotateReferencedElement = refedElement => {
|
|
459
|
+
// Schema Object - merge keywords from referenced schema with referencing schema
|
|
460
|
+
const mergedElement = new _apidomNsOpenapi.SchemaElement([...refedElement.content], (0, _apidomCore.cloneDeep)(refedElement.meta), (0, _apidomCore.cloneDeep)(refedElement.attributes));
|
|
461
|
+
// existing keywords from referencing schema overrides ones from referenced schema
|
|
462
|
+
referencingElement.forEach((value, keyElement, item) => {
|
|
463
|
+
mergedElement.remove((0, _apidomCore.toValue)(keyElement));
|
|
464
|
+
mergedElement.content.push(item);
|
|
465
|
+
});
|
|
466
|
+
mergedElement.remove('$ref');
|
|
467
|
+
// annotate referenced element with info about original referencing element
|
|
468
|
+
mergedElement.setMetaProperty('ref-fields', {
|
|
469
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref)
|
|
470
|
+
});
|
|
471
|
+
// annotate fragment with info about origin
|
|
472
|
+
mergedElement.setMetaProperty('ref-origin', reference.uri);
|
|
448
473
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
mergedSchemaElement.remove('$ref');
|
|
457
|
-
|
|
458
|
-
// annotate referenced element with info about original referencing element
|
|
459
|
-
mergedSchemaElement.setMetaProperty('ref-fields', {
|
|
460
|
-
$ref: (_referencingElement$$2 = referencingElement.$ref) == null ? void 0 : _referencingElement$$2.toValue()
|
|
461
|
-
});
|
|
462
|
-
// annotate fragment with info about origin
|
|
463
|
-
mergedSchemaElement.setMetaProperty('ref-origin', retrievalURI);
|
|
464
|
-
|
|
465
|
-
// allowMetaPatches option processing
|
|
466
|
-
if (this.allowMetaPatches) {
|
|
467
|
-
// apply meta patch only when not already applied
|
|
468
|
-
if (typeof mergedSchemaElement.get('$$ref') === 'undefined') {
|
|
469
|
-
const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
|
|
470
|
-
mergedSchemaElement.set('$$ref', baseURI);
|
|
474
|
+
// allowMetaPatches option processing
|
|
475
|
+
if (this.allowMetaPatches) {
|
|
476
|
+
// apply meta patch only when not already applied
|
|
477
|
+
if (typeof mergedElement.get('$$ref') === 'undefined') {
|
|
478
|
+
const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
|
|
479
|
+
mergedElement.set('$$ref', baseURI);
|
|
480
|
+
}
|
|
471
481
|
}
|
|
482
|
+
return mergedElement;
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// attempting to create cycle
|
|
486
|
+
if (ancestorsLineage.includes(referencedElement)) {
|
|
487
|
+
if ((0, _apidomCore.isMemberElement)(parent)) {
|
|
488
|
+
parent.value = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
|
|
489
|
+
} else if (Array.isArray(parent)) {
|
|
490
|
+
parent[key] = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return false;
|
|
472
494
|
}
|
|
473
495
|
|
|
474
496
|
// transclude referencing element with merged referenced element
|
|
475
|
-
return
|
|
497
|
+
return mergeAndAnnotateReferencedElement(referencedElement);
|
|
476
498
|
} catch (error) {
|
|
477
499
|
var _this$basePath6, _this$options$derefer3;
|
|
478
500
|
const rootCause = (0, _getRootCause.default)(error);
|
|
479
501
|
const wrappedError = new _index.SchemaRefError(`Could not resolve reference: ${rootCause.message}`, {
|
|
480
502
|
baseDoc: this.reference.uri,
|
|
481
|
-
$ref: referencingElement.$ref
|
|
503
|
+
$ref: (0, _apidomCore.toValue)(referencingElement.$ref),
|
|
482
504
|
fullPath: (_this$basePath6 = this.basePath) != null ? _this$basePath6 : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
|
|
483
505
|
}, rootCause);
|
|
484
506
|
(_this$options$derefer3 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer3 = _this$options$derefer3.errors) == null || _this$options$derefer3.push == null || _this$options$derefer3.push(wrappedError);
|
|
@@ -497,11 +519,11 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
497
519
|
try {
|
|
498
520
|
return await _openapi.OpenApi3_1DereferenceVisitor.compose.methods.ExampleElement.call(this, exampleElement, key, parent, path, ancestors);
|
|
499
521
|
} catch (error) {
|
|
500
|
-
var
|
|
522
|
+
var _this$basePath7, _this$options$derefer4;
|
|
501
523
|
const rootCause = (0, _getRootCause.default)(error);
|
|
502
524
|
const wrappedError = wrapError(rootCause, {
|
|
503
525
|
baseDoc: this.reference.uri,
|
|
504
|
-
externalValue: (
|
|
526
|
+
externalValue: (0, _apidomCore.toValue)(exampleElement.externalValue),
|
|
505
527
|
fullPath: (_this$basePath7 = this.basePath) != null ? _this$basePath7 : [...(0, _toPath.default)([...ancestors, parent, exampleElement]), 'externalValue']
|
|
506
528
|
});
|
|
507
529
|
(_this$options$derefer4 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer4 = _this$options$derefer4.errors) == null || _this$options$derefer4.push == null || _this$options$derefer4.push(wrappedError);
|
|
@@ -510,6 +532,5 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
|
|
|
510
532
|
}
|
|
511
533
|
}
|
|
512
534
|
});
|
|
513
|
-
var _default = OpenApi3_1SwaggerClientDereferenceVisitor;
|
|
514
|
-
/* eslint-enable camelcase */
|
|
515
|
-
exports.default = _default;
|
|
535
|
+
var _default = exports.default = OpenApi3_1SwaggerClientDereferenceVisitor;
|
|
536
|
+
/* eslint-enable camelcase */
|
|
@@ -56,6 +56,5 @@ const OpenApiJson3_1Parser = _empty.Parser.compose({
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
});
|
|
59
|
-
var _default = OpenApiJson3_1Parser;
|
|
60
|
-
/* eslint-enable camelcase */
|
|
61
|
-
exports.default = _default;
|
|
59
|
+
var _default = exports.default = OpenApiJson3_1Parser;
|
|
60
|
+
/* eslint-enable camelcase */
|
|
@@ -58,6 +58,5 @@ const OpenApiYaml3_1Parser = _empty.Parser.compose({
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
var _default = OpenApiYaml3_1Parser;
|
|
62
|
-
/* eslint-enable camelcase */
|
|
63
|
-
exports.default = _default;
|
|
61
|
+
var _default = exports.default = OpenApiYaml3_1Parser;
|
|
62
|
+
/* eslint-enable camelcase */
|
package/lib/resolver/index.js
CHANGED
|
@@ -36,7 +36,6 @@ const makeResolve = defaultOptions => async options => {
|
|
|
36
36
|
return resolve(mergedOptions);
|
|
37
37
|
};
|
|
38
38
|
exports.makeResolve = makeResolve;
|
|
39
|
-
var _default = makeResolve({
|
|
39
|
+
var _default = exports.default = makeResolve({
|
|
40
40
|
strategies: [_index4.default, _index3.default, _index2.default]
|
|
41
|
-
});
|
|
42
|
-
exports.default = _default;
|
|
41
|
+
});
|
|
@@ -45,6 +45,5 @@ const pojoAdapter = normalizeFn => spec => {
|
|
|
45
45
|
};
|
|
46
46
|
exports.pojoAdapter = pojoAdapter;
|
|
47
47
|
pojoAdapter.cache = new WeakMap();
|
|
48
|
-
var _default = normalize;
|
|
49
|
-
/* eslint-enable camelcase */
|
|
50
|
-
exports.default = _default;
|
|
48
|
+
var _default = exports.default = normalize;
|
|
49
|
+
/* eslint-enable camelcase */
|