swagger-client 3.22.3 → 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.
Files changed (45) hide show
  1. package/dist/swagger-client.browser.js +1467 -2213
  2. package/dist/swagger-client.browser.min.js +1 -1
  3. package/dist/swagger-client.browser.min.js.map +1 -1
  4. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/to-path.js +2 -2
  5. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +2 -2
  6. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +168 -146
  7. package/lib/constants.js +2 -4
  8. package/lib/execute/index.js +1 -2
  9. package/lib/execute/swagger2/parameter-builders.js +1 -2
  10. package/lib/helpers/btoa.browser.js +1 -2
  11. package/lib/helpers/btoa.node.js +1 -2
  12. package/lib/helpers/fetch-ponyfill-undici.node.js +1 -2
  13. package/lib/helpers/replace-special-chars-with-underscore.js +1 -2
  14. package/lib/http/index.js +1 -2
  15. package/lib/index.js +2 -3
  16. package/lib/interfaces.js +1 -2
  17. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/errors/index.js +2 -3
  18. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +2 -3
  19. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/compose.js +2 -3
  20. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/get-root-cause.js +1 -2
  21. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/to-path.js +2 -3
  22. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +2 -3
  23. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +169 -148
  24. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +1 -2
  25. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +1 -2
  26. package/lib/resolver/apidom/reference/parse/parsers/json/index.js +1 -2
  27. package/lib/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js +2 -3
  28. package/lib/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +2 -3
  29. package/lib/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +1 -2
  30. package/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +1 -2
  31. package/lib/resolver/index.js +2 -3
  32. package/lib/resolver/strategies/generic/index.js +1 -2
  33. package/lib/resolver/strategies/openapi-2/index.js +1 -2
  34. package/lib/resolver/strategies/openapi-3-0/index.js +1 -2
  35. package/lib/resolver/strategies/openapi-3-1-apidom/index.js +1 -2
  36. package/lib/resolver/strategies/openapi-3-1-apidom/normalize.js +2 -3
  37. package/lib/resolver/strategies/openapi-3-1-apidom/resolve.js +2 -3
  38. package/lib/specmap/index.js +2 -3
  39. package/lib/specmap/lib/all-of.js +2 -3
  40. package/lib/specmap/lib/index.js +1 -2
  41. package/lib/specmap/lib/parameters.js +2 -3
  42. package/lib/specmap/lib/properties.js +2 -3
  43. package/lib/specmap/lib/refs.js +1 -2
  44. package/lib/subtree-resolver/index.js +2 -3
  45. package/package.json +8 -8
@@ -1,4 +1,4 @@
1
- import { isMemberElement, isArrayElement } from '@swagger-api/apidom-core';
1
+ import { isMemberElement, isArrayElement, toValue } from '@swagger-api/apidom-core';
2
2
  const trimParseResult = elementPath => elementPath.slice(2);
3
3
 
4
4
  /**
@@ -11,7 +11,7 @@ const toPath = elementPath => {
11
11
  const elementPathSanitized = trimParseResult(elementPath);
12
12
  return elementPathSanitized.reduce((path, element, index) => {
13
13
  if (isMemberElement(element)) {
14
- const token = String(element.key.toValue());
14
+ const token = String(toValue(element.key));
15
15
  path.push(token);
16
16
  } else if (isArrayElement(elementPathSanitized[index - 2])) {
17
17
  const token = elementPathSanitized[index - 2].content.indexOf(element);
@@ -1,4 +1,4 @@
1
- import { isArrayElement, deepmerge } from '@swagger-api/apidom-core';
1
+ import { isArrayElement, deepmerge, cloneDeep, toValue } from '@swagger-api/apidom-core';
2
2
  import { isSchemaElement, SchemaElement } from '@swagger-api/apidom-ns-openapi-3-1';
3
3
  import compose from '../utils/compose.js';
4
4
  import toPath from '../utils/to-path.js';
@@ -27,7 +27,7 @@ const AllOfVisitor = compose({
27
27
 
28
28
  // remove allOf keyword if empty
29
29
  if (schemaElement.allOf.isEmpty) {
30
- return new SchemaElement(schemaElement.content.filter(memberElement => memberElement.key.toValue() !== 'allOf'), schemaElement.meta.clone(), schemaElement.attributes.clone());
30
+ return new SchemaElement(schemaElement.content.filter(memberElement => toValue(memberElement.key) !== 'allOf'), cloneDeep(schemaElement.meta), cloneDeep(schemaElement.attributes));
31
31
  }
32
32
 
33
33
  // collect errors if allOf keyword contains anything else than Schema Object
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable camelcase */
2
- import { isObjectElement, isPrimitiveElement, isStringElement, visit, includesClasses } from '@swagger-api/apidom-core';
2
+ import { isObjectElement, isPrimitiveElement, isStringElement, isMemberElement, visit, toValue, cloneShallow, cloneDeep } from '@swagger-api/apidom-core';
3
3
  import { isReferenceElementExternal, isReferenceLikeElement, isPathItemElementExternal, isBooleanJsonSchemaElement, ReferenceElement, PathItemElement, SchemaElement, getNodeType, keyMap } from '@swagger-api/apidom-ns-openapi-3-1';
4
4
  import { evaluate as jsonPointerEvaluate, uriToPointer } from '@swagger-api/apidom-json-pointer';
5
5
  import { url, MaximumDereferenceDepthError, File } from '@swagger-api/apidom-reference/configuration/empty';
@@ -31,53 +31,47 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
31
31
  this.basePath = basePath;
32
32
  },
33
33
  methods: {
34
- async ReferenceElement(referenceElement, key, parent, path, ancestors) {
34
+ async ReferenceElement(referencingElement, key, parent, path, ancestors) {
35
35
  try {
36
- var _this$basePath, _referenceElement$$re, _referenceElement$des, _referenceElement$sum;
36
+ var _this$basePath;
37
37
  const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
38
38
 
39
- // skip already identified cycled Path Item Objects
40
- if (includesClasses(['cycle'], referenceElement.$ref)) {
41
- return false;
42
- }
43
-
44
39
  // detect possible cycle in traversal and avoid it
45
- if (ancestorsLineage.some(ancs => ancs.has(referenceElement))) {
46
- // skip processing this schema and all it's child schemas
40
+ if (ancestorsLineage.includesCycle(referencingElement)) {
47
41
  return false;
48
42
  }
49
43
 
50
44
  // ignore resolving external Reference Objects
51
- if (!this.options.resolve.external && isReferenceElementExternal(referenceElement)) {
45
+ if (!this.options.resolve.external && isReferenceElementExternal(referencingElement)) {
52
46
  return false;
53
47
  }
54
- const reference = await this.toReference(referenceElement.$ref.toValue());
48
+ const reference = await this.toReference(toValue(referencingElement.$ref));
55
49
  const {
56
50
  uri: retrievalURI
57
51
  } = reference;
58
- const $refBaseURI = url.resolve(retrievalURI, referenceElement.$ref.toValue());
59
- this.indirections.push(referenceElement);
52
+ const $refBaseURI = url.resolve(retrievalURI, toValue(referencingElement.$ref));
53
+ this.indirections.push(referencingElement);
60
54
  const jsonPointer = uriToPointer($refBaseURI);
61
55
 
62
56
  // possibly non-semantic fragment
63
- let fragment = jsonPointerEvaluate(jsonPointer, reference.value.result);
57
+ let referencedElement = jsonPointerEvaluate(jsonPointer, reference.value.result);
64
58
 
65
59
  // applying semantics to a fragment
66
- if (isPrimitiveElement(fragment)) {
67
- const referencedElementType = referenceElement.meta.get('referenced-element').toValue();
68
- if (isReferenceLikeElement(fragment)) {
60
+ if (isPrimitiveElement(referencedElement)) {
61
+ const referencedElementType = toValue(referencingElement.meta.get('referenced-element'));
62
+ if (isReferenceLikeElement(referencedElement)) {
69
63
  // handling indirect references
70
- fragment = ReferenceElement.refract(fragment);
71
- fragment.setMetaProperty('referenced-element', referencedElementType);
64
+ referencedElement = ReferenceElement.refract(referencedElement);
65
+ referencedElement.setMetaProperty('referenced-element', referencedElementType);
72
66
  } else {
73
67
  // handling direct references
74
68
  const ElementClass = this.namespace.getElementClass(referencedElementType);
75
- fragment = ElementClass.refract(fragment);
69
+ referencedElement = ElementClass.refract(referencedElement);
76
70
  }
77
71
  }
78
72
 
79
73
  // detect direct or indirect reference
80
- if (this.indirections.includes(fragment)) {
74
+ if (this.indirections.includes(referencedElement)) {
81
75
  throw new Error('Recursive JSON Pointer detected');
82
76
  }
83
77
 
@@ -86,23 +80,21 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
86
80
  throw new MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
87
81
  }
88
82
  if (!this.useCircularStructures) {
89
- const hasCycles = ancestorsLineage.some(ancs => ancs.has(fragment));
83
+ const hasCycles = ancestorsLineage.includes(referencedElement);
90
84
  if (hasCycles) {
91
85
  if (url.isHttpUrl(retrievalURI) || url.isFileSystemPath(retrievalURI)) {
92
86
  // make the referencing URL or file system path absolute
93
- const cycledReferenceElement = new ReferenceElement({
87
+ return new ReferenceElement({
94
88
  $ref: $refBaseURI
95
- }, referenceElement.meta.clone(), referenceElement.attributes.clone());
96
- cycledReferenceElement.get('$ref').classes.push('cycle');
97
- return cycledReferenceElement;
89
+ }, cloneDeep(referencingElement.meta), cloneDeep(referencingElement.attributes));
98
90
  }
99
- // skip processing this schema and all it's child schemas
91
+ // skip processing this reference
100
92
  return false;
101
93
  }
102
94
  }
103
95
 
104
96
  // append referencing schema to ancestors lineage
105
- directAncestors.add(referenceElement);
97
+ directAncestors.add(referencingElement);
106
98
 
107
99
  // dive deep into the fragment
108
100
  const visitor = OpenApi3_1SwaggerClientDereferenceVisitor({
@@ -113,55 +105,78 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
113
105
  ancestors: ancestorsLineage,
114
106
  allowMetaPatches: this.allowMetaPatches,
115
107
  useCircularStructures: this.useCircularStructures,
116
- basePath: (_this$basePath = this.basePath) !== null && _this$basePath !== void 0 ? _this$basePath : [...toPath([...ancestors, parent, referenceElement]), '$ref']
108
+ basePath: (_this$basePath = this.basePath) !== null && _this$basePath !== void 0 ? _this$basePath : [...toPath([...ancestors, parent, referencingElement]), '$ref']
117
109
  });
118
- fragment = await visitAsync(fragment, visitor, {
110
+ referencedElement = await visitAsync(referencedElement, visitor, {
119
111
  keyMap,
120
112
  nodeTypeGetter: getNodeType
121
113
  });
122
114
 
123
115
  // remove referencing schema from ancestors lineage
124
- directAncestors.delete(referenceElement);
116
+ directAncestors.delete(referencingElement);
125
117
  this.indirections.pop();
126
- fragment = fragment.clone();
127
- fragment.setMetaProperty('ref-fields', {
128
- $ref: (_referenceElement$$re = referenceElement.$ref) === null || _referenceElement$$re === void 0 ? void 0 : _referenceElement$$re.toValue(),
129
- description: (_referenceElement$des = referenceElement.description) === null || _referenceElement$des === void 0 ? void 0 : _referenceElement$des.toValue(),
130
- summary: (_referenceElement$sum = referenceElement.summary) === null || _referenceElement$sum === void 0 ? void 0 : _referenceElement$sum.toValue()
131
- });
132
- // annotate fragment with info about origin
133
- fragment.setMetaProperty('ref-origin', reference.uri);
134
-
135
- // override description and summary (outer has higher priority then inner)
136
- const hasDescription = typeof referenceElement.description !== 'undefined';
137
- const hasSummary = typeof referenceElement.summary !== 'undefined';
138
- if (hasDescription && 'description' in fragment) {
139
- fragment.description = referenceElement.description;
140
- }
141
- if (hasSummary && 'summary' in fragment) {
142
- fragment.summary = referenceElement.summary;
143
- }
118
+ const mergeAndAnnotateReferencedElement = refedElement => {
119
+ const copy = cloneShallow(refedElement);
120
+
121
+ // annotate fragment with info about original Reference element
122
+ copy.setMetaProperty('ref-fields', {
123
+ $ref: toValue(referencingElement.$ref),
124
+ // @ts-ignore
125
+ description: toValue(referencingElement.description),
126
+ // @ts-ignore
127
+ summary: toValue(referencingElement.summary)
128
+ });
129
+ // annotate fragment with info about origin
130
+ copy.setMetaProperty('ref-origin', reference.uri);
131
+
132
+ // override description and summary (outer has higher priority then inner)
133
+ if (isObjectElement(refedElement)) {
134
+ if (referencingElement.hasKey('description') && 'description' in refedElement) {
135
+ // @ts-ignore
136
+ copy.remove('description');
137
+ // @ts-ignore
138
+ copy.set('description', referencingElement.get('description'));
139
+ }
140
+ if (referencingElement.hasKey('summary') && 'summary' in refedElement) {
141
+ // @ts-ignore
142
+ copy.remove('summary');
143
+ // @ts-ignore
144
+ copy.set('summary', referencingElement.get('summary'));
145
+ }
146
+ }
144
147
 
145
- // apply meta patches
146
- if (this.allowMetaPatches && isObjectElement(fragment)) {
147
- const objectFragment = fragment;
148
- // apply meta patch only when not already applied
149
- if (typeof objectFragment.get('$$ref') === 'undefined') {
150
- const baseURI = url.resolve(retrievalURI, $refBaseURI);
151
- objectFragment.set('$$ref', baseURI);
148
+ // apply meta patches
149
+ if (this.allowMetaPatches && isObjectElement(copy)) {
150
+ // apply meta patch only when not already applied
151
+ if (!copy.hasKey('$$ref')) {
152
+ const baseURI = url.resolve(retrievalURI, $refBaseURI);
153
+ copy.set('$$ref', baseURI);
154
+ }
155
+ }
156
+ return copy;
157
+ };
158
+
159
+ // attempting to create cycle
160
+ if (ancestorsLineage.includes(referencedElement)) {
161
+ if (isMemberElement(parent)) {
162
+ parent.value = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
163
+ } else if (Array.isArray(parent)) {
164
+ parent[key] = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
152
165
  }
166
+
167
+ return false;
153
168
  }
154
169
 
155
170
  // transclude the element for a fragment
156
- return fragment;
171
+ return mergeAndAnnotateReferencedElement(referencedElement);
157
172
  } catch (error) {
158
173
  var _this$basePath2, _this$options$derefer, _this$options$derefer2;
159
174
  const rootCause = getRootCause(error);
160
175
  const wrappedError = wrapError(rootCause, {
161
176
  baseDoc: this.reference.uri,
162
- $ref: referenceElement.$ref.toValue(),
163
- pointer: uriToPointer(referenceElement.$ref.toValue()),
164
- fullPath: (_this$basePath2 = this.basePath) !== null && _this$basePath2 !== void 0 ? _this$basePath2 : [...toPath([...ancestors, parent, referenceElement]), '$ref']
177
+ $ref: toValue(referencingElement.$ref),
178
+ pointer: uriToPointer(toValue(referencingElement.$ref)),
179
+ fullPath: (_this$basePath2 = this.basePath) !== null && _this$basePath2 !== void 0 ? _this$basePath2 : [...toPath([...ancestors, parent, referencingElement]), '$ref']
165
180
  });
166
181
  (_this$options$derefer = this.options.dereference.dereferenceOpts) === null || _this$options$derefer === void 0 || (_this$options$derefer = _this$options$derefer.errors) === null || _this$options$derefer === void 0 || (_this$options$derefer2 = _this$options$derefer.push) === null || _this$options$derefer2 === void 0 || _this$options$derefer2.call(_this$options$derefer, wrappedError);
167
182
  return undefined;
@@ -169,7 +184,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
169
184
  },
170
185
  async PathItemElement(pathItemElement, key, parent, path, ancestors) {
171
186
  try {
172
- var _this$basePath3, _pathItemElement$$ref;
187
+ var _this$basePath3;
173
188
  const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
174
189
 
175
190
  // ignore PathItemElement without $ref field
@@ -177,14 +192,8 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
177
192
  return undefined;
178
193
  }
179
194
 
180
- // skip already identified cycled Path Item Objects
181
- if (includesClasses(['cycle'], pathItemElement.$ref)) {
182
- return false;
183
- }
184
-
185
195
  // detect possible cycle in traversal and avoid it
186
- if (ancestorsLineage.some(ancs => ancs.has(pathItemElement))) {
187
- // skip processing this schema and all it's child schemas
196
+ if (ancestorsLineage.includesCycle(pathItemElement)) {
188
197
  return false;
189
198
  }
190
199
 
@@ -192,11 +201,11 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
192
201
  if (!this.options.resolve.external && isPathItemElementExternal(pathItemElement)) {
193
202
  return undefined;
194
203
  }
195
- const reference = await this.toReference(pathItemElement.$ref.toValue());
204
+ const reference = await this.toReference(toValue(pathItemElement.$ref));
196
205
  const {
197
206
  uri: retrievalURI
198
207
  } = reference;
199
- const $refBaseURI = url.resolve(retrievalURI, pathItemElement.$ref.toValue());
208
+ const $refBaseURI = url.resolve(retrievalURI, toValue(pathItemElement.$ref));
200
209
  this.indirections.push(pathItemElement);
201
210
  const jsonPointer = uriToPointer($refBaseURI);
202
211
 
@@ -218,17 +227,15 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
218
227
  throw new MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
219
228
  }
220
229
  if (!this.useCircularStructures) {
221
- const hasCycles = ancestorsLineage.some(ancs => ancs.has(referencedElement));
230
+ const hasCycles = ancestorsLineage.includes(referencedElement);
222
231
  if (hasCycles) {
223
232
  if (url.isHttpUrl(retrievalURI) || url.isFileSystemPath(retrievalURI)) {
224
233
  // make the referencing URL or file system path absolute
225
- const cycledPathItemElement = new PathItemElement({
234
+ return new PathItemElement({
226
235
  $ref: $refBaseURI
227
- }, pathItemElement.meta.clone(), pathItemElement.attributes.clone());
228
- cycledPathItemElement.get('$ref').classes.push('cycle');
229
- return cycledPathItemElement;
236
+ }, cloneDeep(pathItemElement.meta), cloneDeep(pathItemElement.attributes));
230
237
  }
231
- // skip processing this schema and all it's child schemas
238
+ // skip processing this path item and all it's child elements
232
239
  return false;
233
240
  }
234
241
  }
@@ -255,41 +262,54 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
255
262
  // remove referencing schema from ancestors lineage
256
263
  directAncestors.delete(pathItemElement);
257
264
  this.indirections.pop();
265
+ const mergeAndAnnotateReferencedElement = refedElement => {
266
+ // merge fields from referenced Path Item with referencing one
267
+ const mergedElement = new PathItemElement([...refedElement.content], cloneDeep(refedElement.meta), cloneDeep(refedElement.attributes));
268
+ // existing keywords from referencing PathItemElement overrides ones from referenced element
269
+ pathItemElement.forEach((value, keyElement, item) => {
270
+ mergedElement.remove(toValue(keyElement));
271
+ mergedElement.content.push(item);
272
+ });
273
+ mergedElement.remove('$ref');
258
274
 
259
- // merge fields from referenced Path Item with referencing one
260
- const mergedPathItemElement = new PathItemElement([...referencedElement.content], referencedElement.meta.clone(), referencedElement.attributes.clone());
261
- // existing keywords from referencing PathItemElement overrides ones from referenced element
262
- pathItemElement.forEach((valueElement, keyElement, item) => {
263
- mergedPathItemElement.remove(keyElement.toValue());
264
- mergedPathItemElement.content.push(item);
265
- });
266
- mergedPathItemElement.remove('$ref');
275
+ // annotate referenced element with info about original referencing element
276
+ mergedElement.setMetaProperty('ref-fields', {
277
+ $ref: toValue(pathItemElement.$ref)
278
+ });
279
+ // annotate referenced element with info about origin
280
+ mergedElement.setMetaProperty('ref-origin', reference.uri);
267
281
 
268
- // annotate referenced element with info about original referencing element
269
- mergedPathItemElement.setMetaProperty('ref-fields', {
270
- $ref: (_pathItemElement$$ref = pathItemElement.$ref) === null || _pathItemElement$$ref === void 0 ? void 0 : _pathItemElement$$ref.toValue()
271
- });
272
- // annotate referenced element with info about origin
273
- mergedPathItemElement.setMetaProperty('ref-origin', reference.uri);
274
-
275
- // apply meta patches
276
- if (this.allowMetaPatches) {
277
- // apply meta patch only when not already applied
278
- if (typeof mergedPathItemElement.get('$$ref') === 'undefined') {
279
- const baseURI = url.resolve(retrievalURI, $refBaseURI);
280
- mergedPathItemElement.set('$$ref', baseURI);
282
+ // apply meta patches
283
+ if (this.allowMetaPatches) {
284
+ // apply meta patch only when not already applied
285
+ if (typeof mergedElement.get('$$ref') === 'undefined') {
286
+ const baseURI = url.resolve(retrievalURI, $refBaseURI);
287
+ mergedElement.set('$$ref', baseURI);
288
+ }
289
+ }
290
+ return mergedElement;
291
+ };
292
+
293
+ // attempting to create cycle
294
+ if (ancestorsLineage.includes(referencedElement)) {
295
+ if (isMemberElement(parent)) {
296
+ parent.value = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
297
+ } else if (Array.isArray(parent)) {
298
+ parent[key] = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
281
299
  }
300
+
301
+ return false;
282
302
  }
283
303
 
284
304
  // transclude referencing element with merged referenced element
285
- return mergedPathItemElement;
305
+ return mergeAndAnnotateReferencedElement(referencedElement);
286
306
  } catch (error) {
287
307
  var _this$basePath4, _this$options$derefer3, _this$options$derefer4;
288
308
  const rootCause = getRootCause(error);
289
309
  const wrappedError = wrapError(rootCause, {
290
310
  baseDoc: this.reference.uri,
291
- $ref: pathItemElement.$ref.toValue(),
292
- pointer: uriToPointer(pathItemElement.$ref.toValue()),
311
+ $ref: toValue(pathItemElement.$ref),
312
+ pointer: uriToPointer(toValue(pathItemElement.$ref)),
293
313
  fullPath: (_this$basePath4 = this.basePath) !== null && _this$basePath4 !== void 0 ? _this$basePath4 : [...toPath([...ancestors, parent, pathItemElement]), '$ref']
294
314
  });
295
315
  (_this$options$derefer3 = this.options.dereference.dereferenceOpts) === null || _this$options$derefer3 === void 0 || (_this$options$derefer3 = _this$options$derefer3.errors) === null || _this$options$derefer3 === void 0 || (_this$options$derefer4 = _this$options$derefer3.push) === null || _this$options$derefer4 === void 0 || _this$options$derefer4.call(_this$options$derefer3, wrappedError);
@@ -298,7 +318,7 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
298
318
  },
299
319
  async SchemaElement(referencingElement, key, parent, path, ancestors) {
300
320
  try {
301
- var _this$basePath5, _referencingElement$$2;
321
+ var _this$basePath5;
302
322
  const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
303
323
 
304
324
  // skip current referencing schema as $ref keyword was not defined
@@ -307,14 +327,8 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
307
327
  return undefined;
308
328
  }
309
329
 
310
- // skip already identified cycled schemas
311
- if (includesClasses(['cycle'], referencingElement.$ref)) {
312
- return false;
313
- }
314
-
315
330
  // detect possible cycle in traversal and avoid it
316
- if (ancestorsLineage.some(ancs => ancs.has(referencingElement))) {
317
- // skip processing this schema and all it's child schemas
331
+ if (ancestorsLineage.includesCycle(referencingElement)) {
318
332
  return false;
319
333
  }
320
334
 
@@ -394,11 +408,9 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
394
408
  if (url.isHttpUrl(retrievalURI) || url.isFileSystemPath(retrievalURI)) {
395
409
  // make the referencing URL or file system path absolute
396
410
  const baseURI = url.resolve(retrievalURI, $refBaseURI);
397
- const cycledSchemaElement = new SchemaElement({
411
+ return new SchemaElement({
398
412
  $ref: baseURI
399
- }, referencingElement.meta.clone(), referencingElement.attributes.clone());
400
- cycledSchemaElement.get('$ref').classes.push('cycle');
401
- return cycledSchemaElement;
413
+ }, cloneDeep(referencingElement.meta), cloneDeep(referencingElement.attributes));
402
414
  }
403
415
  // skip processing this schema and all it's child schemas
404
416
  return false;
@@ -428,51 +440,61 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
428
440
  directAncestors.delete(referencingElement);
429
441
  this.indirections.pop();
430
442
  if (isBooleanJsonSchemaElement(referencedElement)) {
431
- var _referencingElement$$;
432
- // Boolean JSON Schema
433
- const jsonSchemaBooleanElement = referencedElement.clone();
443
+ const booleanJsonSchemaElement = cloneDeep(referencedElement);
434
444
  // annotate referenced element with info about original referencing element
435
- jsonSchemaBooleanElement.setMetaProperty('ref-fields', {
436
- $ref: (_referencingElement$$ = referencingElement.$ref) === null || _referencingElement$$ === void 0 ? void 0 : _referencingElement$$.toValue()
445
+ booleanJsonSchemaElement.setMetaProperty('ref-fields', {
446
+ $ref: toValue(referencingElement.$ref)
437
447
  });
438
448
  // annotate referenced element with info about origin
439
- jsonSchemaBooleanElement.setMetaProperty('ref-origin', retrievalURI);
440
- return jsonSchemaBooleanElement;
449
+ booleanJsonSchemaElement.setMetaProperty('ref-origin', reference.uri);
450
+ return booleanJsonSchemaElement;
441
451
  }
452
+ const mergeAndAnnotateReferencedElement = refedElement => {
453
+ // Schema Object - merge keywords from referenced schema with referencing schema
454
+ const mergedElement = new SchemaElement([...refedElement.content], cloneDeep(refedElement.meta), cloneDeep(refedElement.attributes));
455
+ // existing keywords from referencing schema overrides ones from referenced schema
456
+ referencingElement.forEach((value, keyElement, item) => {
457
+ mergedElement.remove(toValue(keyElement));
458
+ mergedElement.content.push(item);
459
+ });
460
+ mergedElement.remove('$ref');
461
+ // annotate referenced element with info about original referencing element
462
+ mergedElement.setMetaProperty('ref-fields', {
463
+ $ref: toValue(referencingElement.$ref)
464
+ });
465
+ // annotate fragment with info about origin
466
+ mergedElement.setMetaProperty('ref-origin', reference.uri);
442
467
 
443
- // Schema Object - merge keywords from referenced schema with referencing schema
444
- const mergedSchemaElement = new SchemaElement([...referencedElement.content], referencedElement.meta.clone(), referencedElement.attributes.clone());
445
- // existing keywords from referencing schema overrides ones from referenced schema
446
- referencingElement.forEach((memberValue, memberKey, member) => {
447
- mergedSchemaElement.remove(memberKey.toValue());
448
- mergedSchemaElement.content.push(member);
449
- });
450
- mergedSchemaElement.remove('$ref');
451
-
452
- // annotate referenced element with info about original referencing element
453
- mergedSchemaElement.setMetaProperty('ref-fields', {
454
- $ref: (_referencingElement$$2 = referencingElement.$ref) === null || _referencingElement$$2 === void 0 ? void 0 : _referencingElement$$2.toValue()
455
- });
456
- // annotate fragment with info about origin
457
- mergedSchemaElement.setMetaProperty('ref-origin', retrievalURI);
458
-
459
- // allowMetaPatches option processing
460
- if (this.allowMetaPatches) {
461
- // apply meta patch only when not already applied
462
- if (typeof mergedSchemaElement.get('$$ref') === 'undefined') {
463
- const baseURI = url.resolve(retrievalURI, $refBaseURI);
464
- mergedSchemaElement.set('$$ref', baseURI);
468
+ // allowMetaPatches option processing
469
+ if (this.allowMetaPatches) {
470
+ // apply meta patch only when not already applied
471
+ if (typeof mergedElement.get('$$ref') === 'undefined') {
472
+ const baseURI = url.resolve(retrievalURI, $refBaseURI);
473
+ mergedElement.set('$$ref', baseURI);
474
+ }
465
475
  }
476
+ return mergedElement;
477
+ };
478
+
479
+ // attempting to create cycle
480
+ if (ancestorsLineage.includes(referencedElement)) {
481
+ if (isMemberElement(parent)) {
482
+ parent.value = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
483
+ } else if (Array.isArray(parent)) {
484
+ parent[key] = mergeAndAnnotateReferencedElement(referencedElement); // eslint-disable-line no-param-reassign
485
+ }
486
+
487
+ return false;
466
488
  }
467
489
 
468
490
  // transclude referencing element with merged referenced element
469
- return mergedSchemaElement;
491
+ return mergeAndAnnotateReferencedElement(referencedElement);
470
492
  } catch (error) {
471
493
  var _this$basePath6, _this$options$derefer5, _this$options$derefer6;
472
494
  const rootCause = getRootCause(error);
473
495
  const wrappedError = new SchemaRefError(`Could not resolve reference: ${rootCause.message}`, {
474
496
  baseDoc: this.reference.uri,
475
- $ref: referencingElement.$ref.toValue(),
497
+ $ref: toValue(referencingElement.$ref),
476
498
  fullPath: (_this$basePath6 = this.basePath) !== null && _this$basePath6 !== void 0 ? _this$basePath6 : [...toPath([...ancestors, parent, referencingElement]), '$ref']
477
499
  }, rootCause);
478
500
  (_this$options$derefer5 = this.options.dereference.dereferenceOpts) === null || _this$options$derefer5 === void 0 || (_this$options$derefer5 = _this$options$derefer5.errors) === null || _this$options$derefer5 === void 0 || (_this$options$derefer6 = _this$options$derefer5.push) === null || _this$options$derefer6 === void 0 || _this$options$derefer6.call(_this$options$derefer5, wrappedError);
@@ -491,11 +513,11 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = OpenApi3_1DereferenceVisitor.c
491
513
  try {
492
514
  return await OpenApi3_1DereferenceVisitor.compose.methods.ExampleElement.call(this, exampleElement, key, parent, path, ancestors);
493
515
  } catch (error) {
494
- var _exampleElement$exter, _this$basePath7, _this$options$derefer7, _this$options$derefer8;
516
+ var _this$basePath7, _this$options$derefer7, _this$options$derefer8;
495
517
  const rootCause = getRootCause(error);
496
518
  const wrappedError = wrapError(rootCause, {
497
519
  baseDoc: this.reference.uri,
498
- externalValue: (_exampleElement$exter = exampleElement.externalValue) === null || _exampleElement$exter === void 0 ? void 0 : _exampleElement$exter.toValue(),
520
+ externalValue: toValue(exampleElement.externalValue),
499
521
  fullPath: (_this$basePath7 = this.basePath) !== null && _this$basePath7 !== void 0 ? _this$basePath7 : [...toPath([...ancestors, parent, exampleElement]), 'externalValue']
500
522
  });
501
523
  (_this$options$derefer7 = this.options.dereference.dereferenceOpts) === null || _this$options$derefer7 === void 0 || (_this$options$derefer7 = _this$options$derefer7.errors) === null || _this$options$derefer7 === void 0 || (_this$options$derefer8 = _this$options$derefer7.push) === null || _this$options$derefer8 === void 0 || _this$options$derefer8.call(_this$options$derefer7, wrappedError);
package/lib/constants.js CHANGED
@@ -2,7 +2,5 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
  exports.DEFAULT_BASE_URL = exports.ACCEPT_HEADER_VALUE_FOR_DOCUMENTS = void 0;
5
- const ACCEPT_HEADER_VALUE_FOR_DOCUMENTS = 'application/json, application/yaml';
6
- exports.ACCEPT_HEADER_VALUE_FOR_DOCUMENTS = ACCEPT_HEADER_VALUE_FOR_DOCUMENTS;
7
- const DEFAULT_BASE_URL = 'https://swagger.io';
8
- exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
5
+ const ACCEPT_HEADER_VALUE_FOR_DOCUMENTS = exports.ACCEPT_HEADER_VALUE_FOR_DOCUMENTS = 'application/json, application/yaml';
6
+ const DEFAULT_BASE_URL = exports.DEFAULT_BASE_URL = 'https://swagger.io';
@@ -72,13 +72,12 @@ const deduplicateParameters = parameters => {
72
72
  };
73
73
 
74
74
  // For stubbing in tests
75
- const self = {
75
+ const self = exports.self = {
76
76
  buildRequest
77
77
  };
78
78
 
79
79
  // Execute request, with the given operationId and parameters
80
80
  // pathName/method or operationId is optional
81
- exports.self = self;
82
81
  function execute(_ref) {
83
82
  let {
84
83
  http: userHttp,
@@ -4,14 +4,13 @@ exports.__esModule = true;
4
4
  exports.default = void 0;
5
5
  // These functions will update the request.
6
6
  // They'll be given {req, value, paramter, spec, operation}.
7
- var _default = {
7
+ var _default = exports.default = {
8
8
  body: bodyBuilder,
9
9
  header: headerBuilder,
10
10
  query: queryBuilder,
11
11
  path: pathBuilder,
12
12
  formData: formDataBuilder
13
13
  }; // Add the body to the request
14
- exports.default = _default;
15
14
  function bodyBuilder(_ref) {
16
15
  let {
17
16
  req,
@@ -19,5 +19,4 @@ const globalObject = (() => {
19
19
  const {
20
20
  btoa
21
21
  } = globalObject;
22
- var _default = btoa;
23
- exports.default = _default;
22
+ var _default = exports.default = btoa;
@@ -12,5 +12,4 @@ const btoa = val => {
12
12
  }
13
13
  return buffer.toString('base64');
14
14
  };
15
- var _default = btoa;
16
- exports.default = _default;
15
+ var _default = exports.default = btoa;
@@ -10,5 +10,4 @@ exports.Headers = _undici.Headers;
10
10
  exports.Request = _undici.Request;
11
11
  exports.FormData = _undici.FormData;
12
12
  exports.File = _undici.File;
13
- const BlobU = typeof _undici.fetch === 'undefined' ? undefined : _buffer.Blob;
14
- exports.Blob = BlobU;
13
+ const BlobU = exports.Blob = typeof _undici.fetch === 'undefined' ? undefined : _buffer.Blob;
@@ -3,5 +3,4 @@
3
3
  exports.__esModule = true;
4
4
  exports.default = void 0;
5
5
  const replaceSpecialCharsWithUnderscore = operationId => operationId.replace(/\W/gi, '_');
6
- var _default = replaceSpecialCharsWithUnderscore;
7
- exports.default = _default;
6
+ var _default = exports.default = replaceSpecialCharsWithUnderscore;
package/lib/http/index.js CHANGED
@@ -16,14 +16,13 @@ var _jsYaml = _interopRequireDefault(require("js-yaml"));
16
16
  require("../helpers/fetch-polyfill.node.js");
17
17
  var _styleSerializer = require("../execute/oas3/style-serializer.js");
18
18
  // For testing
19
- const self = {
19
+ const self = exports.self = {
20
20
  serializeRes,
21
21
  mergeInQueryOrForm
22
22
  };
23
23
 
24
24
  // Handles fetch-like syntax and the case where there is only one object passed-in
25
25
  // (which will have the URL as a property). Also serializes the response.
26
- exports.self = self;
27
26
  async function http(url, request) {
28
27
  if (request === void 0) {
29
28
  request = {};
package/lib/index.js CHANGED
@@ -155,6 +155,5 @@ const {
155
155
  helpers
156
156
  } = Swagger;
157
157
  exports.helpers = helpers;
158
- var _default = Swagger;
159
- /* eslint-enable camelcase */
160
- exports.default = _default;
158
+ var _default = exports.default = Swagger;
159
+ /* eslint-enable camelcase */