@speclynx/apidom-reference 5.1.0 → 5.2.1

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.
@@ -16,6 +16,7 @@ var _File = _interopRequireDefault(require("../../../File.cjs"));
16
16
  var url = _interopRequireWildcard(require("../../../util/url.cjs"));
17
17
  var _util = require("../../../options/util.cjs");
18
18
  var _index = _interopRequireDefault(require("../../index.cjs"));
19
+ var _util2 = require("../../../dereference/strategies/arazzo-1/util.cjs");
19
20
  // shared key for recursion state (works across JSON/YAML parsers)
20
21
  const ARAZZO_RECURSION_KEY = 'arazzo-1';
21
22
  /**
@@ -188,8 +189,12 @@ async function parseSourceDescriptions(parseResult, parseResultRetrievalURI, opt
188
189
  const currentDepth = sharedOpts.sourceDescriptionsDepth ?? 0;
189
190
  const visitedUrls = sharedOpts.sourceDescriptionsVisitedUrls ?? new Set();
190
191
 
191
- // add current file to visited URLs to prevent cycles
192
+ // base URI for resolving source description URLs honors Arazzo `$self` field
193
+ const baseURI = (0, _util2.resolveArazzo$selfField)(file.uri, api);
194
+
195
+ // add current file to visited URLs to prevent cycles (by retrieval URI and by identity)
192
196
  visitedUrls.add(file.uri);
197
+ visitedUrls.add(baseURI);
193
198
  if (currentDepth >= maxDepth) {
194
199
  const annotation = new _apidomDatamodel.AnnotationElement(`Maximum parse depth of ${maxDepth} has been exceeded by file "${file.uri}"`);
195
200
  annotation.classes.push('error');
@@ -198,7 +203,7 @@ async function parseSourceDescriptions(parseResult, parseResultRetrievalURI, opt
198
203
  return [parseResult];
199
204
  }
200
205
  const ctx = {
201
- baseURI: file.uri,
206
+ baseURI,
202
207
  options,
203
208
  currentDepth,
204
209
  visitedUrls
@@ -7,7 +7,8 @@ import { toValue } from '@speclynx/apidom-core';
7
7
  import File from "../../../File.mjs";
8
8
  import * as url from "../../../util/url.mjs";
9
9
  import { merge as mergeOptions } from "../../../options/util.mjs";
10
- import parse from "../../index.mjs"; // shared key for recursion state (works across JSON/YAML parsers)
10
+ import parse from "../../index.mjs";
11
+ import { resolveArazzo$selfField } from "../../../dereference/strategies/arazzo-1/util.mjs"; // shared key for recursion state (works across JSON/YAML parsers)
11
12
  const ARAZZO_RECURSION_KEY = 'arazzo-1';
12
13
  /**
13
14
  * Parses a single source description element.
@@ -179,8 +180,12 @@ export async function parseSourceDescriptions(parseResult, parseResultRetrievalU
179
180
  const currentDepth = sharedOpts.sourceDescriptionsDepth ?? 0;
180
181
  const visitedUrls = sharedOpts.sourceDescriptionsVisitedUrls ?? new Set();
181
182
 
182
- // add current file to visited URLs to prevent cycles
183
+ // base URI for resolving source description URLs honors Arazzo `$self` field
184
+ const baseURI = resolveArazzo$selfField(file.uri, api);
185
+
186
+ // add current file to visited URLs to prevent cycles (by retrieval URI and by identity)
183
187
  visitedUrls.add(file.uri);
188
+ visitedUrls.add(baseURI);
184
189
  if (currentDepth >= maxDepth) {
185
190
  const annotation = new AnnotationElement(`Maximum parse depth of ${maxDepth} has been exceeded by file "${file.uri}"`);
186
191
  annotation.classes.push('error');
@@ -189,7 +194,7 @@ export async function parseSourceDescriptions(parseResult, parseResultRetrievalU
189
194
  return [parseResult];
190
195
  }
191
196
  const ctx = {
192
- baseURI: file.uri,
197
+ baseURI,
193
198
  options,
194
199
  currentDepth,
195
200
  visitedUrls
@@ -17,6 +17,12 @@ export interface Arazzo1BundleVisitorOptions {
17
17
  */
18
18
  declare class Arazzo1BundleVisitor {
19
19
  protected readonly reference: Reference;
20
+ /**
21
+ * Base URI of the current document for resolving relative references.
22
+ * Honors the Arazzo `$self` field when present, otherwise falls back
23
+ * to the retrieval URI (`this.reference.uri`).
24
+ */
25
+ protected readonly baseURI: string;
20
26
  protected readonly options: ReferenceOptions;
21
27
  /**
22
28
  * The entry parse result. Derived from the shared refSet's root reference.
@@ -28,6 +28,6 @@ declare class Arazzo1DereferenceStrategy extends DereferenceStrategy {
28
28
  dereference(file: File, options: ReferenceOptions): Promise<Element>;
29
29
  }
30
30
  export { Arazzo1DereferenceVisitor };
31
- export { resolveSchema$refField, resolveSchema$idField, maybeRefractToJSONSchemaElement, } from './util.ts';
31
+ export { resolveSchema$refField, resolveSchema$idField, resolveArazzo$selfField, identifiedBy$self, maybeRefractToJSONSchemaElement, } from './util.ts';
32
32
  export { dereferenceSourceDescriptions } from './source-descriptions.ts';
33
33
  export default Arazzo1DereferenceStrategy;
@@ -1,5 +1,27 @@
1
1
  import { Element } from '@speclynx/apidom-datamodel';
2
+ import type Reference from '../../../Reference.ts';
2
3
  export { resolveSchema$refField, resolveSchema$idField } from '../openapi-3-1/util.ts';
4
+ /**
5
+ * Computes the base URI of an Arazzo document per Arazzo 1.1.0 rules.
6
+ *
7
+ * When the Arazzo Object carries a `$self` field, it establishes the document's
8
+ * canonical identity and the base URI for resolving relative references. `$self`
9
+ * may itself be relative, in which case it's resolved against the retrieval URI.
10
+ * Any fragment is stripped, as `$self` MUST NOT contain one. When `$self` is
11
+ * absent (or `element` is not an Arazzo document), the retrieval URI is the base URI.
12
+ *
13
+ * @public
14
+ */
15
+ export declare const resolveArazzo$selfField: (retrievalURI: string, element: unknown) => string;
16
+ /**
17
+ * Predicate matching a Reference by the identity (`$self`) of the Arazzo
18
+ * document it holds, rather than by its retrieval URI. Implements identity-based
19
+ * referencing from Arazzo 1.1.0: a URI matching a loaded document's `$self`
20
+ * refers to that document, regardless of where it was retrieved from.
21
+ *
22
+ * @public
23
+ */
24
+ export declare const identifiedBy$self: (uri: string) => (reference: Reference) => boolean;
3
25
  /**
4
26
  * Cached version of JSONSchemaElement.refract.
5
27
  */
@@ -19,6 +19,12 @@ export interface Arazzo1DereferenceVisitorOptions {
19
19
  declare class Arazzo1DereferenceVisitor {
20
20
  protected readonly indirections: Element[];
21
21
  protected readonly reference: Reference;
22
+ /**
23
+ * Base URI of the current document for resolving relative references.
24
+ * Honors the Arazzo `$self` field when present, otherwise falls back
25
+ * to the retrieval URI (`this.reference.uri`).
26
+ */
27
+ protected readonly baseURI: string;
22
28
  protected readonly options: ReferenceOptions;
23
29
  protected readonly visited: WeakSet<Element>;
24
30
  /**