swagger-client 3.27.8 → 3.28.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 (30) hide show
  1. package/dist/swagger-client.browser.js +2183 -2304
  2. package/dist/swagger-client.browser.min.js +1 -1
  3. package/dist/swagger-client.browser.min.js.map +1 -1
  4. package/es/index.js +2 -2
  5. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +107 -109
  6. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +66 -69
  7. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +582 -582
  8. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +31 -34
  9. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +25 -28
  10. package/es/resolver/apidom/reference/parse/parsers/json/index.js +43 -42
  11. package/es/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js +46 -45
  12. package/es/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +46 -45
  13. package/es/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +44 -43
  14. package/es/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +62 -60
  15. package/es/resolver/strategies/openapi-3-1-apidom/resolve.js +18 -18
  16. package/lib/index.js +1 -1
  17. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js +105 -107
  18. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/all-of.js +66 -69
  19. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/dereference.js +581 -581
  20. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/parameters.js +31 -34
  21. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/visitors/properties.js +25 -28
  22. package/lib/resolver/apidom/reference/parse/parsers/json/index.js +43 -42
  23. package/lib/resolver/apidom/reference/parse/parsers/openapi-json-3-1/index.js +46 -45
  24. package/lib/resolver/apidom/reference/parse/parsers/openapi-yaml-3-1/index.js +46 -45
  25. package/lib/resolver/apidom/reference/parse/parsers/yaml-1-2/index.js +44 -43
  26. package/lib/resolver/apidom/reference/resolve/resolvers/http-swagger-client/index.js +61 -59
  27. package/lib/resolver/strategies/openapi-3-1-apidom/resolve.js +11 -11
  28. package/package.json +23 -22
  29. package/es/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/compose.js +0 -5
  30. package/lib/resolver/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/utils/compose.js +0 -11
@@ -23,420 +23,463 @@ const {
23
23
  const visitAsync = _apidomCore.visit[Symbol.for('nodejs.util.promisify.custom')];
24
24
 
25
25
  // initialize element identity manager
26
- const identityManager = (0, _apidomCore.IdentityManager)();
27
- const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1DereferenceVisitor.compose({
28
- props: {
29
- useCircularStructures: true,
30
- allowMetaPatches: false,
31
- basePath: null
32
- },
33
- init({
34
- allowMetaPatches = this.allowMetaPatches,
35
- useCircularStructures = this.useCircularStructures,
36
- basePath = this.basePath
26
+ const identityManager = new _apidomCore.IdentityManager();
27
+ class OpenAPI3_1SwaggerClientDereferenceVisitor extends _openapi.OpenAPI3_1DereferenceVisitor {
28
+ useCircularStructures;
29
+ allowMetaPatches;
30
+ basePath;
31
+ constructor({
32
+ allowMetaPatches = true,
33
+ useCircularStructures = false,
34
+ basePath = null,
35
+ ...rest
37
36
  }) {
37
+ super(rest);
38
38
  this.allowMetaPatches = allowMetaPatches;
39
39
  this.useCircularStructures = useCircularStructures;
40
40
  this.basePath = basePath;
41
- },
42
- methods: {
43
- async ReferenceElement(referencingElement, key, parent, path, ancestors) {
44
- try {
45
- // skip current referencing element as it's already been access
46
- if (this.indirections.includes(referencingElement)) {
47
- return false;
48
- }
49
- const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
50
- const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(referencingElement.$ref));
51
- const isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
52
- const isExternalReference = !isInternalReference;
53
-
54
- // ignore resolving internal Reference Objects
55
- if (!this.options.resolve.internal && isInternalReference) {
56
- return false;
57
- }
58
- // ignore resolving external Reference Objects
59
- if (!this.options.resolve.external && isExternalReference) {
60
- return false;
61
- }
62
- const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
63
- const $refBaseURI = _empty.url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
64
- this.indirections.push(referencingElement);
65
- const jsonPointer = (0, _apidomJsonPointer.uriToPointer)($refBaseURI);
66
-
67
- // possibly non-semantic fragment
68
- let referencedElement = (0, _apidomJsonPointer.evaluate)(jsonPointer, reference.value.result);
69
- referencedElement.id = identityManager.identify(referencedElement);
70
-
71
- // applying semantics to a fragment
72
- if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
73
- const referencedElementType = (0, _apidomCore.toValue)(referencingElement.meta.get('referenced-element'));
74
- const cacheKey = `${referencedElementType}-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
75
- if (this.refractCache.has(cacheKey)) {
76
- referencedElement = this.refractCache.get(cacheKey);
77
- } else if ((0, _apidomNsOpenapi.isReferenceLikeElement)(referencedElement)) {
78
- // handling indirect references
79
- referencedElement = _apidomNsOpenapi.ReferenceElement.refract(referencedElement);
80
- referencedElement.setMetaProperty('referenced-element', referencedElementType);
81
- this.refractCache.set(cacheKey, referencedElement);
82
- } else {
83
- // handling direct references
84
- const ElementClass = this.namespace.getElementClass(referencedElementType);
85
- referencedElement = ElementClass.refract(referencedElement);
86
- this.refractCache.set(cacheKey, referencedElement);
87
- }
88
- }
89
-
90
- // detect direct or indirect reference
91
- if (referencingElement === referencedElement) {
92
- throw new _apidomError.ApiDOMError('Recursive Reference Object detected');
41
+ }
42
+ async ReferenceElement(referencingElement, key, parent, path, ancestors) {
43
+ try {
44
+ // skip current referencing element as it's already been access
45
+ if (this.indirections.includes(referencingElement)) {
46
+ return false;
47
+ }
48
+ const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
49
+ const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(referencingElement.$ref));
50
+ const isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
51
+ const isExternalReference = !isInternalReference;
52
+
53
+ // ignore resolving internal Reference Objects
54
+ if (!this.options.resolve.internal && isInternalReference) {
55
+ return false;
56
+ }
57
+ // ignore resolving external Reference Objects
58
+ if (!this.options.resolve.external && isExternalReference) {
59
+ return false;
60
+ }
61
+ const reference = await this.toReference((0, _apidomCore.toValue)(referencingElement.$ref));
62
+ const $refBaseURI = _empty.url.resolve(retrievalURI, (0, _apidomCore.toValue)(referencingElement.$ref));
63
+ this.indirections.push(referencingElement);
64
+ const jsonPointer = (0, _apidomJsonPointer.uriToPointer)($refBaseURI);
65
+
66
+ // possibly non-semantic fragment
67
+ let referencedElement = (0, _apidomJsonPointer.evaluate)(jsonPointer, reference.value.result);
68
+ referencedElement.id = identityManager.identify(referencedElement);
69
+
70
+ // applying semantics to a fragment
71
+ if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
72
+ const referencedElementType = (0, _apidomCore.toValue)(referencingElement.meta.get('referenced-element'));
73
+ const cacheKey = `${referencedElementType}-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
74
+ if (this.refractCache.has(cacheKey)) {
75
+ referencedElement = this.refractCache.get(cacheKey);
76
+ } else if ((0, _apidomNsOpenapi.isReferenceLikeElement)(referencedElement)) {
77
+ // handling indirect references
78
+ referencedElement = _apidomNsOpenapi.ReferenceElement.refract(referencedElement);
79
+ referencedElement.setMetaProperty('referenced-element', referencedElementType);
80
+ this.refractCache.set(cacheKey, referencedElement);
81
+ } else {
82
+ // handling direct references
83
+ const ElementClass = this.namespace.getElementClass(referencedElementType);
84
+ referencedElement = ElementClass.refract(referencedElement);
85
+ this.refractCache.set(cacheKey, referencedElement);
93
86
  }
87
+ }
94
88
 
95
- // detect maximum depth of dereferencing
96
- if (this.indirections.length > this.options.dereference.maxDepth) {
97
- throw new _empty.MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
98
- }
89
+ // detect direct or indirect reference
90
+ if (referencingElement === referencedElement) {
91
+ throw new _apidomError.ApiDOMError('Recursive Reference Object detected');
92
+ }
99
93
 
100
- // detect second deep dive into the same fragment and avoid it
101
- if (ancestorsLineage.includes(referencedElement)) {
102
- reference.refSet.circular = true;
103
- if (this.options.dereference.circular === 'error') {
104
- throw new _apidomError.ApiDOMError('Circular reference detected');
105
- } else if (this.options.dereference.circular === 'replace') {
106
- var _this$options$derefer, _this$options$derefer2;
107
- const refElement = new _apidomCore.RefElement(referencedElement.id, {
108
- type: 'reference',
109
- uri: reference.uri,
110
- $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
111
- baseURI: $refBaseURI,
112
- referencingElement
113
- });
114
- const replacer = (_this$options$derefer = (_this$options$derefer2 = this.options.dereference.strategyOpts['openapi-3-1']) == null ? void 0 : _this$options$derefer2.circularReplacer) != null ? _this$options$derefer : this.options.dereference.circularReplacer;
115
- const replacement = replacer(refElement);
116
- if ((0, _apidomCore.isMemberElement)(parent)) {
117
- parent.value = replacement; // eslint-disable-line no-param-reassign
118
- } else if (Array.isArray(parent)) {
119
- parent[key] = replacement; // eslint-disable-line no-param-reassign
120
- }
121
- return !parent ? replacement : false;
122
- }
123
- }
94
+ // detect maximum depth of dereferencing
95
+ if (this.indirections.length > this.options.dereference.maxDepth) {
96
+ throw new _empty.MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
97
+ }
124
98
 
125
- /**
126
- * Dive deep into the fragment.
127
- *
128
- * Cases to consider:
129
- * 1. We're crossing document boundary
130
- * 2. Fragment is from non-root document
131
- * 3. Fragment is a Reference Object. We need to follow it to get the eventual value
132
- * 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
133
- */
134
- const isNonRootDocument = _empty.url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
135
- const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
136
- if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isReferenceElement)(referencedElement) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
137
- var _this$basePath;
138
- // append referencing reference to ancestors lineage
139
- directAncestors.add(referencingElement);
140
- const visitor = OpenApi3_1SwaggerClientDereferenceVisitor({
141
- reference,
142
- namespace: this.namespace,
143
- indirections: [...this.indirections],
144
- options: this.options,
145
- refractCache: this.refractCache,
146
- ancestors: ancestorsLineage,
147
- allowMetaPatches: this.allowMetaPatches,
148
- useCircularStructures: this.useCircularStructures,
149
- basePath: (_this$basePath = this.basePath) != null ? _this$basePath : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
99
+ // detect second deep dive into the same fragment and avoid it
100
+ if (ancestorsLineage.includes(referencedElement)) {
101
+ reference.refSet.circular = true;
102
+ if (this.options.dereference.circular === 'error') {
103
+ throw new _apidomError.ApiDOMError('Circular reference detected');
104
+ } else if (this.options.dereference.circular === 'replace') {
105
+ var _this$options$derefer, _this$options$derefer2;
106
+ const refElement = new _apidomCore.RefElement(referencedElement.id, {
107
+ type: 'reference',
108
+ uri: reference.uri,
109
+ $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
110
+ baseURI: $refBaseURI,
111
+ referencingElement
150
112
  });
151
- referencedElement = await visitAsync(referencedElement, visitor, {
152
- keyMap: _apidomNsOpenapi.keyMap,
153
- nodeTypeGetter: _apidomNsOpenapi.getNodeType
154
- });
155
-
156
- // remove referencing reference from ancestors lineage
157
- directAncestors.delete(referencingElement);
113
+ const replacer = (_this$options$derefer = (_this$options$derefer2 = this.options.dereference.strategyOpts['openapi-3-1']) == null ? void 0 : _this$options$derefer2.circularReplacer) != null ? _this$options$derefer : this.options.dereference.circularReplacer;
114
+ const replacement = replacer(refElement);
115
+ if ((0, _apidomCore.isMemberElement)(parent)) {
116
+ parent.value = replacement; // eslint-disable-line no-param-reassign
117
+ } else if (Array.isArray(parent)) {
118
+ parent[key] = replacement; // eslint-disable-line no-param-reassign
119
+ }
120
+ return !parent ? replacement : false;
158
121
  }
159
- this.indirections.pop();
160
- const mergedElement = (0, _apidomCore.cloneShallow)(referencedElement);
122
+ }
161
123
 
162
- // annotate fragment with info about original Reference element
163
- mergedElement.setMetaProperty('ref-fields', {
164
- $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
165
- description: (0, _apidomCore.toValue)(referencingElement.description),
166
- summary: (0, _apidomCore.toValue)(referencingElement.summary)
124
+ /**
125
+ * Dive deep into the fragment.
126
+ *
127
+ * Cases to consider:
128
+ * 1. We're crossing document boundary
129
+ * 2. Fragment is from non-root document
130
+ * 3. Fragment is a Reference Object. We need to follow it to get the eventual value
131
+ * 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
132
+ */
133
+ const isNonRootDocument = _empty.url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
134
+ const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
135
+ if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isReferenceElement)(referencedElement) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
136
+ var _this$basePath;
137
+ // append referencing reference to ancestors lineage
138
+ directAncestors.add(referencingElement);
139
+ const visitor = new OpenAPI3_1SwaggerClientDereferenceVisitor({
140
+ reference,
141
+ namespace: this.namespace,
142
+ indirections: [...this.indirections],
143
+ options: this.options,
144
+ refractCache: this.refractCache,
145
+ ancestors: ancestorsLineage,
146
+ allowMetaPatches: this.allowMetaPatches,
147
+ useCircularStructures: this.useCircularStructures,
148
+ basePath: (_this$basePath = this.basePath) != null ? _this$basePath : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
149
+ });
150
+ referencedElement = await visitAsync(referencedElement, visitor, {
151
+ keyMap: _apidomNsOpenapi.keyMap,
152
+ nodeTypeGetter: _apidomNsOpenapi.getNodeType
167
153
  });
168
- // annotate fragment with info about origin
169
- mergedElement.setMetaProperty('ref-origin', reference.uri);
170
- // annotate fragment with info about referencing element
171
- mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
172
154
 
173
- // override description and summary (outer has higher priority then inner)
174
- if ((0, _apidomCore.isObjectElement)(referencedElement)) {
175
- if (referencingElement.hasKey('description') && 'description' in referencedElement) {
176
- mergedElement.remove('description');
177
- mergedElement.set('description', referencingElement.get('description'));
178
- }
179
- if (referencingElement.hasKey('summary') && 'summary' in referencedElement) {
180
- mergedElement.remove('summary');
181
- mergedElement.set('summary', referencingElement.get('summary'));
182
- }
155
+ // remove referencing reference from ancestors lineage
156
+ directAncestors.delete(referencingElement);
157
+ }
158
+ this.indirections.pop();
159
+ const mergedElement = (0, _apidomCore.cloneShallow)(referencedElement);
160
+
161
+ // annotate fragment with info about original Reference element
162
+ mergedElement.setMetaProperty('ref-fields', {
163
+ $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
164
+ description: (0, _apidomCore.toValue)(referencingElement.description),
165
+ summary: (0, _apidomCore.toValue)(referencingElement.summary)
166
+ });
167
+ // annotate fragment with info about origin
168
+ mergedElement.setMetaProperty('ref-origin', reference.uri);
169
+ // annotate fragment with info about referencing element
170
+ mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
171
+
172
+ // override description and summary (outer has higher priority then inner)
173
+ if ((0, _apidomCore.isObjectElement)(referencedElement)) {
174
+ if (referencingElement.hasKey('description') && 'description' in referencedElement) {
175
+ mergedElement.remove('description');
176
+ mergedElement.set('description', referencingElement.get('description'));
177
+ }
178
+ if (referencingElement.hasKey('summary') && 'summary' in referencedElement) {
179
+ mergedElement.remove('summary');
180
+ mergedElement.set('summary', referencingElement.get('summary'));
183
181
  }
182
+ }
184
183
 
185
- // apply meta patches
186
- if (this.allowMetaPatches && (0, _apidomCore.isObjectElement)(mergedElement)) {
187
- // apply meta patch only when not already applied
188
- if (!mergedElement.hasKey('$$ref')) {
189
- const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
190
- mergedElement.set('$$ref', baseURI);
191
- }
184
+ // apply meta patches
185
+ if (this.allowMetaPatches && (0, _apidomCore.isObjectElement)(mergedElement)) {
186
+ // apply meta patch only when not already applied
187
+ if (!mergedElement.hasKey('$$ref')) {
188
+ const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
189
+ mergedElement.set('$$ref', baseURI);
192
190
  }
191
+ }
193
192
 
194
- /**
195
- * Transclude referencing element with merged referenced element.
196
- */
197
- if ((0, _apidomCore.isMemberElement)(parent)) {
198
- parent.value = mergedElement; // eslint-disable-line no-param-reassign
199
- } else if (Array.isArray(parent)) {
200
- parent[key] = mergedElement; // eslint-disable-line no-param-reassign
201
- }
193
+ /**
194
+ * Transclude referencing element with merged referenced element.
195
+ */
196
+ if ((0, _apidomCore.isMemberElement)(parent)) {
197
+ parent.value = mergedElement; // eslint-disable-line no-param-reassign
198
+ } else if (Array.isArray(parent)) {
199
+ parent[key] = mergedElement; // eslint-disable-line no-param-reassign
200
+ }
202
201
 
203
- /**
204
- * We're at the root of the tree, so we're just replacing the entire tree.
205
- */
206
- return !parent ? mergedElement : false;
207
- } catch (error) {
208
- var _this$basePath2, _this$options$derefer3;
209
- const rootCause = (0, _getRootCause.default)(error);
210
- const wrappedError = wrapError(rootCause, {
211
- baseDoc: this.reference.uri,
212
- $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
213
- pointer: (0, _apidomJsonPointer.uriToPointer)((0, _apidomCore.toValue)(referencingElement.$ref)),
214
- fullPath: (_this$basePath2 = this.basePath) != null ? _this$basePath2 : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
215
- });
216
- (_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);
202
+ /**
203
+ * We're at the root of the tree, so we're just replacing the entire tree.
204
+ */
205
+ return !parent ? mergedElement : false;
206
+ } catch (error) {
207
+ var _this$basePath2, _this$options$derefer3;
208
+ const rootCause = (0, _getRootCause.default)(error);
209
+ const wrappedError = wrapError(rootCause, {
210
+ baseDoc: this.reference.uri,
211
+ $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
212
+ pointer: (0, _apidomJsonPointer.uriToPointer)((0, _apidomCore.toValue)(referencingElement.$ref)),
213
+ fullPath: (_this$basePath2 = this.basePath) != null ? _this$basePath2 : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
214
+ });
215
+ (_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);
216
+ return undefined;
217
+ }
218
+ }
219
+ async PathItemElement(pathItemElement, key, parent, path, ancestors) {
220
+ try {
221
+ // ignore PathItemElement without $ref field
222
+ if (!(0, _apidomCore.isStringElement)(pathItemElement.$ref)) {
217
223
  return undefined;
218
224
  }
219
- },
220
- async PathItemElement(pathItemElement, key, parent, path, ancestors) {
221
- try {
222
- // ignore PathItemElement without $ref field
223
- if (!(0, _apidomCore.isStringElement)(pathItemElement.$ref)) {
224
- return undefined;
225
- }
226
225
 
227
- // skip current referencing element as it's already been access
228
- if (this.indirections.includes(pathItemElement)) {
229
- return false;
230
- }
226
+ // skip current referencing element as it's already been access
227
+ if (this.indirections.includes(pathItemElement)) {
228
+ return false;
229
+ }
231
230
 
232
- // skip already identified cycled Path Item Objects
233
- if ((0, _apidomCore.includesClasses)(['cycle'], pathItemElement.$ref)) {
234
- return false;
235
- }
236
- const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
237
- const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(pathItemElement.$ref));
238
- const isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
239
- const isExternalReference = !isInternalReference;
240
-
241
- // ignore resolving internal Path Item Elements
242
- if (!this.options.resolve.internal && isInternalReference) {
243
- return undefined;
244
- }
245
- // ignore resolving external Path Item Elements
246
- if (!this.options.resolve.external && isExternalReference) {
247
- return undefined;
248
- }
249
- const reference = await this.toReference((0, _apidomCore.toValue)(pathItemElement.$ref));
250
- const $refBaseURI = _empty.url.resolve(retrievalURI, (0, _apidomCore.toValue)(pathItemElement.$ref));
251
- this.indirections.push(pathItemElement);
252
- const jsonPointer = (0, _apidomJsonPointer.uriToPointer)($refBaseURI);
253
-
254
- // possibly non-semantic referenced element
255
- let referencedElement = (0, _apidomJsonPointer.evaluate)(jsonPointer, reference.value.result);
256
- referencedElement.id = identityManager.identify(referencedElement);
257
-
258
- // applying semantics to a referenced element
259
- if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
260
- const cacheKey = `path-item-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
261
- if (this.refractCache.has(cacheKey)) {
262
- referencedElement = this.refractCache.get(cacheKey);
263
- } else {
264
- referencedElement = _apidomNsOpenapi.PathItemElement.refract(referencedElement);
265
- this.refractCache.set(cacheKey, referencedElement);
266
- }
267
- }
231
+ // skip already identified cycled Path Item Objects
232
+ if ((0, _apidomCore.includesClasses)(['cycle'], pathItemElement.$ref)) {
233
+ return false;
234
+ }
235
+ const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
236
+ const retrievalURI = this.toBaseURI((0, _apidomCore.toValue)(pathItemElement.$ref));
237
+ const isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
238
+ const isExternalReference = !isInternalReference;
268
239
 
269
- // detect direct or indirect reference
270
- if (pathItemElement === referencedElement) {
271
- throw new _apidomError.ApiDOMError('Recursive Path Item Object reference detected');
240
+ // ignore resolving internal Path Item Elements
241
+ if (!this.options.resolve.internal && isInternalReference) {
242
+ return undefined;
243
+ }
244
+ // ignore resolving external Path Item Elements
245
+ if (!this.options.resolve.external && isExternalReference) {
246
+ return undefined;
247
+ }
248
+ const reference = await this.toReference((0, _apidomCore.toValue)(pathItemElement.$ref));
249
+ const $refBaseURI = _empty.url.resolve(retrievalURI, (0, _apidomCore.toValue)(pathItemElement.$ref));
250
+ this.indirections.push(pathItemElement);
251
+ const jsonPointer = (0, _apidomJsonPointer.uriToPointer)($refBaseURI);
252
+
253
+ // possibly non-semantic referenced element
254
+ let referencedElement = (0, _apidomJsonPointer.evaluate)(jsonPointer, reference.value.result);
255
+ referencedElement.id = identityManager.identify(referencedElement);
256
+
257
+ // applying semantics to a referenced element
258
+ if ((0, _apidomCore.isPrimitiveElement)(referencedElement)) {
259
+ const cacheKey = `path-item-${(0, _apidomCore.toValue)(identityManager.identify(referencedElement))}`;
260
+ if (this.refractCache.has(cacheKey)) {
261
+ referencedElement = this.refractCache.get(cacheKey);
262
+ } else {
263
+ referencedElement = _apidomNsOpenapi.PathItemElement.refract(referencedElement);
264
+ this.refractCache.set(cacheKey, referencedElement);
272
265
  }
266
+ }
273
267
 
274
- // detect maximum depth of dereferencing
275
- if (this.indirections.length > this.options.dereference.maxDepth) {
276
- throw new _empty.MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
277
- }
268
+ // detect direct or indirect reference
269
+ if (pathItemElement === referencedElement) {
270
+ throw new _apidomError.ApiDOMError('Recursive Path Item Object reference detected');
271
+ }
278
272
 
279
- // detect second deep dive into the same fragment and avoid it
280
- if (ancestorsLineage.includes(referencedElement)) {
281
- reference.refSet.circular = true;
282
- if (this.options.dereference.circular === 'error') {
283
- throw new _apidomError.ApiDOMError('Circular reference detected');
284
- } else if (this.options.dereference.circular === 'replace') {
285
- var _this$options$derefer4, _this$options$derefer5;
286
- const refElement = new _apidomCore.RefElement(referencedElement.id, {
287
- type: 'path-item',
288
- uri: reference.uri,
289
- $ref: (0, _apidomCore.toValue)(pathItemElement.$ref),
290
- baseURI: $refBaseURI,
291
- referencingElement: pathItemElement
292
- });
293
- const replacer = (_this$options$derefer4 = (_this$options$derefer5 = this.options.dereference.strategyOpts['openapi-3-1']) == null ? void 0 : _this$options$derefer5.circularReplacer) != null ? _this$options$derefer4 : this.options.dereference.circularReplacer;
294
- const replacement = replacer(refElement);
295
- if ((0, _apidomCore.isMemberElement)(parent)) {
296
- parent.value = replacement; // eslint-disable-line no-param-reassign
297
- } else if (Array.isArray(parent)) {
298
- parent[key] = replacement; // eslint-disable-line no-param-reassign
299
- }
300
- return !parent ? replacement : false;
273
+ // detect maximum depth of dereferencing
274
+ if (this.indirections.length > this.options.dereference.maxDepth) {
275
+ throw new _empty.MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
276
+ }
277
+
278
+ // detect second deep dive into the same fragment and avoid it
279
+ if (ancestorsLineage.includes(referencedElement)) {
280
+ reference.refSet.circular = true;
281
+ if (this.options.dereference.circular === 'error') {
282
+ throw new _apidomError.ApiDOMError('Circular reference detected');
283
+ } else if (this.options.dereference.circular === 'replace') {
284
+ var _this$options$derefer4, _this$options$derefer5;
285
+ const refElement = new _apidomCore.RefElement(referencedElement.id, {
286
+ type: 'path-item',
287
+ uri: reference.uri,
288
+ $ref: (0, _apidomCore.toValue)(pathItemElement.$ref),
289
+ baseURI: $refBaseURI,
290
+ referencingElement: pathItemElement
291
+ });
292
+ const replacer = (_this$options$derefer4 = (_this$options$derefer5 = this.options.dereference.strategyOpts['openapi-3-1']) == null ? void 0 : _this$options$derefer5.circularReplacer) != null ? _this$options$derefer4 : this.options.dereference.circularReplacer;
293
+ const replacement = replacer(refElement);
294
+ if ((0, _apidomCore.isMemberElement)(parent)) {
295
+ parent.value = replacement; // eslint-disable-line no-param-reassign
296
+ } else if (Array.isArray(parent)) {
297
+ parent[key] = replacement; // eslint-disable-line no-param-reassign
301
298
  }
299
+ return !parent ? replacement : false;
302
300
  }
301
+ }
303
302
 
304
- /**
305
- * Dive deep into the fragment.
306
- *
307
- * Cases to consider:
308
- * 1. We're crossing document boundary
309
- * 2. Fragment is from non-root document
310
- * 3. Fragment is a Path Item Object with $ref field. We need to follow it to get the eventual value
311
- * 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
312
- */
313
- const isNonRootDocument = _empty.url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
314
- const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
315
- if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isPathItemElement)(referencedElement) && (0, _apidomCore.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
316
- var _this$basePath3;
317
- // append referencing schema to ancestors lineage
318
- directAncestors.add(pathItemElement);
319
-
320
- // dive deep into the referenced element
321
- const visitor = OpenApi3_1SwaggerClientDereferenceVisitor({
322
- reference,
323
- namespace: this.namespace,
324
- indirections: [...this.indirections],
325
- options: this.options,
326
- ancestors: ancestorsLineage,
327
- allowMetaPatches: this.allowMetaPatches,
328
- useCircularStructures: this.useCircularStructures,
329
- basePath: (_this$basePath3 = this.basePath) != null ? _this$basePath3 : [...(0, _toPath.default)([...ancestors, parent, pathItemElement]), '$ref']
330
- });
331
- referencedElement = await visitAsync(referencedElement, visitor, {
332
- keyMap: _apidomNsOpenapi.keyMap,
333
- nodeTypeGetter: _apidomNsOpenapi.getNodeType
334
- });
303
+ /**
304
+ * Dive deep into the fragment.
305
+ *
306
+ * Cases to consider:
307
+ * 1. We're crossing document boundary
308
+ * 2. Fragment is from non-root document
309
+ * 3. Fragment is a Path Item Object with $ref field. We need to follow it to get the eventual value
310
+ * 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
311
+ */
312
+ const isNonRootDocument = _empty.url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
313
+ const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
314
+ if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isPathItemElement)(referencedElement) && (0, _apidomCore.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
315
+ var _this$basePath3;
316
+ // append referencing schema to ancestors lineage
317
+ directAncestors.add(pathItemElement);
318
+
319
+ // dive deep into the referenced element
320
+ const visitor = new OpenAPI3_1SwaggerClientDereferenceVisitor({
321
+ reference,
322
+ namespace: this.namespace,
323
+ indirections: [...this.indirections],
324
+ options: this.options,
325
+ ancestors: ancestorsLineage,
326
+ allowMetaPatches: this.allowMetaPatches,
327
+ useCircularStructures: this.useCircularStructures,
328
+ basePath: (_this$basePath3 = this.basePath) != null ? _this$basePath3 : [...(0, _toPath.default)([...ancestors, parent, pathItemElement]), '$ref']
329
+ });
330
+ referencedElement = await visitAsync(referencedElement, visitor, {
331
+ keyMap: _apidomNsOpenapi.keyMap,
332
+ nodeTypeGetter: _apidomNsOpenapi.getNodeType
333
+ });
335
334
 
336
- // remove referencing schema from ancestors lineage
337
- directAncestors.delete(pathItemElement);
338
- }
339
- this.indirections.pop();
335
+ // remove referencing schema from ancestors lineage
336
+ directAncestors.delete(pathItemElement);
337
+ }
338
+ this.indirections.pop();
340
339
 
341
- /**
342
- * Creating a new version of Path Item by merging fields from referenced Path Item with referencing one.
343
- */
344
- if ((0, _apidomNsOpenapi.isPathItemElement)(referencedElement)) {
345
- const mergedElement = new _apidomNsOpenapi.PathItemElement([...referencedElement.content], (0, _apidomCore.cloneDeep)(referencedElement.meta), (0, _apidomCore.cloneDeep)(referencedElement.attributes));
346
- // existing keywords from referencing PathItemElement overrides ones from referenced element
347
- pathItemElement.forEach((value, keyElement, item) => {
348
- mergedElement.remove((0, _apidomCore.toValue)(keyElement));
349
- mergedElement.content.push(item);
350
- });
351
- mergedElement.remove('$ref');
340
+ /**
341
+ * Creating a new version of Path Item by merging fields from referenced Path Item with referencing one.
342
+ */
343
+ if ((0, _apidomNsOpenapi.isPathItemElement)(referencedElement)) {
344
+ const mergedElement = new _apidomNsOpenapi.PathItemElement([...referencedElement.content], (0, _apidomCore.cloneDeep)(referencedElement.meta), (0, _apidomCore.cloneDeep)(referencedElement.attributes));
345
+ // existing keywords from referencing PathItemElement overrides ones from referenced element
346
+ pathItemElement.forEach((value, keyElement, item) => {
347
+ mergedElement.remove((0, _apidomCore.toValue)(keyElement));
348
+ mergedElement.content.push(item);
349
+ });
350
+ mergedElement.remove('$ref');
352
351
 
353
- // annotate referenced element with info about original referencing element
354
- mergedElement.setMetaProperty('ref-fields', {
355
- $ref: (0, _apidomCore.toValue)(pathItemElement.$ref)
356
- });
357
- // annotate referenced element with info about origin
358
- mergedElement.setMetaProperty('ref-origin', reference.uri);
359
- // annotate fragment with info about referencing element
360
- mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(pathItemElement)));
361
-
362
- // apply meta patches
363
- if (this.allowMetaPatches) {
364
- // apply meta patch only when not already applied
365
- if (typeof mergedElement.get('$$ref') === 'undefined') {
366
- const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
367
- mergedElement.set('$$ref', baseURI);
368
- }
352
+ // annotate referenced element with info about original referencing element
353
+ mergedElement.setMetaProperty('ref-fields', {
354
+ $ref: (0, _apidomCore.toValue)(pathItemElement.$ref)
355
+ });
356
+ // annotate referenced element with info about origin
357
+ mergedElement.setMetaProperty('ref-origin', reference.uri);
358
+ // annotate fragment with info about referencing element
359
+ mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(pathItemElement)));
360
+
361
+ // apply meta patches
362
+ if (this.allowMetaPatches) {
363
+ // apply meta patch only when not already applied
364
+ if (typeof mergedElement.get('$$ref') === 'undefined') {
365
+ const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
366
+ mergedElement.set('$$ref', baseURI);
369
367
  }
370
- referencedElement = mergedElement;
371
368
  }
369
+ referencedElement = mergedElement;
370
+ }
372
371
 
373
- /**
374
- * Transclude referencing element with merged referenced element.
375
- */
376
- if ((0, _apidomCore.isMemberElement)(parent)) {
377
- parent.value = referencedElement; // eslint-disable-line no-param-reassign
378
- } else if (Array.isArray(parent)) {
379
- parent[key] = referencedElement; // eslint-disable-line no-param-reassign
380
- }
372
+ /**
373
+ * Transclude referencing element with merged referenced element.
374
+ */
375
+ if ((0, _apidomCore.isMemberElement)(parent)) {
376
+ parent.value = referencedElement; // eslint-disable-line no-param-reassign
377
+ } else if (Array.isArray(parent)) {
378
+ parent[key] = referencedElement; // eslint-disable-line no-param-reassign
379
+ }
381
380
 
382
- /**
383
- * We're at the root of the tree, so we're just replacing the entire tree.
384
- */
385
- return !parent ? referencedElement : undefined;
386
- } catch (error) {
387
- var _this$basePath4, _this$options$derefer6;
388
- const rootCause = (0, _getRootCause.default)(error);
389
- const wrappedError = wrapError(rootCause, {
390
- baseDoc: this.reference.uri,
391
- $ref: (0, _apidomCore.toValue)(pathItemElement.$ref),
392
- pointer: (0, _apidomJsonPointer.uriToPointer)((0, _apidomCore.toValue)(pathItemElement.$ref)),
393
- fullPath: (_this$basePath4 = this.basePath) != null ? _this$basePath4 : [...(0, _toPath.default)([...ancestors, parent, pathItemElement]), '$ref']
394
- });
395
- (_this$options$derefer6 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer6 = _this$options$derefer6.errors) == null || _this$options$derefer6.push == null || _this$options$derefer6.push(wrappedError);
381
+ /**
382
+ * We're at the root of the tree, so we're just replacing the entire tree.
383
+ */
384
+ return !parent ? referencedElement : undefined;
385
+ } catch (error) {
386
+ var _this$basePath4, _this$options$derefer6;
387
+ const rootCause = (0, _getRootCause.default)(error);
388
+ const wrappedError = wrapError(rootCause, {
389
+ baseDoc: this.reference.uri,
390
+ $ref: (0, _apidomCore.toValue)(pathItemElement.$ref),
391
+ pointer: (0, _apidomJsonPointer.uriToPointer)((0, _apidomCore.toValue)(pathItemElement.$ref)),
392
+ fullPath: (_this$basePath4 = this.basePath) != null ? _this$basePath4 : [...(0, _toPath.default)([...ancestors, parent, pathItemElement]), '$ref']
393
+ });
394
+ (_this$options$derefer6 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer6 = _this$options$derefer6.errors) == null || _this$options$derefer6.push == null || _this$options$derefer6.push(wrappedError);
395
+ return undefined;
396
+ }
397
+ }
398
+ async SchemaElement(referencingElement, key, parent, path, ancestors) {
399
+ try {
400
+ // skip current referencing schema as $ref keyword was not defined
401
+ if (!(0, _apidomCore.isStringElement)(referencingElement.$ref)) {
402
+ // skip traversing this schema but traverse all it's child schemas
396
403
  return undefined;
397
404
  }
398
- },
399
- async SchemaElement(referencingElement, key, parent, path, ancestors) {
400
- try {
401
- // skip current referencing schema as $ref keyword was not defined
402
- if (!(0, _apidomCore.isStringElement)(referencingElement.$ref)) {
403
- // skip traversing this schema but traverse all it's child schemas
404
- return undefined;
405
- }
406
405
 
407
- // skip current referencing element as it's already been access
408
- if (this.indirections.includes(referencingElement)) {
409
- return false;
406
+ // skip current referencing element as it's already been access
407
+ if (this.indirections.includes(referencingElement)) {
408
+ return false;
409
+ }
410
+ const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
411
+
412
+ // compute baseURI using rules around $id and $ref keywords
413
+ let reference = await this.toReference(_empty.url.unsanitize(this.reference.uri));
414
+ let {
415
+ uri: retrievalURI
416
+ } = reference;
417
+ const $refBaseURI = (0, _openapi.resolveSchema$refField)(retrievalURI, referencingElement);
418
+ const $refBaseURIStrippedHash = _empty.url.stripHash($refBaseURI);
419
+ const file = new _empty.File({
420
+ uri: $refBaseURIStrippedHash
421
+ });
422
+ const isUnknownURI = !this.options.resolve.resolvers.some(r => r.canRead(file));
423
+ const isURL = !isUnknownURI;
424
+ let isInternalReference = _empty.url.stripHash(this.reference.uri) === $refBaseURI;
425
+ let isExternalReference = !isInternalReference;
426
+ this.indirections.push(referencingElement);
427
+
428
+ // determining reference, proper evaluation and selection mechanism
429
+ let referencedElement;
430
+ try {
431
+ if (isUnknownURI || isURL) {
432
+ // we're dealing with canonical URI or URL with possible fragment
433
+ retrievalURI = this.toBaseURI($refBaseURI);
434
+ const selector = $refBaseURI;
435
+ const referenceAsSchema = (0, _openapi.maybeRefractToSchemaElement)(reference.value.result);
436
+ referencedElement = (0, _uri.evaluate)(selector, referenceAsSchema);
437
+ referencedElement = (0, _openapi.maybeRefractToSchemaElement)(referencedElement);
438
+ referencedElement.id = identityManager.identify(referencedElement);
439
+
440
+ // ignore resolving internal Schema Objects
441
+ if (!this.options.resolve.internal && isInternalReference) {
442
+ // skip traversing this schema element but traverse all it's child elements
443
+ return undefined;
444
+ }
445
+ // ignore resolving external Schema Objects
446
+ if (!this.options.resolve.external && isExternalReference) {
447
+ // skip traversing this schema element but traverse all it's child elements
448
+ return undefined;
449
+ }
450
+ } else {
451
+ // we're assuming here that we're dealing with JSON Pointer here
452
+ retrievalURI = this.toBaseURI($refBaseURI);
453
+ isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
454
+ isExternalReference = !isInternalReference;
455
+
456
+ // ignore resolving internal Schema Objects
457
+ if (!this.options.resolve.internal && isInternalReference) {
458
+ // skip traversing this schema element but traverse all it's child elements
459
+ return undefined;
460
+ }
461
+ // ignore resolving external Schema Objects
462
+ if (!this.options.resolve.external && isExternalReference) {
463
+ // skip traversing this schema element but traverse all it's child elements
464
+ return undefined;
465
+ }
466
+ reference = await this.toReference(_empty.url.unsanitize($refBaseURI));
467
+ const selector = (0, _apidomJsonPointer.uriToPointer)($refBaseURI);
468
+ const referenceAsSchema = (0, _openapi.maybeRefractToSchemaElement)(reference.value.result);
469
+ referencedElement = (0, _apidomJsonPointer.evaluate)(selector, referenceAsSchema);
470
+ referencedElement = (0, _openapi.maybeRefractToSchemaElement)(referencedElement);
471
+ referencedElement.id = identityManager.identify(referencedElement);
410
472
  }
411
- const [ancestorsLineage, directAncestors] = this.toAncestorLineage([...ancestors, parent]);
412
-
413
- // compute baseURI using rules around $id and $ref keywords
414
- let reference = await this.toReference(_empty.url.unsanitize(this.reference.uri));
415
- let {
416
- uri: retrievalURI
417
- } = reference;
418
- const $refBaseURI = (0, _openapi.resolveSchema$refField)(retrievalURI, referencingElement);
419
- const $refBaseURIStrippedHash = _empty.url.stripHash($refBaseURI);
420
- const file = (0, _empty.File)({
421
- uri: $refBaseURIStrippedHash
422
- });
423
- const isUnknownURI = !this.options.resolve.resolvers.some(r => r.canRead(file));
424
- const isURL = !isUnknownURI;
425
- let isInternalReference = _empty.url.stripHash(this.reference.uri) === $refBaseURI;
426
- let isExternalReference = !isInternalReference;
427
- this.indirections.push(referencingElement);
428
-
429
- // determining reference, proper evaluation and selection mechanism
430
- let referencedElement;
431
- try {
432
- if (isUnknownURI || isURL) {
433
- // we're dealing with canonical URI or URL with possible fragment
434
- retrievalURI = this.toBaseURI($refBaseURI);
435
- const selector = $refBaseURI;
436
- const referenceAsSchema = (0, _openapi.maybeRefractToSchemaElement)(reference.value.result);
437
- referencedElement = (0, _uri.evaluate)(selector, referenceAsSchema);
438
- referencedElement = (0, _openapi.maybeRefractToSchemaElement)(referencedElement);
439
- referencedElement.id = identityManager.identify(referencedElement);
473
+ } catch (error) {
474
+ /**
475
+ * No SchemaElement($id=URL) was not found, so we're going to try to resolve
476
+ * the URL and assume the returned response is a JSON Schema.
477
+ */
478
+ if (isURL && error instanceof _uri.EvaluationJsonSchemaUriError) {
479
+ if ((0, _$anchor.isAnchor)((0, _$anchor.uriToAnchor)($refBaseURI))) {
480
+ // we're dealing with JSON Schema $anchor here
481
+ isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
482
+ isExternalReference = !isInternalReference;
440
483
 
441
484
  // ignore resolving internal Schema Objects
442
485
  if (!this.options.resolve.internal && isInternalReference) {
@@ -448,9 +491,15 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
448
491
  // skip traversing this schema element but traverse all it's child elements
449
492
  return undefined;
450
493
  }
494
+ reference = await this.toReference(_empty.url.unsanitize($refBaseURI));
495
+ const selector = (0, _$anchor.uriToAnchor)($refBaseURI);
496
+ const referenceAsSchema = (0, _openapi.maybeRefractToSchemaElement)(reference.value.result);
497
+ referencedElement = (0, _$anchor.evaluate)(selector, referenceAsSchema);
498
+ referencedElement = (0, _openapi.maybeRefractToSchemaElement)(referencedElement);
499
+ referencedElement.id = identityManager.identify(referencedElement);
451
500
  } else {
452
501
  // we're assuming here that we're dealing with JSON Pointer here
453
- retrievalURI = this.toBaseURI($refBaseURI);
502
+ retrievalURI = this.toBaseURI((0, _apidomCore.toValue)($refBaseURI));
454
503
  isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
455
504
  isExternalReference = !isInternalReference;
456
505
 
@@ -471,232 +520,183 @@ const OpenApi3_1SwaggerClientDereferenceVisitor = _openapi.OpenApi3_1Dereference
471
520
  referencedElement = (0, _openapi.maybeRefractToSchemaElement)(referencedElement);
472
521
  referencedElement.id = identityManager.identify(referencedElement);
473
522
  }
474
- } catch (error) {
475
- /**
476
- * No SchemaElement($id=URL) was not found, so we're going to try to resolve
477
- * the URL and assume the returned response is a JSON Schema.
478
- */
479
- if (isURL && error instanceof _uri.EvaluationJsonSchemaUriError) {
480
- if ((0, _$anchor.isAnchor)((0, _$anchor.uriToAnchor)($refBaseURI))) {
481
- // we're dealing with JSON Schema $anchor here
482
- isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
483
- isExternalReference = !isInternalReference;
484
-
485
- // ignore resolving internal Schema Objects
486
- if (!this.options.resolve.internal && isInternalReference) {
487
- // skip traversing this schema element but traverse all it's child elements
488
- return undefined;
489
- }
490
- // ignore resolving external Schema Objects
491
- if (!this.options.resolve.external && isExternalReference) {
492
- // skip traversing this schema element but traverse all it's child elements
493
- return undefined;
494
- }
495
- reference = await this.toReference(_empty.url.unsanitize($refBaseURI));
496
- const selector = (0, _$anchor.uriToAnchor)($refBaseURI);
497
- const referenceAsSchema = (0, _openapi.maybeRefractToSchemaElement)(reference.value.result);
498
- referencedElement = (0, _$anchor.evaluate)(selector, referenceAsSchema);
499
- referencedElement = (0, _openapi.maybeRefractToSchemaElement)(referencedElement);
500
- referencedElement.id = identityManager.identify(referencedElement);
501
- } else {
502
- // we're assuming here that we're dealing with JSON Pointer here
503
- retrievalURI = this.toBaseURI((0, _apidomCore.toValue)($refBaseURI));
504
- isInternalReference = _empty.url.stripHash(this.reference.uri) === retrievalURI;
505
- isExternalReference = !isInternalReference;
506
-
507
- // ignore resolving internal Schema Objects
508
- if (!this.options.resolve.internal && isInternalReference) {
509
- // skip traversing this schema element but traverse all it's child elements
510
- return undefined;
511
- }
512
- // ignore resolving external Schema Objects
513
- if (!this.options.resolve.external && isExternalReference) {
514
- // skip traversing this schema element but traverse all it's child elements
515
- return undefined;
516
- }
517
- reference = await this.toReference(_empty.url.unsanitize($refBaseURI));
518
- const selector = (0, _apidomJsonPointer.uriToPointer)($refBaseURI);
519
- const referenceAsSchema = (0, _openapi.maybeRefractToSchemaElement)(reference.value.result);
520
- referencedElement = (0, _apidomJsonPointer.evaluate)(selector, referenceAsSchema);
521
- referencedElement = (0, _openapi.maybeRefractToSchemaElement)(referencedElement);
522
- referencedElement.id = identityManager.identify(referencedElement);
523
- }
524
- } else {
525
- throw error;
526
- }
527
- }
528
-
529
- // detect direct or indirect reference
530
- if (referencingElement === referencedElement) {
531
- throw new _apidomError.ApiDOMError('Recursive Schema Object reference detected');
532
- }
533
-
534
- // detect maximum depth of dereferencing
535
- if (this.indirections.length > this.options.dereference.maxDepth) {
536
- throw new _empty.MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
523
+ } else {
524
+ throw error;
537
525
  }
526
+ }
538
527
 
539
- // detect second deep dive into the same fragment and avoid it
540
- if (ancestorsLineage.includes(referencedElement)) {
541
- reference.refSet.circular = true;
542
- if (this.options.dereference.circular === 'error') {
543
- throw new _apidomError.ApiDOMError('Circular reference detected');
544
- } else if (this.options.dereference.circular === 'replace') {
545
- var _this$options$derefer7, _this$options$derefer8;
546
- const refElement = new _apidomCore.RefElement(referencedElement.id, {
547
- type: 'json-schema',
548
- uri: reference.uri,
549
- $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
550
- baseURI: _empty.url.resolve(retrievalURI, $refBaseURI),
551
- referencingElement
552
- });
553
- const replacer = (_this$options$derefer7 = (_this$options$derefer8 = this.options.dereference.strategyOpts['openapi-3-1']) == null ? void 0 : _this$options$derefer8.circularReplacer) != null ? _this$options$derefer7 : this.options.dereference.circularReplacer;
554
- const replacement = replacer(refElement);
555
- if ((0, _apidomCore.isMemberElement)(parent)) {
556
- parent.value = replacement; // eslint-disable-line no-param-reassign
557
- } else if (Array.isArray(parent)) {
558
- parent[key] = replacement; // eslint-disable-line no-param-reassign
559
- }
560
- return !parent ? replacement : false;
561
- }
562
- }
528
+ // detect direct or indirect reference
529
+ if (referencingElement === referencedElement) {
530
+ throw new _apidomError.ApiDOMError('Recursive Schema Object reference detected');
531
+ }
563
532
 
564
- /**
565
- * Dive deep into the fragment.
566
- *
567
- * Cases to consider:
568
- * 1. We're crossing document boundary
569
- * 2. Fragment is from non-root document
570
- * 3. Fragment is a Schema Object with $ref field. We need to follow it to get the eventual value
571
- * 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
572
- */
573
- const isNonRootDocument = _empty.url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
574
- const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
575
- if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isSchemaElement)(referencedElement) && (0, _apidomCore.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
576
- var _this$basePath5;
577
- // append referencing schema to ancestors lineage
578
- directAncestors.add(referencingElement);
579
-
580
- // dive deep into the fragment
581
- const mergeVisitor = OpenApi3_1SwaggerClientDereferenceVisitor({
582
- reference,
583
- namespace: this.namespace,
584
- indirections: [...this.indirections],
585
- options: this.options,
586
- useCircularStructures: this.useCircularStructures,
587
- allowMetaPatches: this.allowMetaPatches,
588
- ancestors: ancestorsLineage,
589
- basePath: (_this$basePath5 = this.basePath) != null ? _this$basePath5 : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
590
- });
591
- referencedElement = await visitAsync(referencedElement, mergeVisitor, {
592
- keyMap: _apidomNsOpenapi.keyMap,
593
- nodeTypeGetter: _apidomNsOpenapi.getNodeType
594
- });
533
+ // detect maximum depth of dereferencing
534
+ if (this.indirections.length > this.options.dereference.maxDepth) {
535
+ throw new _empty.MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
536
+ }
595
537
 
596
- // remove referencing schema from ancestors lineage
597
- directAncestors.delete(referencingElement);
598
- }
599
- this.indirections.pop();
600
- if ((0, _apidomNsOpenapi.isBooleanJsonSchemaElement)(referencedElement)) {
601
- const booleanJsonSchemaElement = (0, _apidomCore.cloneDeep)(referencedElement);
602
- // annotate referenced element with info about original referencing element
603
- booleanJsonSchemaElement.setMetaProperty('ref-fields', {
604
- $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
538
+ // detect second deep dive into the same fragment and avoid it
539
+ if (ancestorsLineage.includes(referencedElement)) {
540
+ reference.refSet.circular = true;
541
+ if (this.options.dereference.circular === 'error') {
542
+ throw new _apidomError.ApiDOMError('Circular reference detected');
543
+ } else if (this.options.dereference.circular === 'replace') {
544
+ var _this$options$derefer7, _this$options$derefer8;
545
+ const refElement = new _apidomCore.RefElement(referencedElement.id, {
546
+ type: 'json-schema',
547
+ uri: reference.uri,
548
+ $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
549
+ baseURI: _empty.url.resolve(retrievalURI, $refBaseURI),
550
+ referencingElement
605
551
  });
606
- // annotate referenced element with info about origin
607
- booleanJsonSchemaElement.setMetaProperty('ref-origin', reference.uri);
608
- // annotate fragment with info about referencing element
609
- booleanJsonSchemaElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
552
+ const replacer = (_this$options$derefer7 = (_this$options$derefer8 = this.options.dereference.strategyOpts['openapi-3-1']) == null ? void 0 : _this$options$derefer8.circularReplacer) != null ? _this$options$derefer7 : this.options.dereference.circularReplacer;
553
+ const replacement = replacer(refElement);
610
554
  if ((0, _apidomCore.isMemberElement)(parent)) {
611
- parent.value = booleanJsonSchemaElement; // eslint-disable-line no-param-reassign
555
+ parent.value = replacement; // eslint-disable-line no-param-reassign
612
556
  } else if (Array.isArray(parent)) {
613
- parent[key] = booleanJsonSchemaElement; // eslint-disable-line no-param-reassign
557
+ parent[key] = replacement; // eslint-disable-line no-param-reassign
614
558
  }
615
- return !parent ? booleanJsonSchemaElement : false;
559
+ return !parent ? replacement : false;
616
560
  }
561
+ }
617
562
 
618
- /**
619
- * Creating a new version of Schema Object by merging fields from referenced Schema Object with referencing one.
620
- */
621
- if ((0, _apidomNsOpenapi.isSchemaElement)(referencedElement)) {
622
- // Schema Object - merge keywords from referenced schema with referencing schema
623
- const mergedElement = new _apidomNsOpenapi.SchemaElement([...referencedElement.content], (0, _apidomCore.cloneDeep)(referencedElement.meta), (0, _apidomCore.cloneDeep)(referencedElement.attributes));
624
- // existing keywords from referencing schema overrides ones from referenced schema
625
- referencingElement.forEach((value, keyElement, item) => {
626
- mergedElement.remove((0, _apidomCore.toValue)(keyElement));
627
- mergedElement.content.push(item);
628
- });
629
- mergedElement.remove('$ref');
630
- // annotate referenced element with info about original referencing element
631
- mergedElement.setMetaProperty('ref-fields', {
632
- $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
633
- });
634
- // annotate fragment with info about origin
635
- mergedElement.setMetaProperty('ref-origin', reference.uri);
636
- // annotate fragment with info about referencing element
637
- mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
638
-
639
- // allowMetaPatches option processing
640
- if (this.allowMetaPatches) {
641
- // apply meta patch only when not already applied
642
- if (typeof mergedElement.get('$$ref') === 'undefined') {
643
- const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
644
- mergedElement.set('$$ref', baseURI);
645
- }
646
- }
647
- referencedElement = mergedElement;
648
- }
563
+ /**
564
+ * Dive deep into the fragment.
565
+ *
566
+ * Cases to consider:
567
+ * 1. We're crossing document boundary
568
+ * 2. Fragment is from non-root document
569
+ * 3. Fragment is a Schema Object with $ref field. We need to follow it to get the eventual value
570
+ * 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
571
+ */
572
+ const isNonRootDocument = _empty.url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
573
+ const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
574
+ if ((isExternalReference || isNonRootDocument || (0, _apidomNsOpenapi.isSchemaElement)(referencedElement) && (0, _apidomCore.isStringElement)(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
575
+ var _this$basePath5;
576
+ // append referencing schema to ancestors lineage
577
+ directAncestors.add(referencingElement);
578
+
579
+ // dive deep into the fragment
580
+ const mergeVisitor = new OpenAPI3_1SwaggerClientDereferenceVisitor({
581
+ reference,
582
+ namespace: this.namespace,
583
+ indirections: [...this.indirections],
584
+ options: this.options,
585
+ useCircularStructures: this.useCircularStructures,
586
+ allowMetaPatches: this.allowMetaPatches,
587
+ ancestors: ancestorsLineage,
588
+ basePath: (_this$basePath5 = this.basePath) != null ? _this$basePath5 : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref']
589
+ });
590
+ referencedElement = await visitAsync(referencedElement, mergeVisitor, {
591
+ keyMap: _apidomNsOpenapi.keyMap,
592
+ nodeTypeGetter: _apidomNsOpenapi.getNodeType
593
+ });
649
594
 
650
- /**
651
- * Transclude referencing element with merged referenced element.
652
- */
595
+ // remove referencing schema from ancestors lineage
596
+ directAncestors.delete(referencingElement);
597
+ }
598
+ this.indirections.pop();
599
+ if ((0, _apidomNsOpenapi.isBooleanJsonSchemaElement)(referencedElement)) {
600
+ const booleanJsonSchemaElement = (0, _apidomCore.cloneDeep)(referencedElement);
601
+ // annotate referenced element with info about original referencing element
602
+ booleanJsonSchemaElement.setMetaProperty('ref-fields', {
603
+ $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
604
+ });
605
+ // annotate referenced element with info about origin
606
+ booleanJsonSchemaElement.setMetaProperty('ref-origin', reference.uri);
607
+ // annotate fragment with info about referencing element
608
+ booleanJsonSchemaElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
653
609
  if ((0, _apidomCore.isMemberElement)(parent)) {
654
- parent.value = referencedElement; // eslint-disable-line no-param-reassign
610
+ parent.value = booleanJsonSchemaElement; // eslint-disable-line no-param-reassign
655
611
  } else if (Array.isArray(parent)) {
656
- parent[key] = referencedElement; // eslint-disable-line no-param-reassign
612
+ parent[key] = booleanJsonSchemaElement; // eslint-disable-line no-param-reassign
657
613
  }
614
+ return !parent ? booleanJsonSchemaElement : false;
615
+ }
658
616
 
659
- /**
660
- * We're at the root of the tree, so we're just replacing the entire tree.
661
- */
662
- return !parent ? referencedElement : undefined;
663
- } catch (error) {
664
- var _this$basePath6, _this$options$derefer9;
665
- const rootCause = (0, _getRootCause.default)(error);
666
- const wrappedError = new _SchemaRefError.default(`Could not resolve reference: ${rootCause.message}`, {
667
- baseDoc: this.reference.uri,
668
- $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
669
- fullPath: (_this$basePath6 = this.basePath) != null ? _this$basePath6 : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref'],
670
- cause: rootCause
617
+ /**
618
+ * Creating a new version of Schema Object by merging fields from referenced Schema Object with referencing one.
619
+ */
620
+ if ((0, _apidomNsOpenapi.isSchemaElement)(referencedElement)) {
621
+ // Schema Object - merge keywords from referenced schema with referencing schema
622
+ const mergedElement = new _apidomNsOpenapi.SchemaElement([...referencedElement.content], (0, _apidomCore.cloneDeep)(referencedElement.meta), (0, _apidomCore.cloneDeep)(referencedElement.attributes));
623
+ // existing keywords from referencing schema overrides ones from referenced schema
624
+ referencingElement.forEach((value, keyElement, item) => {
625
+ mergedElement.remove((0, _apidomCore.toValue)(keyElement));
626
+ mergedElement.content.push(item);
671
627
  });
672
- (_this$options$derefer9 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer9 = _this$options$derefer9.errors) == null || _this$options$derefer9.push == null || _this$options$derefer9.push(wrappedError);
673
- return undefined;
628
+ mergedElement.remove('$ref');
629
+ // annotate referenced element with info about original referencing element
630
+ mergedElement.setMetaProperty('ref-fields', {
631
+ $ref: (0, _apidomCore.toValue)(referencingElement.$ref)
632
+ });
633
+ // annotate fragment with info about origin
634
+ mergedElement.setMetaProperty('ref-origin', reference.uri);
635
+ // annotate fragment with info about referencing element
636
+ mergedElement.setMetaProperty('ref-referencing-element-id', (0, _apidomCore.cloneDeep)(identityManager.identify(referencingElement)));
637
+
638
+ // allowMetaPatches option processing
639
+ if (this.allowMetaPatches) {
640
+ // apply meta patch only when not already applied
641
+ if (typeof mergedElement.get('$$ref') === 'undefined') {
642
+ const baseURI = _empty.url.resolve(retrievalURI, $refBaseURI);
643
+ mergedElement.set('$$ref', baseURI);
644
+ }
645
+ }
646
+ referencedElement = mergedElement;
674
647
  }
675
- },
676
- async LinkElement() {
648
+
677
649
  /**
678
- * OpenApi3_1DereferenceVisitor is doing lookup of Operation Objects
679
- * and assigns them to Link Object metadata. This is not needed in
680
- * swagger-client context, so we're disabling it here.
650
+ * Transclude referencing element with merged referenced element.
681
651
  */
682
- return undefined;
683
- },
684
- async ExampleElement(exampleElement, key, parent, path, ancestors) {
685
- try {
686
- return await _openapi.OpenApi3_1DereferenceVisitor.compose.methods.ExampleElement.call(this, exampleElement, key, parent, path, ancestors);
687
- } catch (error) {
688
- var _this$basePath7, _this$options$derefer10;
689
- const rootCause = (0, _getRootCause.default)(error);
690
- const wrappedError = wrapError(rootCause, {
691
- baseDoc: this.reference.uri,
692
- externalValue: (0, _apidomCore.toValue)(exampleElement.externalValue),
693
- fullPath: (_this$basePath7 = this.basePath) != null ? _this$basePath7 : [...(0, _toPath.default)([...ancestors, parent, exampleElement]), 'externalValue']
694
- });
695
- (_this$options$derefer10 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer10 = _this$options$derefer10.errors) == null || _this$options$derefer10.push == null || _this$options$derefer10.push(wrappedError);
696
- return undefined;
652
+ if ((0, _apidomCore.isMemberElement)(parent)) {
653
+ parent.value = referencedElement; // eslint-disable-line no-param-reassign
654
+ } else if (Array.isArray(parent)) {
655
+ parent[key] = referencedElement; // eslint-disable-line no-param-reassign
697
656
  }
657
+
658
+ /**
659
+ * We're at the root of the tree, so we're just replacing the entire tree.
660
+ */
661
+ return !parent ? referencedElement : undefined;
662
+ } catch (error) {
663
+ var _this$basePath6, _this$options$derefer9;
664
+ const rootCause = (0, _getRootCause.default)(error);
665
+ const wrappedError = new _SchemaRefError.default(`Could not resolve reference: ${rootCause.message}`, {
666
+ baseDoc: this.reference.uri,
667
+ $ref: (0, _apidomCore.toValue)(referencingElement.$ref),
668
+ fullPath: (_this$basePath6 = this.basePath) != null ? _this$basePath6 : [...(0, _toPath.default)([...ancestors, parent, referencingElement]), '$ref'],
669
+ cause: rootCause
670
+ });
671
+ (_this$options$derefer9 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer9 = _this$options$derefer9.errors) == null || _this$options$derefer9.push == null || _this$options$derefer9.push(wrappedError);
672
+ return undefined;
673
+ }
674
+ }
675
+
676
+ // eslint-disable-next-line class-methods-use-this
677
+ async LinkElement() {
678
+ /**
679
+ * OpenApi3_1DereferenceVisitor is doing lookup of Operation Objects
680
+ * and assigns them to Link Object metadata. This is not needed in
681
+ * swagger-client context, so we're disabling it here.
682
+ */
683
+ return undefined;
684
+ }
685
+ async ExampleElement(exampleElement, key, parent, path, ancestors) {
686
+ try {
687
+ return await super.ExampleElement(exampleElement, key, parent, path, ancestors);
688
+ } catch (error) {
689
+ var _this$basePath7, _this$options$derefer10;
690
+ const rootCause = (0, _getRootCause.default)(error);
691
+ const wrappedError = wrapError(rootCause, {
692
+ baseDoc: this.reference.uri,
693
+ externalValue: (0, _apidomCore.toValue)(exampleElement.externalValue),
694
+ fullPath: (_this$basePath7 = this.basePath) != null ? _this$basePath7 : [...(0, _toPath.default)([...ancestors, parent, exampleElement]), 'externalValue']
695
+ });
696
+ (_this$options$derefer10 = this.options.dereference.dereferenceOpts) == null || (_this$options$derefer10 = _this$options$derefer10.errors) == null || _this$options$derefer10.push == null || _this$options$derefer10.push(wrappedError);
697
+ return undefined;
698
698
  }
699
699
  }
700
- });
701
- var _default = exports.default = OpenApi3_1SwaggerClientDereferenceVisitor;
700
+ }
701
+ var _default = exports.default = OpenAPI3_1SwaggerClientDereferenceVisitor;
702
702
  /* eslint-enable camelcase */