@speclynx/apidom-reference 6.1.2 → 7.0.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 (106) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +57 -0
  3. package/dist/apidom-reference.browser.js +5783 -3741
  4. package/dist/apidom-reference.browser.min.js +1 -1
  5. package/package.json +31 -30
  6. package/src/File.cjs +5 -2
  7. package/src/File.mjs +5 -2
  8. package/src/bundle/index.cjs +6 -4
  9. package/src/bundle/index.mjs +6 -4
  10. package/src/bundle/strategies/arazzo-1/index.cjs +3 -2
  11. package/src/bundle/strategies/arazzo-1/index.mjs +3 -2
  12. package/src/bundle/strategies/asyncapi-2/index.cjs +3 -2
  13. package/src/bundle/strategies/asyncapi-2/index.mjs +3 -2
  14. package/src/bundle/strategies/openapi-2/index.cjs +3 -2
  15. package/src/bundle/strategies/openapi-2/index.mjs +3 -2
  16. package/src/bundle/strategies/openapi-3-0/index.cjs +3 -2
  17. package/src/bundle/strategies/openapi-3-0/index.mjs +3 -2
  18. package/src/bundle/strategies/openapi-3-1/index.cjs +3 -2
  19. package/src/bundle/strategies/openapi-3-1/index.mjs +3 -2
  20. package/src/dereference/index.cjs +8 -5
  21. package/src/dereference/index.mjs +8 -5
  22. package/src/dereference/strategies/DereferenceVisitor.cjs +588 -0
  23. package/src/dereference/strategies/DereferenceVisitor.mjs +580 -0
  24. package/src/dereference/strategies/arazzo-1/index.cjs +14 -39
  25. package/src/dereference/strategies/arazzo-1/index.mjs +15 -40
  26. package/src/dereference/strategies/arazzo-1/visitor.cjs +207 -331
  27. package/src/dereference/strategies/arazzo-1/visitor.mjs +215 -338
  28. package/src/dereference/strategies/asyncapi-2/index.cjs +11 -39
  29. package/src/dereference/strategies/asyncapi-2/index.mjs +11 -39
  30. package/src/dereference/strategies/asyncapi-2/visitor.cjs +133 -425
  31. package/src/dereference/strategies/asyncapi-2/visitor.mjs +137 -429
  32. package/src/dereference/strategies/openapi-2/index.cjs +12 -42
  33. package/src/dereference/strategies/openapi-2/index.mjs +12 -42
  34. package/src/dereference/strategies/openapi-2/visitor.cjs +168 -532
  35. package/src/dereference/strategies/openapi-2/visitor.mjs +172 -536
  36. package/src/dereference/strategies/openapi-3-0/index.cjs +12 -42
  37. package/src/dereference/strategies/openapi-3-0/index.mjs +12 -42
  38. package/src/dereference/strategies/openapi-3-0/visitor.cjs +194 -468
  39. package/src/dereference/strategies/openapi-3-0/visitor.mjs +199 -473
  40. package/src/dereference/strategies/openapi-3-1/index.cjs +16 -42
  41. package/src/dereference/strategies/openapi-3-1/index.mjs +16 -42
  42. package/src/dereference/strategies/openapi-3-1/visitor.cjs +350 -602
  43. package/src/dereference/strategies/openapi-3-1/visitor.mjs +357 -608
  44. package/src/dereference/strategies/overlay-1/index.cjs +3 -2
  45. package/src/dereference/strategies/overlay-1/index.mjs +3 -2
  46. package/src/index.cjs +0 -7
  47. package/src/index.mjs +0 -1
  48. package/src/options/index.cjs +4 -0
  49. package/src/options/index.mjs +4 -0
  50. package/src/options/util.cjs +7 -1
  51. package/src/options/util.mjs +8 -2
  52. package/src/parse/index.cjs +9 -1
  53. package/src/parse/index.mjs +9 -1
  54. package/src/parse/parsers/apidom-json/index.cjs +2 -1
  55. package/src/parse/parsers/apidom-json/index.mjs +2 -1
  56. package/src/parse/parsers/arazzo-json-1/index.cjs +2 -1
  57. package/src/parse/parsers/arazzo-json-1/index.mjs +2 -1
  58. package/src/parse/parsers/arazzo-yaml-1/index.cjs +2 -1
  59. package/src/parse/parsers/arazzo-yaml-1/index.mjs +2 -1
  60. package/src/parse/parsers/asyncapi-json-2/index.cjs +2 -1
  61. package/src/parse/parsers/asyncapi-json-2/index.mjs +2 -1
  62. package/src/parse/parsers/asyncapi-yaml-2/index.cjs +2 -1
  63. package/src/parse/parsers/asyncapi-yaml-2/index.mjs +2 -1
  64. package/src/parse/parsers/json/index.cjs +2 -1
  65. package/src/parse/parsers/json/index.mjs +2 -1
  66. package/src/parse/parsers/openapi-json-2/index.cjs +2 -1
  67. package/src/parse/parsers/openapi-json-2/index.mjs +2 -1
  68. package/src/parse/parsers/openapi-json-3-0/index.cjs +2 -1
  69. package/src/parse/parsers/openapi-json-3-0/index.mjs +2 -1
  70. package/src/parse/parsers/openapi-json-3-1/index.cjs +2 -1
  71. package/src/parse/parsers/openapi-json-3-1/index.mjs +2 -1
  72. package/src/parse/parsers/openapi-yaml-2/index.cjs +2 -1
  73. package/src/parse/parsers/openapi-yaml-2/index.mjs +2 -1
  74. package/src/parse/parsers/openapi-yaml-3-0/index.cjs +2 -1
  75. package/src/parse/parsers/openapi-yaml-3-0/index.mjs +2 -1
  76. package/src/parse/parsers/openapi-yaml-3-1/index.cjs +2 -1
  77. package/src/parse/parsers/openapi-yaml-3-1/index.mjs +2 -1
  78. package/src/parse/parsers/overlay-json-1/index.cjs +2 -1
  79. package/src/parse/parsers/overlay-json-1/index.mjs +2 -1
  80. package/src/parse/parsers/overlay-yaml-1/index.cjs +2 -1
  81. package/src/parse/parsers/overlay-yaml-1/index.mjs +2 -1
  82. package/src/parse/parsers/yaml-1-2/index.cjs +2 -1
  83. package/src/parse/parsers/yaml-1-2/index.mjs +2 -1
  84. package/src/resolve/index.cjs +6 -3
  85. package/src/resolve/index.mjs +6 -3
  86. package/src/util/url.cjs +38 -8
  87. package/src/util/url.mjs +35 -6
  88. package/types/apidom-reference.d.ts +13 -9
  89. package/types/dereference/strategies/DereferenceVisitor.d.ts +224 -0
  90. package/types/dereference/strategies/arazzo-1/index.d.ts +0 -1
  91. package/types/dereference/strategies/arazzo-1/visitor.d.ts +38 -38
  92. package/types/dereference/strategies/asyncapi-2/index.d.ts +0 -1
  93. package/types/dereference/strategies/asyncapi-2/visitor.d.ts +13 -29
  94. package/types/dereference/strategies/openapi-2/index.d.ts +0 -1
  95. package/types/dereference/strategies/openapi-2/visitor.d.ts +14 -29
  96. package/types/dereference/strategies/openapi-3-0/index.d.ts +0 -1
  97. package/types/dereference/strategies/openapi-3-0/visitor.d.ts +13 -28
  98. package/types/dereference/strategies/openapi-3-1/index.d.ts +0 -1
  99. package/types/dereference/strategies/openapi-3-1/visitor.d.ts +37 -33
  100. package/types/index.d.ts +0 -1
  101. package/types/util/url.d.ts +11 -0
  102. package/LICENSES/AFL-3.0.txt +0 -182
  103. package/LICENSES/BSD-3-Clause.txt +0 -26
  104. package/src/dereference/util.cjs +0 -33
  105. package/src/dereference/util.mjs +0 -27
  106. package/types/dereference/util.d.ts +0 -9
package/CHANGELOG.md CHANGED
@@ -3,6 +3,69 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [7.0.0](https://github.com/speclynx/apidom/compare/v6.2.0...v7.0.0) (2026-11-08)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **reference:** address arazzo-1 dereference review findings ([319775e](https://github.com/speclynx/apidom/commit/319775e226c65e9dd123f1b0f08618f9e003ded6)), closes [#757](https://github.com/speclynx/apidom/issues/757)
11
+ - **reference:** address dereference by expected type review findings ([d08052d](https://github.com/speclynx/apidom/commit/d08052dd65470057fe0fb49ccb9c22826aa080a3)), closes [#757](https://github.com/speclynx/apidom/issues/757)
12
+ - **reference:** dereference arazzo-1 references by expected type ([76570ce](https://github.com/speclynx/apidom/commit/76570ce6f5aacf61038c0474d10ba816b8fa486d)), closes [#751](https://github.com/speclynx/apidom/issues/751) [#757](https://github.com/speclynx/apidom/issues/757)
13
+ - **reference:** dereference asyncapi-2 references by expected type ([0ea89fd](https://github.com/speclynx/apidom/commit/0ea89fdd7a7c6e2329336980c805050cf1b8ad80)), closes [#753](https://github.com/speclynx/apidom/issues/753) [#756](https://github.com/speclynx/apidom/issues/756)
14
+ - **reference:** dereference each shared reusable component once ([cc26ac4](https://github.com/speclynx/apidom/commit/cc26ac4fb5573913155383624e86da6213febd04)), closes [#751](https://github.com/speclynx/apidom/issues/751)
15
+ - **reference:** dereference frozen elements without editing them ([98917c0](https://github.com/speclynx/apidom/commit/98917c0d636517c338533316a5ee793810f647e9)), closes [#766](https://github.com/speclynx/apidom/issues/766)
16
+ - **reference:** dereference openapi-2 references by expected type ([b1bbe37](https://github.com/speclynx/apidom/commit/b1bbe37156714e0e837a52c83aac17bed96dbe98)), closes [#753](https://github.com/speclynx/apidom/issues/753) [#756](https://github.com/speclynx/apidom/issues/756)
17
+ - **reference:** dereference openapi-3-0 references by expected type ([d570b0c](https://github.com/speclynx/apidom/commit/d570b0c1c35a826b7c2372c4deb807c15af4d6bb)), closes [#753](https://github.com/speclynx/apidom/issues/753) [#756](https://github.com/speclynx/apidom/issues/756)
18
+ - **reference:** dereference openapi-3-1 references by expected type ([70c7f94](https://github.com/speclynx/apidom/commit/70c7f94632185dba21cfa1aa5eafeaaaa786e27f)), closes [#754](https://github.com/speclynx/apidom/issues/754) [#756](https://github.com/speclynx/apidom/issues/756)
19
+ - **reference:** dereference reusable objects nested in components ([64dff81](https://github.com/speclynx/apidom/commit/64dff81cc9d62a3b518db2b9b95f0335d529fdc3)), closes [#751](https://github.com/speclynx/apidom/issues/751)
20
+ - **reference:** detect generic targets by class in DereferenceVisitor ([5baea86](https://github.com/speclynx/apidom/commit/5baea86a9d8ac2d479380a3e12c8abaa84981e48)), closes [#757](https://github.com/speclynx/apidom/issues/757)
21
+ - **reference:** report error locations in external documents once ([a24358b](https://github.com/speclynx/apidom/commit/a24358b4e668ec6860798058a5a0210568211cde)), closes [#555](https://github.com/speclynx/apidom/issues/555)
22
+ - **reference:** select parsers by the given media type first ([5b490c7](https://github.com/speclynx/apidom/commit/5b490c7c16517b373fc985c3ec3fb42efb7ad454)), closes [#620](https://github.com/speclynx/apidom/issues/620)
23
+ - **reference:** skip only dereferenced elements in arazzo-1 deref ([4789960](https://github.com/speclynx/apidom/commit/47899604d0796932d127f14f2419facdefeee8e6)), closes [#751](https://github.com/speclynx/apidom/issues/751)
24
+ - **reference:** skip parsed source descriptions in arazzo-1 deref ([45f4484](https://github.com/speclynx/apidom/commit/45f448474ac0db8ad08f580f2e50df74db6bb96f)), closes [#757](https://github.com/speclynx/apidom/issues/757)
25
+ - **traverse:** use the leaving node's own key on leave ([a44ef46](https://github.com/speclynx/apidom/commit/a44ef467872a2b0e724b4cbd37187374f14f3ea2)), closes [#16](https://github.com/speclynx/apidom/issues/16)
26
+
27
+ ### Code Refactoring
28
+
29
+ - **reference:** remove AncestorLineage ([e9e62c2](https://github.com/speclynx/apidom/commit/e9e62c2da1dcb5526eafd75e1898db8a1f1ed157)), closes [#757](https://github.com/speclynx/apidom/issues/757)
30
+
31
+ ### BREAKING CHANGES
32
+
33
+ - **reference:** Arazzo1DereferenceVisitor no longer dereferences when
34
+ traversed directly: its dereference(element) method does, and its
35
+ handlers only record transclusions. Arazzo1DereferenceVisitorOptions no
36
+ longer accepts indirections, ancestors and visited. A Reusable Object
37
+ referencing a component of another type yields that component refracted
38
+ to the expected type, and a JSON Schema $ref to a non-schema element
39
+ yields a JSON Schema. A ReferenceSet passed to the arazzo-1 strategy
40
+ is no longer cloned with immutable=true: documents loaded during
41
+ dereference are added to it as parsed, and its circular flag is set.
42
+ - **reference:** DereferenceAncestorLineage is no longer exported, nor
43
+ is the AncestorLineage type from the dereference strategies.
44
+ OpenAPI3_1DereferenceVisitor, OpenAPI3_0DereferenceVisitor,
45
+ OpenAPI2DereferenceVisitor and AsyncAPI2DereferenceVisitor extend
46
+ - **reference:** when parse.mediaType is listed by a parser, that parser
47
+ parses the file even if the file's contents are detected as another
48
+ specification or version by an earlier configured parser. Media types
49
+ differing from the listed ones only in case, whitespace or additional
50
+ parameters, or listed with wildcards, now select the parsers and
51
+ strategies listing them instead of falling back to detection or
52
+ matching no strategy. File.mediaType is trimmed, and text/plain for a
53
+ blank media type or one that isn't a string.
54
+
55
+ # [6.2.0](https://github.com/speclynx/apidom/compare/v6.1.2...v6.2.0) (2026-11-07)
56
+
57
+ ### Bug Fixes
58
+
59
+ - **reference:** decode file system path characters only once ([41b8476](https://github.com/speclynx/apidom/commit/41b8476ca854b4eb0225e7b07736a416f7420e31)), closes [#733](https://github.com/speclynx/apidom/issues/733)
60
+ - **reference:** keep an encoded file:// page URL as default baseURI ([af3bfe0](https://github.com/speclynx/apidom/commit/af3bfe09690ad0c9289cf9bd3411bf3ebb4a9413)), closes [#733](https://github.com/speclynx/apidom/issues/733)
61
+ - **reference:** normalize root URI across entry points ([9c2475d](https://github.com/speclynx/apidom/commit/9c2475d2ad4da4ae3b2bdc54e353f754655463ef)), closes [#733](https://github.com/speclynx/apidom/issues/733)
62
+ - **reference:** round-trip '?' in file system paths ([bb4af5b](https://github.com/speclynx/apidom/commit/bb4af5b9a980ea97688ad6b919b3bb932dd55257)), closes [#733](https://github.com/speclynx/apidom/issues/733)
63
+ - **reference:** sanitize the path of file:// URLs in url.normalize ([8db965b](https://github.com/speclynx/apidom/commit/8db965baac0667eafd5ca2ab2bf695595c6c8831)), closes [#733](https://github.com/speclynx/apidom/issues/733)
64
+
65
+ ### Features
66
+
67
+ - **reference:** add url.normalize util ([dcb7aea](https://github.com/speclynx/apidom/commit/dcb7aeaa6aa91b9c28fc52e769e7e6fd9848be36)), closes [#733](https://github.com/speclynx/apidom/issues/733)
68
+
6
69
  ## [6.1.2](https://github.com/speclynx/apidom/compare/v6.1.1...v6.1.2) (2026-10-29)
7
70
 
8
71
  **Note:** Version bump only for package @speclynx/apidom-reference
package/README.md CHANGED
@@ -79,6 +79,15 @@ await parse('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/ex
79
79
  Notice how we explicitly pass a `mediaType` parse option. This option is actually **not required**,
80
80
  but if not provided, the Parse component will try to identify appropriate parser plugin by file contents, and it's extension (`.json`).
81
81
 
82
+ When provided, the parser plugins listing the `mediaType` parse the file first, before the ones detecting it by its contents,
83
+ which are only used when the listing ones fail. A media type of a serialization format only (`application/json`, `application/yaml`,
84
+ `text/yaml`) names no specification, so for it the parser plugins keep their configured order, which puts the specific ones
85
+ (e.g. OpenAPI JSON) before the generic ones (JSON). Media types are compared as defined by [RFC 9110](https://www.rfc-editor.org/rfc/rfc9110#section-8.3.1):
86
+ type, subtype and parameter names ignore case, whitespace around the media type and its parameters doesn't matter, and the given media type
87
+ may carry additional parameters, so a `Content-Type` value like `application/openapi+yaml; version=3.1.2; charset=utf-8`
88
+ selects the OpenAPI 3.1 YAML parser. Resolve, dereference and bundle strategies compare the `mediaType` with the media types
89
+ they list the same way.
90
+
82
91
  What actually happens if you don't provide `mediaType` parse option?
83
92
 
84
93
  ```js
@@ -1536,6 +1545,12 @@ await resolve('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/
1536
1545
  When externally resolving an ApiDOM fragment, [baseURI](https://github.com/speclynx/apidom/blob/91763fa4ad876375a413e7049c28c2031c7bbe83/apidom/packages/apidom-reference/src/options/index.ts#L47)
1537
1546
  resolve option needs to be provided to have a starting point for external dependency resolution.
1538
1547
  `mediaType` parse option is unnecessary as we can directly assert the type of ApiDOM fragment.
1548
+ A fragment in `baseURI` means the ApiDOM fragment is located at that fragment of the document,
1549
+ e.g. `/home/user/root.json#/components/parameters/userId`. When passing a whole document,
1550
+ give `baseURI` without a fragment.
1551
+ `baseURI` must be absolute: a file system path, a `file://` URL or an HTTP(S) URL. It defaults
1552
+ to the current working directory (the page URL in browsers). The same applies to the file passed
1553
+ to `resolve`, `dereference` or `bundle`; resolve a relative path first, e.g. with `path.resolve`.
1539
1554
 
1540
1555
  ```js
1541
1556
  import { OpenApi3_1Element } from '@speclynx/apidom-ns-openapi-3-1';
@@ -1937,6 +1952,12 @@ await dereference('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/m
1937
1952
  When dereferencing an ApiDOM fragment, [baseURI](https://github.com/speclynx/apidom/blob/91763fa4ad876375a413e7049c28c2031c7bbe83/apidom/packages/apidom-reference/src/options/index.ts#L47)
1938
1953
  resolve option needs to be provided to have a starting point for external dependency resolution.
1939
1954
  `mediaType` parse option is unnecessary as we can directly assert the type of ApiDOM fragment.
1955
+ A fragment in `baseURI` means the ApiDOM fragment is located at that fragment of the document,
1956
+ e.g. `/home/user/root.json#/components/parameters/userId`. When passing a whole document,
1957
+ give `baseURI` without a fragment.
1958
+ `baseURI` must be absolute: a file system path, a `file://` URL or an HTTP(S) URL. It defaults
1959
+ to the current working directory (the page URL in browsers). The same applies to the file passed
1960
+ to `resolve`, `dereference` or `bundle`; resolve a relative path first, e.g. with `path.resolve`.
1940
1961
 
1941
1962
  **ex.json**
1942
1963
 
@@ -1987,6 +2008,13 @@ const dereferenced = await dereferenceApiDOM(apidom, {
1987
2008
  Dereference strategy determines how a document is internally or externally dereferenced. Depending on document `mediaType` option,
1988
2009
  every strategy differs significantly. `Dereference component` comes with six (6) default dereference strategies.
1989
2010
 
2011
+ The `arazzo-1`, `asyncapi-2`, `openapi-2`, `openapi-3-0` and `openapi-3-1` strategies read a referenced structure
2012
+ as the type its reference expects (a structure referenced as a Parameter Object and as a Header Object is read as both),
2013
+ and dereference it once per type. Elements transcluded in place of references carry the `ref-type` meta.
2014
+ Frozen elements aren't edited: when the dereferenced element, a document of the `dereference.refSet` or its parsed
2015
+ result is frozen, `dereference.immutable: false` dereferences as `dereference.immutable: true` does, for the whole run.
2016
+ Only these are checked: a frozen element within an unfrozen document is dereferenced in place.
2017
+
1990
2018
  #### [apidom](https://github.com/speclynx/apidom/tree/main/packages/apidom-reference/src/dereference/strategies/apidom)
1991
2019
 
1992
2020
  Dereference strategy for dereferencing ApiDOM using [Ref Element](https://apielements.org/en/latest/element-definitions.html?highlight=referencing#ref-element).
@@ -2043,6 +2071,35 @@ base URI. Per Arazzo 1.1.0, the base URI is the Arazzo Object's `$self` field wh
2043
2071
  against the retrieval URI when relative), otherwise the retrieval URI. A reference whose URI matches the `$self`
2044
2072
  of an already loaded Arazzo document resolves to that document by identity, without fetching it again.
2045
2073
 
2074
+ With `dereference.immutable` (the default) the dereferenced documents aren't edited: the result is a new tree.
2075
+ With `dereference.immutable: false` the documents are dereferenced in place and the dereferenced
2076
+ ParseResultElement itself is returned. Elements transcluded in place of references carry the `ref-type` meta
2077
+ and aren't traversed again, so dereferencing a document dereferenced in place earlier leaves those parts as they are.
2078
+
2079
+ The **reference decides the type of what it points at**. A Reusable Object (`reference` field holding
2080
+ a `$components.*` runtime expression) reads its target as the type it expects in its position: a Parameter in
2081
+ `parameters`, a Success Action in `onSuccess` / `successActions`, a Failure Action in `onFailure` / `failureActions`.
2082
+ A JSON Schema `$ref` reads its target as a JSON Schema, whatever object it is otherwise (e.g. a Parameter
2083
+ component), keeping the keywords next to the `$ref`. A target of a different type is refracted to the expected type
2084
+ from the target dereferenced as its own type, so the result doesn't depend on which reference reaches it first;
2085
+ the component itself keeps its own type. Reusable Objects and `$ref`s nested within the target are dereferenced too
2086
+ (e.g. Parameter references in the `parameters` of a component Success or Failure Action), and the `value` field
2087
+ of a Reusable Object overrides the `value` of the Parameter it references.
2088
+
2089
+ Every referenced structure is dereferenced once per type and shared by all the references reading it as that type,
2090
+ and each unresolvable reference is reported once. `dereference.maxDepth` limits the number of references followed
2091
+ in a row, Reusable Objects and `$ref`s alike. A reference leading back to a structure that's still being
2092
+ dereferenced is a circular reference and is handled per the `dereference.circular` option: `ignore` creates
2093
+ a cyclic structure, `error` fails with an `UnresolvableReferenceError` and `replace` substitutes a `RefElement`
2094
+ processed by the `circularReplacer` (`dereference.strategyOpts['arazzo-1'].circularReplacer` takes precedence over
2095
+ `dereference.circularReplacer`). Parsed Arazzo documents form circular references through JSON Schema `$ref`s;
2096
+ Reusable Objects, read as their expected types, don't lead back to the components holding them, but are handled
2097
+ the same way when they do.
2098
+
2099
+ Source Descriptions parsed into the document (`parse.parserOpts.sourceDescriptions`) are never dereferenced in
2100
+ the context of the document referencing them: they're left as parsed, or dereferenced in their own context when
2101
+ the `sourceDescriptions` strategy option is set.
2102
+
2046
2103
  Supported media types:
2047
2104
 
2048
2105
  ```js