@speclynx/apidom-reference 2.4.0 → 2.5.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 (31) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +23 -1
  3. package/dist/apidom-reference.browser.js +3201 -559
  4. package/dist/apidom-reference.browser.min.js +1 -1
  5. package/package.json +31 -24
  6. package/src/configuration/saturated.cjs +11 -10
  7. package/src/configuration/saturated.mjs +2 -1
  8. package/src/dereference/strategies/arazzo-1/index.cjs +101 -0
  9. package/src/dereference/strategies/arazzo-1/index.mjs +91 -0
  10. package/src/dereference/strategies/arazzo-1/selectors/$anchor.cjs +12 -0
  11. package/src/dereference/strategies/arazzo-1/selectors/$anchor.mjs +1 -0
  12. package/src/dereference/strategies/arazzo-1/selectors/uri.cjs +8 -0
  13. package/src/dereference/strategies/arazzo-1/selectors/uri.mjs +1 -0
  14. package/src/dereference/strategies/arazzo-1/util.cjs +37 -0
  15. package/src/dereference/strategies/arazzo-1/util.mjs +29 -0
  16. package/src/dereference/strategies/arazzo-1/visitor.cjs +411 -0
  17. package/src/dereference/strategies/arazzo-1/visitor.mjs +405 -0
  18. package/src/dereference/strategies/asyncapi-2/visitor.cjs +1 -1
  19. package/src/dereference/strategies/asyncapi-2/visitor.mjs +2 -2
  20. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +2 -2
  21. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +2 -2
  22. package/src/dereference/strategies/openapi-3-1/selectors/uri.cjs +3 -3
  23. package/src/dereference/strategies/openapi-3-1/selectors/uri.mjs +3 -3
  24. package/src/dereference/strategies/openapi-3-1/visitor.cjs +3 -3
  25. package/src/dereference/strategies/openapi-3-1/visitor.mjs +4 -4
  26. package/types/dereference/strategies/arazzo-1/index.d.ts +32 -0
  27. package/types/dereference/strategies/arazzo-1/selectors/$anchor.d.ts +1 -0
  28. package/types/dereference/strategies/arazzo-1/selectors/uri.d.ts +1 -0
  29. package/types/dereference/strategies/arazzo-1/util.d.ts +13 -0
  30. package/types/dereference/strategies/arazzo-1/visitor.d.ts +32 -0
  31. package/types/dereference/strategies/openapi-3-1/util.d.ts +3 -3
@@ -0,0 +1,405 @@
1
+ import { propEq, none } from 'ramda';
2
+ import { isElement, isStringElement, RefElement, cloneShallow, cloneDeep } from '@speclynx/apidom-datamodel';
3
+ import { IdentityManager, toValue } from '@speclynx/apidom-core';
4
+ import { ApiDOMError } from '@speclynx/apidom-error';
5
+ import { traverseAsync } from '@speclynx/apidom-traverse';
6
+ import { evaluate as jsonPointerEvaluate, compile as jsonPointerCompile, URIFragmentIdentifier } from '@speclynx/apidom-json-pointer';
7
+ import { isParameterElement, isJSONSchemaElement, isBooleanJSONSchemaElement } from '@speclynx/apidom-ns-arazzo-1';
8
+ import { parse as parseRuntimeExpression } from '@swaggerexpert/arazzo-runtime-expression';
9
+ import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from "./selectors/$anchor.mjs";
10
+ import { evaluate as uriEvaluate } from "./selectors/uri.mjs";
11
+ import { resolveSchema$refField } from "../openapi-3-1/util.mjs";
12
+ import { maybeRefractToJSONSchemaElement } from "./util.mjs";
13
+ import MaximumDereferenceDepthError from "../../../errors/MaximumDereferenceDepthError.mjs";
14
+ import MaximumResolveDepthError from "../../../errors/MaximumResolveDepthError.mjs";
15
+ import * as url from "../../../util/url.mjs";
16
+ import parse from "../../../parse/index.mjs";
17
+ import Reference from "../../../Reference.mjs";
18
+ import File from "../../../File.mjs";
19
+ import { AncestorLineage } from "../../util.mjs";
20
+ import EvaluationJsonSchemaUriError from "../../../errors/EvaluationJsonSchemaUriError.mjs";
21
+ // initialize element identity manager
22
+ const identityManager = new IdentityManager();
23
+
24
+ /**
25
+ * @public
26
+ */
27
+
28
+ /**
29
+ * @public
30
+ */
31
+ class Arazzo1DereferenceVisitor {
32
+ indirections;
33
+ namespace;
34
+ reference;
35
+ options;
36
+ ancestors;
37
+ constructor({
38
+ reference,
39
+ namespace,
40
+ options,
41
+ indirections = [],
42
+ ancestors = new AncestorLineage()
43
+ }) {
44
+ this.indirections = indirections;
45
+ this.namespace = namespace;
46
+ this.reference = reference;
47
+ this.options = options;
48
+ this.ancestors = new AncestorLineage(...ancestors);
49
+ }
50
+ toBaseURI(uri) {
51
+ return url.resolve(this.reference.uri, url.sanitize(url.stripHash(uri)));
52
+ }
53
+ async toReference(uri) {
54
+ // detect maximum depth of resolution
55
+ if (this.reference.depth >= this.options.resolve.maxDepth) {
56
+ throw new MaximumResolveDepthError(`Maximum resolution depth of ${this.options.resolve.maxDepth} has been exceeded by file "${this.reference.uri}"`);
57
+ }
58
+ const baseURI = this.toBaseURI(uri);
59
+ const {
60
+ refSet
61
+ } = this.reference;
62
+
63
+ // we've already processed this Reference in past
64
+ if (refSet.has(baseURI)) {
65
+ return refSet.find(propEq(baseURI, 'uri'));
66
+ }
67
+ const parseResult = await parse(url.unsanitize(baseURI), {
68
+ ...this.options,
69
+ parse: {
70
+ ...this.options.parse,
71
+ mediaType: 'text/plain'
72
+ }
73
+ });
74
+
75
+ // register new mutable reference with a refSet
76
+ const mutableReference = new Reference({
77
+ uri: baseURI,
78
+ value: cloneDeep(parseResult),
79
+ depth: this.reference.depth + 1
80
+ });
81
+ refSet.add(mutableReference);
82
+ if (this.options.dereference.immutable) {
83
+ // register new immutable reference with a refSet
84
+ const immutableReference = new Reference({
85
+ uri: `immutable://${baseURI}`,
86
+ value: parseResult,
87
+ depth: this.reference.depth + 1
88
+ });
89
+ refSet.add(immutableReference);
90
+ }
91
+ return mutableReference;
92
+ }
93
+ toAncestorLineage(path) {
94
+ /**
95
+ * Compute full ancestors lineage.
96
+ * Ancestors are flatten to unwrap all Element instances.
97
+ */
98
+ const ancestorNodes = path.getAncestorNodes();
99
+ const directAncestors = new Set(ancestorNodes.filter(isElement));
100
+ const ancestorsLineage = new AncestorLineage(...this.ancestors, directAncestors);
101
+ return [ancestorsLineage, directAncestors];
102
+ }
103
+ ReusableElement(path) {
104
+ const referencingElement = path.node;
105
+
106
+ // skip current Reusable Object if reference field is not defined as a string
107
+ if (!isStringElement(referencingElement.reference)) {
108
+ path.skip();
109
+ return;
110
+ }
111
+
112
+ // ignore if resolve.internal is false (Reusable Objects are internal references only)
113
+ if (!this.options.resolve.internal) {
114
+ path.skip();
115
+ return;
116
+ }
117
+ const runtimeExpression = toValue(referencingElement.reference);
118
+
119
+ // parse the runtime expression
120
+ const {
121
+ result,
122
+ tree
123
+ } = parseRuntimeExpression(runtimeExpression);
124
+ if (!result.success) {
125
+ throw new ApiDOMError(`Invalid Reusable Object reference format: "${runtimeExpression}"`);
126
+ }
127
+
128
+ // ReusableElement can only reference components
129
+ if (tree.type !== 'ComponentsExpression') {
130
+ throw new ApiDOMError(`Reusable Object reference "${runtimeExpression}" must be a components expression`);
131
+ }
132
+
133
+ // evaluate runtime expression as JSON Pointer to get the referenced element
134
+ const jsonPointer = jsonPointerCompile(['components', tree.field, tree.subField]);
135
+ let referencedElement;
136
+ try {
137
+ referencedElement = jsonPointerEvaluate(this.reference.value.result, jsonPointer);
138
+ } catch {
139
+ throw new ApiDOMError(`Reusable Object reference "${runtimeExpression}" cannot be resolved`);
140
+ }
141
+
142
+ /**
143
+ * Create a shallow clone of the referenced element to avoid modifying the original.
144
+ */
145
+ const mergedElement = cloneShallow(referencedElement);
146
+ // assign unique id to merged element
147
+ mergedElement.meta.set('id', identityManager.generateId());
148
+ // annotate with info about original referencing element
149
+ mergedElement.meta.set('ref-fields', {
150
+ reference: runtimeExpression,
151
+ value: toValue(referencingElement.value)
152
+ });
153
+ // annotate with info about origin
154
+ mergedElement.meta.set('ref-origin', this.reference.uri);
155
+ // annotate with info about referencing element
156
+ mergedElement.meta.set('ref-referencing-element-id', identityManager.identify(referencingElement));
157
+
158
+ // override value field if present for Parameter Objects
159
+ if (isParameterElement(mergedElement) && referencingElement.hasKey('value')) {
160
+ mergedElement.remove('value');
161
+ mergedElement.set('value', referencingElement.get('value'));
162
+ }
163
+
164
+ /**
165
+ * Transclude referencing element with merged referenced element.
166
+ */
167
+ path.replaceWith(mergedElement);
168
+ }
169
+ async JSONSchemaElement(path) {
170
+ const referencingElement = path.node;
171
+
172
+ // skip current referencing schema as $ref keyword was not defined
173
+ if (!isStringElement(referencingElement.$ref)) {
174
+ return;
175
+ }
176
+
177
+ // skip current referencing element as it's already been accessed
178
+ if (this.indirections.includes(referencingElement)) {
179
+ path.skip();
180
+ return;
181
+ }
182
+ const [ancestorsLineage, directAncestors] = this.toAncestorLineage(path);
183
+
184
+ // compute baseURI using rules around $id and $ref keywords
185
+ let reference = await this.toReference(url.unsanitize(this.reference.uri));
186
+ let {
187
+ uri: retrievalURI
188
+ } = reference;
189
+ const $refBaseURI = resolveSchema$refField(retrievalURI, referencingElement);
190
+ const $refBaseURIStrippedHash = url.stripHash($refBaseURI);
191
+ const file = new File({
192
+ uri: $refBaseURIStrippedHash
193
+ });
194
+ const isUnknownURI = none(r => r.canRead(file), this.options.resolve.resolvers);
195
+ const isURL = !isUnknownURI;
196
+ let isInternalReference = url.stripHash(this.reference.uri) === $refBaseURI;
197
+ let isExternalReference = !isInternalReference;
198
+
199
+ // determining reference, proper evaluation and selection mechanism
200
+ let referencedElement;
201
+ try {
202
+ if (isUnknownURI || isURL) {
203
+ // we're dealing with canonical URI or URL with possible fragment
204
+ retrievalURI = this.toBaseURI($refBaseURI);
205
+ const selector = $refBaseURI;
206
+ const referenceAsSchema = maybeRefractToJSONSchemaElement(reference.value.result);
207
+ referencedElement = uriEvaluate(selector, referenceAsSchema);
208
+ referencedElement = maybeRefractToJSONSchemaElement(referencedElement);
209
+ referencedElement.id = identityManager.identify(referencedElement);
210
+
211
+ // ignore resolving internal Schema Objects
212
+ if (!this.options.resolve.internal && isInternalReference) {
213
+ // skip traversing this schema element but traverse all its child elements
214
+ return;
215
+ }
216
+ // ignore resolving external Schema Objects
217
+ if (!this.options.resolve.external && isExternalReference) {
218
+ // skip traversing this schema element but traverse all its child elements
219
+ return;
220
+ }
221
+ } else {
222
+ // we're assuming here that we're dealing with JSON Pointer here
223
+ retrievalURI = this.toBaseURI($refBaseURI);
224
+ isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
225
+ isExternalReference = !isInternalReference;
226
+
227
+ // ignore resolving internal Schema Objects
228
+ if (!this.options.resolve.internal && isInternalReference) {
229
+ // skip traversing this schema element but traverse all its child elements
230
+ return;
231
+ }
232
+ // ignore resolving external Schema Objects
233
+ if (!this.options.resolve.external && isExternalReference) {
234
+ // skip traversing this schema element but traverse all its child elements
235
+ return;
236
+ }
237
+ reference = await this.toReference(url.unsanitize($refBaseURI));
238
+ const selector = URIFragmentIdentifier.fromURIReference($refBaseURI);
239
+ const referenceAsSchema = maybeRefractToJSONSchemaElement(reference.value.result);
240
+ referencedElement = jsonPointerEvaluate(referenceAsSchema, selector);
241
+ referencedElement = maybeRefractToJSONSchemaElement(referencedElement);
242
+ referencedElement.id = identityManager.identify(referencedElement);
243
+ }
244
+ } catch (error) {
245
+ /**
246
+ * JSONSchemaElement($id=URL) was not found, so we're going to try to resolve
247
+ * the URL and assume the returned response is a JSON Schema.
248
+ */
249
+ if (isURL && error instanceof EvaluationJsonSchemaUriError) {
250
+ if (isAnchor(uriToAnchor($refBaseURI))) {
251
+ // we're dealing with JSON Schema $anchor here
252
+ isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
253
+ isExternalReference = !isInternalReference;
254
+
255
+ // ignore resolving internal Schema Objects
256
+ if (!this.options.resolve.internal && isInternalReference) {
257
+ // skip traversing this schema element but traverse all its child elements
258
+ return;
259
+ }
260
+ // ignore resolving external Schema Objects
261
+ if (!this.options.resolve.external && isExternalReference) {
262
+ // skip traversing this schema element but traverse all its child elements
263
+ return;
264
+ }
265
+ reference = await this.toReference(url.unsanitize($refBaseURI));
266
+ const selector = uriToAnchor($refBaseURI);
267
+ const referenceAsSchema = maybeRefractToJSONSchemaElement(reference.value.result);
268
+ referencedElement = $anchorEvaluate(selector, referenceAsSchema);
269
+ referencedElement = maybeRefractToJSONSchemaElement(referencedElement);
270
+ referencedElement.id = identityManager.identify(referencedElement);
271
+ } else {
272
+ // we're assuming here that we're dealing with JSON Pointer here
273
+ retrievalURI = this.toBaseURI($refBaseURI);
274
+ isInternalReference = url.stripHash(this.reference.uri) === retrievalURI;
275
+ isExternalReference = !isInternalReference;
276
+
277
+ // ignore resolving internal Schema Objects
278
+ if (!this.options.resolve.internal && isInternalReference) {
279
+ // skip traversing this schema element but traverse all its child elements
280
+ return;
281
+ }
282
+ // ignore resolving external Schema Objects
283
+ if (!this.options.resolve.external && isExternalReference) {
284
+ // skip traversing this schema element but traverse all its child elements
285
+ return;
286
+ }
287
+ reference = await this.toReference(url.unsanitize($refBaseURI));
288
+ const selector = URIFragmentIdentifier.fromURIReference($refBaseURI);
289
+ const referenceAsSchema = maybeRefractToJSONSchemaElement(reference.value.result);
290
+ referencedElement = jsonPointerEvaluate(referenceAsSchema, selector);
291
+ referencedElement = maybeRefractToJSONSchemaElement(referencedElement);
292
+ referencedElement.id = identityManager.identify(referencedElement);
293
+ }
294
+ } else {
295
+ throw error;
296
+ }
297
+ }
298
+ this.indirections.push(referencingElement);
299
+
300
+ // detect direct or indirect reference
301
+ if (referencingElement === referencedElement) {
302
+ throw new ApiDOMError('Recursive JSON Schema reference detected');
303
+ }
304
+
305
+ // detect maximum depth of dereferencing
306
+ if (this.indirections.length > this.options.dereference.maxDepth) {
307
+ throw new MaximumDereferenceDepthError(`Maximum dereference depth of "${this.options.dereference.maxDepth}" has been exceeded in file "${this.reference.uri}"`);
308
+ }
309
+
310
+ // detect second deep dive into the same fragment and avoid it
311
+ if (ancestorsLineage.includes(referencedElement)) {
312
+ reference.refSet.circular = true;
313
+ if (this.options.dereference.circular === 'error') {
314
+ throw new ApiDOMError('Circular reference detected');
315
+ } else if (this.options.dereference.circular === 'replace') {
316
+ const refElement = new RefElement(referencedElement.id, {
317
+ type: 'json-schema',
318
+ uri: reference.uri,
319
+ $ref: toValue(referencingElement.$ref)
320
+ });
321
+ const replacer = this.options.dereference.strategyOpts['arazzo-1']?.circularReplacer ?? this.options.dereference.circularReplacer;
322
+ const replacement = replacer(refElement);
323
+ this.indirections.pop();
324
+ path.replaceWith(replacement);
325
+ return;
326
+ }
327
+ }
328
+
329
+ /**
330
+ * Dive deep into the fragment.
331
+ *
332
+ * Cases to consider:
333
+ * 1. We're crossing document boundary
334
+ * 2. Fragment is from non-root document
335
+ * 3. Fragment is a JSON Schema with $ref field. We need to follow it to get the eventual value
336
+ * 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
337
+ */
338
+ const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri;
339
+ const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
340
+ if ((isExternalReference || isNonRootDocument || isJSONSchemaElement(referencedElement) && isStringElement(referencedElement.$ref) || shouldDetectCircular) && !ancestorsLineage.includesCycle(referencedElement)) {
341
+ // append referencing reference to ancestors lineage
342
+ directAncestors.add(referencingElement);
343
+ const visitor = new Arazzo1DereferenceVisitor({
344
+ reference,
345
+ namespace: this.namespace,
346
+ indirections: [...this.indirections],
347
+ options: this.options,
348
+ ancestors: ancestorsLineage
349
+ });
350
+ referencedElement = await traverseAsync(referencedElement, visitor, {
351
+ mutable: true
352
+ });
353
+
354
+ // remove referencing reference from ancestors lineage
355
+ directAncestors.delete(referencingElement);
356
+ }
357
+ this.indirections.pop();
358
+
359
+ // Boolean JSON Schemas
360
+ if (isBooleanJSONSchemaElement(referencedElement)) {
361
+ const booleanJsonSchemaElement = cloneDeep(referencedElement);
362
+ // assign unique id to merged element
363
+ booleanJsonSchemaElement.meta.set('id', identityManager.generateId());
364
+ // annotate referenced element with info about original referencing element
365
+ booleanJsonSchemaElement.meta.set('ref-fields', {
366
+ $ref: toValue(referencingElement.$ref)
367
+ });
368
+ // annotate referenced element with info about origin
369
+ booleanJsonSchemaElement.meta.set('ref-origin', reference.uri);
370
+ // annotate fragment with info about referencing element
371
+ booleanJsonSchemaElement.meta.set('ref-referencing-element-id', cloneDeep(identityManager.identify(referencingElement)));
372
+ path.replaceWith(booleanJsonSchemaElement);
373
+ return;
374
+ }
375
+
376
+ /**
377
+ * Creating a new version of JSON Schema by merging fields from referenced Schema with referencing one.
378
+ */
379
+ if (isJSONSchemaElement(referencedElement)) {
380
+ const mergedElement = cloneShallow(referencedElement);
381
+ // assign unique id to merged element
382
+ mergedElement.meta.set('id', identityManager.generateId());
383
+ // existing keywords from referencing schema overrides ones from referenced schema
384
+ referencingElement.forEach((value, keyElement, item) => {
385
+ mergedElement.remove(toValue(keyElement));
386
+ mergedElement.content.push(item);
387
+ });
388
+ mergedElement.remove('$ref');
389
+ // annotate referenced element with info about original referencing element
390
+ mergedElement.meta.set('ref-fields', {
391
+ $ref: toValue(referencingElement.$ref)
392
+ });
393
+ // annotate fragment with info about origin
394
+ mergedElement.meta.set('ref-origin', reference.uri);
395
+ // annotate fragment with info about referencing element
396
+ mergedElement.meta.set('ref-referencing-element-id', cloneDeep(identityManager.identify(referencingElement)));
397
+ referencedElement = mergedElement;
398
+ }
399
+ /**
400
+ * Transclude referencing element with merged referenced element.
401
+ */
402
+ path.replaceWith(referencedElement);
403
+ }
404
+ }
405
+ export default Arazzo1DereferenceVisitor;
@@ -219,7 +219,7 @@ class AsyncAPI2DereferenceVisitor {
219
219
  this.indirections.pop();
220
220
 
221
221
  // Boolean JSON Schemas
222
- if ((0, _apidomNsAsyncapi.isBooleanJsonSchemaElement)(referencedElement)) {
222
+ if ((0, _apidomNsAsyncapi.isBooleanJSONSchemaElement)(referencedElement)) {
223
223
  const booleanJsonSchemaElement = (0, _apidomDatamodel.cloneDeep)(referencedElement);
224
224
  // assign unique id to merged element
225
225
  booleanJsonSchemaElement.meta.set('id', identityManager.generateId());
@@ -4,7 +4,7 @@ import { IdentityManager, toValue } from '@speclynx/apidom-core';
4
4
  import { ApiDOMError } from '@speclynx/apidom-error';
5
5
  import { traverseAsync } from '@speclynx/apidom-traverse';
6
6
  import { evaluate, URIFragmentIdentifier } from '@speclynx/apidom-json-pointer';
7
- import { isReferenceLikeElement, isBooleanJsonSchemaElement, isChannelItemElement, isReferenceElement, refract, refractReference, refractChannelItem } from '@speclynx/apidom-ns-asyncapi-2';
7
+ import { isReferenceLikeElement, isBooleanJSONSchemaElement, isChannelItemElement, isReferenceElement, refract, refractReference, refractChannelItem } from '@speclynx/apidom-ns-asyncapi-2';
8
8
  import MaximumDereferenceDepthError from "../../../errors/MaximumDereferenceDepthError.mjs";
9
9
  import MaximumResolveDepthError from "../../../errors/MaximumResolveDepthError.mjs";
10
10
  import { AncestorLineage } from "../../util.mjs";
@@ -213,7 +213,7 @@ class AsyncAPI2DereferenceVisitor {
213
213
  this.indirections.pop();
214
214
 
215
215
  // Boolean JSON Schemas
216
- if (isBooleanJsonSchemaElement(referencedElement)) {
216
+ if (isBooleanJSONSchemaElement(referencedElement)) {
217
217
  const booleanJsonSchemaElement = cloneDeep(referencedElement);
218
218
  // assign unique id to merged element
219
219
  booleanJsonSchemaElement.meta.set('id', identityManager.generateId());
@@ -6,7 +6,7 @@ exports.uriToAnchor = exports.parse = exports.isAnchor = exports.evaluate = expo
6
6
  var _ramdaAdjunct = require("ramda-adjunct");
7
7
  var _apidomCore = require("@speclynx/apidom-core");
8
8
  var _apidomTraverse = require("@speclynx/apidom-traverse");
9
- var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
9
+ var _apidomNsJsonSchema = require("@speclynx/apidom-ns-json-schema-2020-12");
10
10
  var _url = require("../../../../util/url.cjs");
11
11
  var _EvaluationJsonSchema$anchorError = _interopRequireDefault(require("../../../../errors/EvaluationJsonSchema$anchorError.cjs"));
12
12
  exports.EvaluationJsonSchema$anchorError = _EvaluationJsonSchema$anchorError.default;
@@ -56,7 +56,7 @@ const evaluate = (anchor, element) => {
56
56
  const token = parse(anchor);
57
57
 
58
58
  // @ts-ignore
59
- const result = (0, _apidomTraverse.find)(element, e => (0, _apidomNsOpenapi.isSchemaElement)(e) && (0, _apidomCore.toValue)(e.$anchor) === token);
59
+ const result = (0, _apidomTraverse.find)(element, e => (0, _apidomNsJsonSchema.isJSONSchemaElement)(e) && (0, _apidomCore.toValue)(e.$anchor) === token);
60
60
  if ((0, _ramdaAdjunct.isUndefined)(result)) {
61
61
  throw new _EvaluationJsonSchema$anchorError.default(`Evaluation failed on token: "${token}"`);
62
62
  }
@@ -1,7 +1,7 @@
1
1
  import { trimCharsStart, isUndefined } from 'ramda-adjunct';
2
2
  import { toValue } from '@speclynx/apidom-core';
3
3
  import { find } from '@speclynx/apidom-traverse';
4
- import { isSchemaElement } from '@speclynx/apidom-ns-openapi-3-1';
4
+ import { isJSONSchemaElement } from '@speclynx/apidom-ns-json-schema-2020-12';
5
5
  import { getHash } from "../../../../util/url.mjs";
6
6
  import EvaluationJsonSchema$anchorError from "../../../../errors/EvaluationJsonSchema$anchorError.mjs";
7
7
  import InvalidJsonSchema$anchorError from "../../../../errors/InvalidJsonSchema$anchorError.mjs";
@@ -44,7 +44,7 @@ export const evaluate = (anchor, element) => {
44
44
  const token = parse(anchor);
45
45
 
46
46
  // @ts-ignore
47
- const result = find(element, e => isSchemaElement(e) && toValue(e.$anchor) === token);
47
+ const result = find(element, e => isJSONSchemaElement(e) && toValue(e.$anchor) === token);
48
48
  if (isUndefined(result)) {
49
49
  throw new EvaluationJsonSchema$anchorError(`Evaluation failed on token: "${token}"`);
50
50
  }
@@ -6,7 +6,7 @@ exports.__esModule = true;
6
6
  exports.evaluate = exports.JsonSchemaUriError = void 0;
7
7
  var _ramdaAdjunct = require("ramda-adjunct");
8
8
  var _apidomTraverse = require("@speclynx/apidom-traverse");
9
- var _apidomNsOpenapi = require("@speclynx/apidom-ns-openapi-3-1");
9
+ var _apidomNsJsonSchema = require("@speclynx/apidom-ns-json-schema-2020-12");
10
10
  var _apidomJsonPointer = require("@speclynx/apidom-json-pointer");
11
11
  var url = _interopRequireWildcard(require("../../../../util/url.cjs"));
12
12
  var _EvaluationJsonSchemaUriError = _interopRequireDefault(require("../../../../errors/EvaluationJsonSchemaUriError.cjs"));
@@ -24,11 +24,11 @@ const evaluate = (uri, element) => {
24
24
  cache
25
25
  } = evaluate;
26
26
  const uriStrippedHash = url.stripHash(uri);
27
- const isSchemaElementWith$id = e => (0, _apidomNsOpenapi.isSchemaElement)(e) && typeof e.$id !== 'undefined';
27
+ const isJSONSchemaElementWith$id = e => (0, _apidomNsJsonSchema.isJSONSchemaElement)(e) && typeof e.$id !== 'undefined';
28
28
 
29
29
  // warm the cache
30
30
  if (!cache.has(element)) {
31
- const schemaObjectElements = (0, _apidomTraverse.filter)(element, isSchemaElementWith$id);
31
+ const schemaObjectElements = (0, _apidomTraverse.filter)(element, isJSONSchemaElementWith$id);
32
32
  cache.set(element, Array.from(schemaObjectElements));
33
33
  }
34
34
 
@@ -1,6 +1,6 @@
1
1
  import { isUndefined } from 'ramda-adjunct';
2
2
  import { filter } from '@speclynx/apidom-traverse';
3
- import { isSchemaElement } from '@speclynx/apidom-ns-openapi-3-1';
3
+ import { isJSONSchemaElement } from '@speclynx/apidom-ns-json-schema-2020-12';
4
4
  import { URIFragmentIdentifier, evaluate as jsonPointerEvaluate } from '@speclynx/apidom-json-pointer';
5
5
  import * as url from "../../../../util/url.mjs";
6
6
  import EvaluationJsonSchemaUriError from "../../../../errors/EvaluationJsonSchemaUriError.mjs";
@@ -15,11 +15,11 @@ export const evaluate = (uri, element) => {
15
15
  cache
16
16
  } = evaluate;
17
17
  const uriStrippedHash = url.stripHash(uri);
18
- const isSchemaElementWith$id = e => isSchemaElement(e) && typeof e.$id !== 'undefined';
18
+ const isJSONSchemaElementWith$id = e => isJSONSchemaElement(e) && typeof e.$id !== 'undefined';
19
19
 
20
20
  // warm the cache
21
21
  if (!cache.has(element)) {
22
- const schemaObjectElements = filter(element, isSchemaElementWith$id);
22
+ const schemaObjectElements = filter(element, isJSONSchemaElementWith$id);
23
23
  cache.set(element, Array.from(schemaObjectElements));
24
24
  }
25
25
 
@@ -542,7 +542,6 @@ class OpenAPI3_1DereferenceVisitor {
542
542
  const isURL = !isUnknownURI;
543
543
  let isInternalReference = url.stripHash(this.reference.uri) === $refBaseURI;
544
544
  let isExternalReference = !isInternalReference;
545
- this.indirections.push(referencingElement);
546
545
 
547
546
  // determining reference, proper evaluation and selection mechanism
548
547
  let referencedElement;
@@ -591,7 +590,7 @@ class OpenAPI3_1DereferenceVisitor {
591
590
  }
592
591
  } catch (error) {
593
592
  /**
594
- * No SchemaElement($id=URL) was not found, so we're going to try to resolve
593
+ * SchemaElement($id=URL) was not found, so we're going to try to resolve
595
594
  * the URL and assume the returned response is a JSON Schema.
596
595
  */
597
596
  if (isURL && error instanceof _EvaluationJsonSchemaUriError.default) {
@@ -643,6 +642,7 @@ class OpenAPI3_1DereferenceVisitor {
643
642
  throw error;
644
643
  }
645
644
  }
645
+ this.indirections.push(referencingElement);
646
646
 
647
647
  // detect direct or indirect reference
648
648
  if (referencingElement === referencedElement) {
@@ -705,7 +705,7 @@ class OpenAPI3_1DereferenceVisitor {
705
705
  this.indirections.pop();
706
706
 
707
707
  // Boolean JSON Schemas
708
- if ((0, _apidomNsOpenapi.isBooleanJsonSchemaElement)(referencedElement)) {
708
+ if ((0, _apidomNsOpenapi.isBooleanJSONSchemaElement)(referencedElement)) {
709
709
  const booleanJsonSchemaElement = (0, _apidomDatamodel.cloneDeep)(referencedElement);
710
710
  // assign unique id to merged element
711
711
  booleanJsonSchemaElement.meta.set('id', identityManager.generateId());
@@ -5,7 +5,7 @@ import { IdentityManager, toValue, fixedFields } from '@speclynx/apidom-core';
5
5
  import { ApiDOMError } from '@speclynx/apidom-error';
6
6
  import { traverseAsync, find } from '@speclynx/apidom-traverse';
7
7
  import { evaluate as jsonPointerEvaluate, URIFragmentIdentifier } from '@speclynx/apidom-json-pointer';
8
- import { isReferenceLikeElement, isPathItemElement, isReferenceElement, isSchemaElement, isOperationElement, isBooleanJsonSchemaElement, refract, refractReference, refractPathItem, refractOperation } from '@speclynx/apidom-ns-openapi-3-1';
8
+ import { isReferenceLikeElement, isPathItemElement, isReferenceElement, isSchemaElement, isOperationElement, isBooleanJSONSchemaElement, refract, refractReference, refractPathItem, refractOperation } from '@speclynx/apidom-ns-openapi-3-1';
9
9
  import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from "./selectors/$anchor.mjs";
10
10
  import { evaluate as uriEvaluate } from "./selectors/uri.mjs";
11
11
  import MaximumDereferenceDepthError from "../../../errors/MaximumDereferenceDepthError.mjs";
@@ -536,7 +536,6 @@ class OpenAPI3_1DereferenceVisitor {
536
536
  const isURL = !isUnknownURI;
537
537
  let isInternalReference = url.stripHash(this.reference.uri) === $refBaseURI;
538
538
  let isExternalReference = !isInternalReference;
539
- this.indirections.push(referencingElement);
540
539
 
541
540
  // determining reference, proper evaluation and selection mechanism
542
541
  let referencedElement;
@@ -585,7 +584,7 @@ class OpenAPI3_1DereferenceVisitor {
585
584
  }
586
585
  } catch (error) {
587
586
  /**
588
- * No SchemaElement($id=URL) was not found, so we're going to try to resolve
587
+ * SchemaElement($id=URL) was not found, so we're going to try to resolve
589
588
  * the URL and assume the returned response is a JSON Schema.
590
589
  */
591
590
  if (isURL && error instanceof EvaluationJsonSchemaUriError) {
@@ -637,6 +636,7 @@ class OpenAPI3_1DereferenceVisitor {
637
636
  throw error;
638
637
  }
639
638
  }
639
+ this.indirections.push(referencingElement);
640
640
 
641
641
  // detect direct or indirect reference
642
642
  if (referencingElement === referencedElement) {
@@ -699,7 +699,7 @@ class OpenAPI3_1DereferenceVisitor {
699
699
  this.indirections.pop();
700
700
 
701
701
  // Boolean JSON Schemas
702
- if (isBooleanJsonSchemaElement(referencedElement)) {
702
+ if (isBooleanJSONSchemaElement(referencedElement)) {
703
703
  const booleanJsonSchemaElement = cloneDeep(referencedElement);
704
704
  // assign unique id to merged element
705
705
  booleanJsonSchemaElement.meta.set('id', identityManager.generateId());
@@ -0,0 +1,32 @@
1
+ import { Element } from '@speclynx/apidom-datamodel';
2
+ import DereferenceStrategy, { DereferenceStrategyOptions } from '../DereferenceStrategy.ts';
3
+ import File from '../../../File.ts';
4
+ import Arazzo1DereferenceVisitor from './visitor.ts';
5
+ import type { ReferenceOptions } from '../../../options/index.ts';
6
+ export type { default as DereferenceStrategy, DereferenceStrategyOptions, } from '../DereferenceStrategy.ts';
7
+ export type { default as File, FileOptions } from '../../../File.ts';
8
+ export type { default as Reference, ReferenceOptions } from '../../../Reference.ts';
9
+ export type { default as ReferenceSet, ReferenceSetOptions } from '../../../ReferenceSet.ts';
10
+ export type { Arazzo1DereferenceVisitorOptions } from './visitor.ts';
11
+ export type { ReferenceOptions as ApiDOMReferenceOptions, ReferenceBundleOptions as ApiDOMReferenceBundleOptions, ReferenceDereferenceOptions as ApiDOMReferenceDereferenceOptions, ReferenceParseOptions as ApiDOMReferenceParseOptions, ReferenceResolveOptions as ApiDOMReferenceResolveOptions, } from '../../../options/index.ts';
12
+ export type { default as Parser, ParserOptions } from '../../../parse/parsers/Parser.ts';
13
+ export type { default as Resolver, ResolverOptions } from '../../../resolve/resolvers/Resolver.ts';
14
+ export type { default as ResolveStrategy, ResolveStrategyOptions, } from '../../../resolve/strategies/ResolveStrategy.ts';
15
+ export type { default as BundleStrategy, BundleStrategyOptions, } from '../../../bundle/strategies/BundleStrategy.ts';
16
+ export type { AncestorLineage } from '../../util.ts';
17
+ /**
18
+ * @public
19
+ */
20
+ export interface Arazzo1DereferenceStrategyOptions extends Omit<DereferenceStrategyOptions, 'name'> {
21
+ }
22
+ /**
23
+ * @public
24
+ */
25
+ declare class Arazzo1DereferenceStrategy extends DereferenceStrategy {
26
+ constructor(options?: Arazzo1DereferenceStrategyOptions);
27
+ canDereference(file: File): boolean;
28
+ dereference(file: File, options: ReferenceOptions): Promise<Element>;
29
+ }
30
+ export { Arazzo1DereferenceVisitor };
31
+ export { resolveSchema$refField, resolveSchema$idField, maybeRefractToJSONSchemaElement, } from './util.ts';
32
+ export default Arazzo1DereferenceStrategy;
@@ -0,0 +1 @@
1
+ export { isAnchor, uriToAnchor, parse, evaluate, EvaluationJsonSchema$anchorError, InvalidJsonSchema$anchorError, JsonSchema$anchorError, } from '../../openapi-3-1/selectors/$anchor.ts';
@@ -0,0 +1 @@
1
+ export { evaluate, EvaluationJsonSchemaUriError, JsonSchemaUriError, } from '../../openapi-3-1/selectors/uri.ts';
@@ -0,0 +1,13 @@
1
+ import { Element } from '@speclynx/apidom-datamodel';
2
+ export { resolveSchema$refField, resolveSchema$idField } from '../openapi-3-1/util.ts';
3
+ /**
4
+ * Cached version of JSONSchemaElement.refract.
5
+ */
6
+ export declare const refractToJSONSchemaElement: {
7
+ <T extends Element>(element: T): any;
8
+ cache: WeakMap<WeakKey, any>;
9
+ };
10
+ /**
11
+ * @public
12
+ */
13
+ export declare const maybeRefractToJSONSchemaElement: <T extends Element>(element: T) => any;