@speclynx/apidom-reference 1.12.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.
Files changed (263) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/LICENSE +202 -0
  3. package/LICENSES/AFL-3.0.txt +182 -0
  4. package/LICENSES/Apache-2.0.txt +202 -0
  5. package/LICENSES/BSD-3-Clause.txt +26 -0
  6. package/LICENSES/MIT.txt +9 -0
  7. package/NOTICE +65 -0
  8. package/README.md +2107 -0
  9. package/dist/167.apidom-reference.browser.js +10 -0
  10. package/dist/167.apidom-reference.browser.min.js +1 -0
  11. package/dist/451.apidom-reference.browser.js +10 -0
  12. package/dist/451.apidom-reference.browser.min.js +1 -0
  13. package/dist/9786785aaddf11f37840fad896531940.wasm +0 -0
  14. package/dist/apidom-reference.browser.js +85376 -0
  15. package/dist/apidom-reference.browser.min.js +1 -0
  16. package/package.json +304 -0
  17. package/src/File.cjs +50 -0
  18. package/src/File.mjs +44 -0
  19. package/src/Reference.cjs +31 -0
  20. package/src/Reference.mjs +27 -0
  21. package/src/ReferenceSet.cjs +60 -0
  22. package/src/ReferenceSet.mjs +57 -0
  23. package/src/bundle/index.cjs +61 -0
  24. package/src/bundle/index.mjs +55 -0
  25. package/src/bundle/strategies/BundleStrategy.cjs +20 -0
  26. package/src/bundle/strategies/BundleStrategy.mjs +16 -0
  27. package/src/bundle/strategies/openapi-3-1/index.cjs +35 -0
  28. package/src/bundle/strategies/openapi-3-1/index.mjs +29 -0
  29. package/src/configuration/empty.cjs +9 -0
  30. package/src/configuration/empty.mjs +1 -0
  31. package/src/configuration/saturated.cjs +95 -0
  32. package/src/configuration/saturated.mjs +87 -0
  33. package/src/dereference/index.cjs +86 -0
  34. package/src/dereference/index.mjs +79 -0
  35. package/src/dereference/strategies/DereferenceStrategy.cjs +20 -0
  36. package/src/dereference/strategies/DereferenceStrategy.mjs +16 -0
  37. package/src/dereference/strategies/apidom/index.cjs +89 -0
  38. package/src/dereference/strategies/apidom/index.mjs +84 -0
  39. package/src/dereference/strategies/apidom/selectors/element-id.cjs +36 -0
  40. package/src/dereference/strategies/apidom/selectors/element-id.mjs +30 -0
  41. package/src/dereference/strategies/apidom/visitor.cjs +165 -0
  42. package/src/dereference/strategies/apidom/visitor.mjs +159 -0
  43. package/src/dereference/strategies/asyncapi-2/index.cjs +100 -0
  44. package/src/dereference/strategies/asyncapi-2/index.mjs +94 -0
  45. package/src/dereference/strategies/asyncapi-2/visitor.cjs +412 -0
  46. package/src/dereference/strategies/asyncapi-2/visitor.mjs +406 -0
  47. package/src/dereference/strategies/openapi-2/index.cjs +102 -0
  48. package/src/dereference/strategies/openapi-2/index.mjs +96 -0
  49. package/src/dereference/strategies/openapi-2/visitor.cjs +530 -0
  50. package/src/dereference/strategies/openapi-2/visitor.mjs +524 -0
  51. package/src/dereference/strategies/openapi-3-0/index.cjs +102 -0
  52. package/src/dereference/strategies/openapi-3-0/index.mjs +96 -0
  53. package/src/dereference/strategies/openapi-3-0/visitor.cjs +519 -0
  54. package/src/dereference/strategies/openapi-3-0/visitor.mjs +513 -0
  55. package/src/dereference/strategies/openapi-3-1/index.cjs +105 -0
  56. package/src/dereference/strategies/openapi-3-1/index.mjs +96 -0
  57. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.cjs +66 -0
  58. package/src/dereference/strategies/openapi-3-1/selectors/$anchor.mjs +55 -0
  59. package/src/dereference/strategies/openapi-3-1/selectors/uri.cjs +50 -0
  60. package/src/dereference/strategies/openapi-3-1/selectors/uri.mjs +42 -0
  61. package/src/dereference/strategies/openapi-3-1/util.cjs +67 -0
  62. package/src/dereference/strategies/openapi-3-1/util.mjs +58 -0
  63. package/src/dereference/strategies/openapi-3-1/visitor.cjs +776 -0
  64. package/src/dereference/strategies/openapi-3-1/visitor.mjs +770 -0
  65. package/src/dereference/util.cjs +31 -0
  66. package/src/dereference/util.mjs +27 -0
  67. package/src/errors/BundleError.cjs +10 -0
  68. package/src/errors/BundleError.mjs +7 -0
  69. package/src/errors/DereferenceError.cjs +10 -0
  70. package/src/errors/DereferenceError.mjs +7 -0
  71. package/src/errors/EvaluationElementIdError.cjs +10 -0
  72. package/src/errors/EvaluationElementIdError.mjs +7 -0
  73. package/src/errors/EvaluationJsonSchema$anchorError.cjs +11 -0
  74. package/src/errors/EvaluationJsonSchema$anchorError.mjs +6 -0
  75. package/src/errors/EvaluationJsonSchemaUriError.cjs +11 -0
  76. package/src/errors/EvaluationJsonSchemaUriError.mjs +6 -0
  77. package/src/errors/InvalidJsonSchema$anchorError.cjs +15 -0
  78. package/src/errors/InvalidJsonSchema$anchorError.mjs +10 -0
  79. package/src/errors/JsonSchema$anchorError.cjs +10 -0
  80. package/src/errors/JsonSchema$anchorError.mjs +7 -0
  81. package/src/errors/JsonSchemaUriError.cjs +10 -0
  82. package/src/errors/JsonSchemaUriError.mjs +7 -0
  83. package/src/errors/MaximumBundleDepthError.cjs +11 -0
  84. package/src/errors/MaximumBundleDepthError.mjs +6 -0
  85. package/src/errors/MaximumDereferenceDepthError.cjs +11 -0
  86. package/src/errors/MaximumDereferenceDepthError.mjs +6 -0
  87. package/src/errors/MaximumResolveDepthError.cjs +11 -0
  88. package/src/errors/MaximumResolveDepthError.mjs +6 -0
  89. package/src/errors/ParseError.cjs +10 -0
  90. package/src/errors/ParseError.mjs +7 -0
  91. package/src/errors/ParserError.cjs +11 -0
  92. package/src/errors/ParserError.mjs +6 -0
  93. package/src/errors/PluginError.cjs +18 -0
  94. package/src/errors/PluginError.mjs +15 -0
  95. package/src/errors/ResolveError.cjs +10 -0
  96. package/src/errors/ResolveError.mjs +7 -0
  97. package/src/errors/ResolverError.cjs +11 -0
  98. package/src/errors/ResolverError.mjs +6 -0
  99. package/src/errors/UnmatchedBundleStrategyError.cjs +11 -0
  100. package/src/errors/UnmatchedBundleStrategyError.mjs +6 -0
  101. package/src/errors/UnmatchedDereferenceStrategyError.cjs +11 -0
  102. package/src/errors/UnmatchedDereferenceStrategyError.mjs +6 -0
  103. package/src/errors/UnmatchedResolveStrategyError.cjs +11 -0
  104. package/src/errors/UnmatchedResolveStrategyError.mjs +6 -0
  105. package/src/errors/UnmatchedResolverError.cjs +11 -0
  106. package/src/errors/UnmatchedResolverError.mjs +6 -0
  107. package/src/index.cjs +142 -0
  108. package/src/index.mjs +101 -0
  109. package/src/options/index.cjs +185 -0
  110. package/src/options/index.mjs +182 -0
  111. package/src/options/util.cjs +24 -0
  112. package/src/options/util.mjs +19 -0
  113. package/src/parse/index.cjs +69 -0
  114. package/src/parse/index.mjs +63 -0
  115. package/src/parse/parsers/Parser.cjs +48 -0
  116. package/src/parse/parsers/Parser.mjs +44 -0
  117. package/src/parse/parsers/api-design-systems-json/index.cjs +55 -0
  118. package/src/parse/parsers/api-design-systems-json/index.mjs +49 -0
  119. package/src/parse/parsers/api-design-systems-yaml/index.cjs +54 -0
  120. package/src/parse/parsers/api-design-systems-yaml/index.mjs +48 -0
  121. package/src/parse/parsers/apidom-json/index.cjs +70 -0
  122. package/src/parse/parsers/apidom-json/index.mjs +64 -0
  123. package/src/parse/parsers/arazzo-json-1/index.cjs +55 -0
  124. package/src/parse/parsers/arazzo-json-1/index.mjs +49 -0
  125. package/src/parse/parsers/arazzo-yaml-1/index.cjs +54 -0
  126. package/src/parse/parsers/arazzo-yaml-1/index.mjs +48 -0
  127. package/src/parse/parsers/asyncapi-json-2/index.cjs +55 -0
  128. package/src/parse/parsers/asyncapi-json-2/index.mjs +49 -0
  129. package/src/parse/parsers/asyncapi-yaml-2/index.cjs +54 -0
  130. package/src/parse/parsers/asyncapi-yaml-2/index.mjs +48 -0
  131. package/src/parse/parsers/binary/index-browser.cjs +56 -0
  132. package/src/parse/parsers/binary/index-browser.mjs +50 -0
  133. package/src/parse/parsers/binary/index-node.cjs +51 -0
  134. package/src/parse/parsers/binary/index-node.mjs +45 -0
  135. package/src/parse/parsers/json/index.cjs +54 -0
  136. package/src/parse/parsers/json/index.mjs +48 -0
  137. package/src/parse/parsers/openapi-json-2/index.cjs +55 -0
  138. package/src/parse/parsers/openapi-json-2/index.mjs +49 -0
  139. package/src/parse/parsers/openapi-json-3-0/index.cjs +55 -0
  140. package/src/parse/parsers/openapi-json-3-0/index.mjs +49 -0
  141. package/src/parse/parsers/openapi-json-3-1/index.cjs +55 -0
  142. package/src/parse/parsers/openapi-json-3-1/index.mjs +49 -0
  143. package/src/parse/parsers/openapi-yaml-2/index.cjs +54 -0
  144. package/src/parse/parsers/openapi-yaml-2/index.mjs +48 -0
  145. package/src/parse/parsers/openapi-yaml-3-0/index.cjs +54 -0
  146. package/src/parse/parsers/openapi-yaml-3-0/index.mjs +48 -0
  147. package/src/parse/parsers/openapi-yaml-3-1/index.cjs +54 -0
  148. package/src/parse/parsers/openapi-yaml-3-1/index.mjs +48 -0
  149. package/src/parse/parsers/yaml-1-2/index.cjs +54 -0
  150. package/src/parse/parsers/yaml-1-2/index.mjs +48 -0
  151. package/src/resolve/index.cjs +67 -0
  152. package/src/resolve/index.mjs +60 -0
  153. package/src/resolve/resolvers/HTTPResolver.cjs +38 -0
  154. package/src/resolve/resolvers/HTTPResolver.mjs +31 -0
  155. package/src/resolve/resolvers/Resolver.cjs +20 -0
  156. package/src/resolve/resolvers/Resolver.mjs +16 -0
  157. package/src/resolve/resolvers/file/index-browser.cjs +24 -0
  158. package/src/resolve/resolvers/file/index-browser.mjs +19 -0
  159. package/src/resolve/resolvers/file/index-node.cjs +49 -0
  160. package/src/resolve/resolvers/file/index-node.mjs +42 -0
  161. package/src/resolve/resolvers/http-axios/index.cjs +80 -0
  162. package/src/resolve/resolvers/http-axios/index.mjs +73 -0
  163. package/src/resolve/strategies/ResolveStrategy.cjs +20 -0
  164. package/src/resolve/strategies/ResolveStrategy.mjs +16 -0
  165. package/src/resolve/strategies/apidom/index.cjs +49 -0
  166. package/src/resolve/strategies/apidom/index.mjs +43 -0
  167. package/src/resolve/strategies/asyncapi-2/index.cjs +49 -0
  168. package/src/resolve/strategies/asyncapi-2/index.mjs +43 -0
  169. package/src/resolve/strategies/openapi-2/index.cjs +49 -0
  170. package/src/resolve/strategies/openapi-2/index.mjs +43 -0
  171. package/src/resolve/strategies/openapi-3-0/index.cjs +49 -0
  172. package/src/resolve/strategies/openapi-3-0/index.mjs +43 -0
  173. package/src/resolve/strategies/openapi-3-1/index.cjs +49 -0
  174. package/src/resolve/strategies/openapi-3-1/index.mjs +43 -0
  175. package/src/resolve/util.cjs +37 -0
  176. package/src/resolve/util.mjs +30 -0
  177. package/src/util/plugins.cjs +44 -0
  178. package/src/util/plugins.mjs +37 -0
  179. package/src/util/url.cjs +288 -0
  180. package/src/util/url.mjs +274 -0
  181. package/types/File.d.ts +24 -0
  182. package/types/Reference.d.ts +23 -0
  183. package/types/ReferenceSet.d.ts +25 -0
  184. package/types/apidom-reference.d.ts +584 -0
  185. package/types/bundle/index.d.ts +7 -0
  186. package/types/bundle/strategies/BundleStrategy.d.ts +19 -0
  187. package/types/bundle/strategies/openapi-3-1/index.d.ts +26 -0
  188. package/types/configuration/empty.d.ts +1 -0
  189. package/types/configuration/saturated.d.ts +1 -0
  190. package/types/dereference/index.d.ts +11 -0
  191. package/types/dereference/strategies/DereferenceStrategy.d.ts +19 -0
  192. package/types/dereference/strategies/apidom/index.d.ts +30 -0
  193. package/types/dereference/strategies/apidom/selectors/element-id.d.ts +11 -0
  194. package/types/dereference/strategies/apidom/visitor.d.ts +32 -0
  195. package/types/dereference/strategies/asyncapi-2/index.d.ts +31 -0
  196. package/types/dereference/strategies/asyncapi-2/visitor.d.ts +43 -0
  197. package/types/dereference/strategies/openapi-2/index.d.ts +32 -0
  198. package/types/dereference/strategies/openapi-2/visitor.d.ts +47 -0
  199. package/types/dereference/strategies/openapi-3-0/index.d.ts +31 -0
  200. package/types/dereference/strategies/openapi-3-0/visitor.d.ts +49 -0
  201. package/types/dereference/strategies/openapi-3-1/index.d.ts +32 -0
  202. package/types/dereference/strategies/openapi-3-1/selectors/$anchor.d.ts +22 -0
  203. package/types/dereference/strategies/openapi-3-1/selectors/uri.d.ts +12 -0
  204. package/types/dereference/strategies/openapi-3-1/util.d.ts +21 -0
  205. package/types/dereference/strategies/openapi-3-1/visitor.d.ts +52 -0
  206. package/types/dereference/util.d.ts +9 -0
  207. package/types/errors/BundleError.d.ts +7 -0
  208. package/types/errors/DereferenceError.d.ts +7 -0
  209. package/types/errors/EvaluationElementIdError.d.ts +7 -0
  210. package/types/errors/EvaluationJsonSchema$anchorError.d.ts +7 -0
  211. package/types/errors/EvaluationJsonSchemaUriError.d.ts +7 -0
  212. package/types/errors/InvalidJsonSchema$anchorError.d.ts +8 -0
  213. package/types/errors/JsonSchema$anchorError.d.ts +7 -0
  214. package/types/errors/JsonSchemaUriError.d.ts +7 -0
  215. package/types/errors/MaximumBundleDepthError.d.ts +7 -0
  216. package/types/errors/MaximumDereferenceDepthError.d.ts +7 -0
  217. package/types/errors/MaximumResolveDepthError.d.ts +7 -0
  218. package/types/errors/ParseError.d.ts +7 -0
  219. package/types/errors/ParserError.d.ts +7 -0
  220. package/types/errors/PluginError.d.ts +12 -0
  221. package/types/errors/ResolveError.d.ts +7 -0
  222. package/types/errors/ResolverError.d.ts +7 -0
  223. package/types/errors/UnmatchedBundleStrategyError.d.ts +7 -0
  224. package/types/errors/UnmatchedDereferenceStrategyError.d.ts +7 -0
  225. package/types/errors/UnmatchedResolveStrategyError.d.ts +7 -0
  226. package/types/errors/UnmatchedResolverError.d.ts +7 -0
  227. package/types/index.d.ts +75 -0
  228. package/types/options/index.d.ts +62 -0
  229. package/types/options/util.d.ts +5 -0
  230. package/types/parse/index.d.ts +7 -0
  231. package/types/parse/parsers/Parser.d.ts +38 -0
  232. package/types/parse/parsers/api-design-systems-json/index.d.ts +21 -0
  233. package/types/parse/parsers/api-design-systems-yaml/index.d.ts +20 -0
  234. package/types/parse/parsers/apidom-json/index.d.ts +24 -0
  235. package/types/parse/parsers/arazzo-json-1/index.d.ts +21 -0
  236. package/types/parse/parsers/arazzo-yaml-1/index.d.ts +20 -0
  237. package/types/parse/parsers/asyncapi-json-2/index.d.ts +21 -0
  238. package/types/parse/parsers/asyncapi-yaml-2/index.d.ts +20 -0
  239. package/types/parse/parsers/binary/index-browser.d.ts +21 -0
  240. package/types/parse/parsers/binary/index-node.d.ts +21 -0
  241. package/types/parse/parsers/json/index.d.ts +20 -0
  242. package/types/parse/parsers/openapi-json-2/index.d.ts +21 -0
  243. package/types/parse/parsers/openapi-json-3-0/index.d.ts +21 -0
  244. package/types/parse/parsers/openapi-json-3-1/index.d.ts +21 -0
  245. package/types/parse/parsers/openapi-yaml-2/index.d.ts +20 -0
  246. package/types/parse/parsers/openapi-yaml-3-0/index.d.ts +20 -0
  247. package/types/parse/parsers/openapi-yaml-3-1/index.d.ts +20 -0
  248. package/types/parse/parsers/yaml-1-2/index.d.ts +20 -0
  249. package/types/resolve/index.d.ts +12 -0
  250. package/types/resolve/resolvers/HTTPResolver.d.ts +22 -0
  251. package/types/resolve/resolvers/Resolver.d.ts +17 -0
  252. package/types/resolve/resolvers/file/index-browser.d.ts +12 -0
  253. package/types/resolve/resolvers/file/index-node.d.ts +20 -0
  254. package/types/resolve/resolvers/http-axios/index.d.ts +30 -0
  255. package/types/resolve/strategies/ResolveStrategy.d.ts +19 -0
  256. package/types/resolve/strategies/apidom/index.d.ts +27 -0
  257. package/types/resolve/strategies/asyncapi-2/index.d.ts +27 -0
  258. package/types/resolve/strategies/openapi-2/index.d.ts +27 -0
  259. package/types/resolve/strategies/openapi-3-0/index.d.ts +27 -0
  260. package/types/resolve/strategies/openapi-3-1/index.d.ts +27 -0
  261. package/types/resolve/util.d.ts +6 -0
  262. package/types/util/plugins.d.ts +14 -0
  263. package/types/util/url.d.ts +106 -0
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
7
+ var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
8
+ var _util = require("../../../options/util.cjs");
9
+ var _UnmatchedDereferenceStrategyError = _interopRequireDefault(require("../../../errors/UnmatchedDereferenceStrategyError.cjs"));
10
+ /**
11
+ * @public
12
+ */
13
+
14
+ /**
15
+ * @public
16
+ */
17
+ class OpenAPI3_0ResolveStrategy extends _ResolveStrategy.default {
18
+ constructor(options) {
19
+ super({
20
+ ...(options ?? {}),
21
+ name: 'openapi-3-0'
22
+ });
23
+ }
24
+ canResolve(file, options) {
25
+ const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'openapi-3-0');
26
+ if (dereferenceStrategy === undefined) {
27
+ return false;
28
+ }
29
+ return dereferenceStrategy.canDereference(file, options);
30
+ }
31
+ async resolve(file, options) {
32
+ const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'openapi-3-0');
33
+ if (dereferenceStrategy === undefined) {
34
+ throw new _UnmatchedDereferenceStrategyError.default('"openapi-3-0" dereference strategy is not available.');
35
+ }
36
+ const refSet = new _ReferenceSet.default();
37
+ const mergedOptions = (0, _util.merge)(options, {
38
+ resolve: {
39
+ internal: false
40
+ },
41
+ dereference: {
42
+ refSet
43
+ }
44
+ });
45
+ await dereferenceStrategy.dereference(file, mergedOptions);
46
+ return refSet;
47
+ }
48
+ }
49
+ var _default = exports.default = OpenAPI3_0ResolveStrategy;
@@ -0,0 +1,43 @@
1
+ import ResolveStrategy from "../ResolveStrategy.mjs";
2
+ import ReferenceSet from "../../../ReferenceSet.mjs";
3
+ import { merge as mergeOptions } from "../../../options/util.mjs";
4
+ import UnmatchedDereferenceStrategyError from "../../../errors/UnmatchedDereferenceStrategyError.mjs";
5
+ /**
6
+ * @public
7
+ */
8
+ /**
9
+ * @public
10
+ */
11
+ class OpenAPI3_0ResolveStrategy extends ResolveStrategy {
12
+ constructor(options) {
13
+ super({
14
+ ...(options ?? {}),
15
+ name: 'openapi-3-0'
16
+ });
17
+ }
18
+ canResolve(file, options) {
19
+ const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'openapi-3-0');
20
+ if (dereferenceStrategy === undefined) {
21
+ return false;
22
+ }
23
+ return dereferenceStrategy.canDereference(file, options);
24
+ }
25
+ async resolve(file, options) {
26
+ const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'openapi-3-0');
27
+ if (dereferenceStrategy === undefined) {
28
+ throw new UnmatchedDereferenceStrategyError('"openapi-3-0" dereference strategy is not available.');
29
+ }
30
+ const refSet = new ReferenceSet();
31
+ const mergedOptions = mergeOptions(options, {
32
+ resolve: {
33
+ internal: false
34
+ },
35
+ dereference: {
36
+ refSet
37
+ }
38
+ });
39
+ await dereferenceStrategy.dereference(file, mergedOptions);
40
+ return refSet;
41
+ }
42
+ }
43
+ export default OpenAPI3_0ResolveStrategy;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.default = void 0;
6
+ var _ResolveStrategy = _interopRequireDefault(require("../ResolveStrategy.cjs"));
7
+ var _ReferenceSet = _interopRequireDefault(require("../../../ReferenceSet.cjs"));
8
+ var _util = require("../../../options/util.cjs");
9
+ var _UnmatchedDereferenceStrategyError = _interopRequireDefault(require("../../../errors/UnmatchedDereferenceStrategyError.cjs"));
10
+ /**
11
+ * @public
12
+ */
13
+
14
+ /**
15
+ * @public
16
+ */
17
+ class OpenAPI3_1ResolveStrategy extends _ResolveStrategy.default {
18
+ constructor(options) {
19
+ super({
20
+ ...(options ?? {}),
21
+ name: 'openapi-3-1'
22
+ });
23
+ }
24
+ canResolve(file, options) {
25
+ const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'openapi-3-1');
26
+ if (dereferenceStrategy === undefined) {
27
+ return false;
28
+ }
29
+ return dereferenceStrategy.canDereference(file, options);
30
+ }
31
+ async resolve(file, options) {
32
+ const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'openapi-3-1');
33
+ if (dereferenceStrategy === undefined) {
34
+ throw new _UnmatchedDereferenceStrategyError.default('"openapi-3-1" dereference strategy is not available.');
35
+ }
36
+ const refSet = new _ReferenceSet.default();
37
+ const mergedOptions = (0, _util.merge)(options, {
38
+ resolve: {
39
+ internal: false
40
+ },
41
+ dereference: {
42
+ refSet
43
+ }
44
+ });
45
+ await dereferenceStrategy.dereference(file, mergedOptions);
46
+ return refSet;
47
+ }
48
+ }
49
+ var _default = exports.default = OpenAPI3_1ResolveStrategy;
@@ -0,0 +1,43 @@
1
+ import ResolveStrategy from "../ResolveStrategy.mjs";
2
+ import ReferenceSet from "../../../ReferenceSet.mjs";
3
+ import { merge as mergeOptions } from "../../../options/util.mjs";
4
+ import UnmatchedDereferenceStrategyError from "../../../errors/UnmatchedDereferenceStrategyError.mjs";
5
+ /**
6
+ * @public
7
+ */
8
+ /**
9
+ * @public
10
+ */
11
+ class OpenAPI3_1ResolveStrategy extends ResolveStrategy {
12
+ constructor(options) {
13
+ super({
14
+ ...(options ?? {}),
15
+ name: 'openapi-3-1'
16
+ });
17
+ }
18
+ canResolve(file, options) {
19
+ const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'openapi-3-1');
20
+ if (dereferenceStrategy === undefined) {
21
+ return false;
22
+ }
23
+ return dereferenceStrategy.canDereference(file, options);
24
+ }
25
+ async resolve(file, options) {
26
+ const dereferenceStrategy = options.dereference.strategies.find(strategy => strategy.name === 'openapi-3-1');
27
+ if (dereferenceStrategy === undefined) {
28
+ throw new UnmatchedDereferenceStrategyError('"openapi-3-1" dereference strategy is not available.');
29
+ }
30
+ const refSet = new ReferenceSet();
31
+ const mergedOptions = mergeOptions(options, {
32
+ resolve: {
33
+ internal: false
34
+ },
35
+ dereference: {
36
+ refSet
37
+ }
38
+ });
39
+ await dereferenceStrategy.dereference(file, mergedOptions);
40
+ return refSet;
41
+ }
42
+ }
43
+ export default OpenAPI3_1ResolveStrategy;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
5
+ exports.__esModule = true;
6
+ exports.readFile = void 0;
7
+ var _ramda = require("ramda");
8
+ var plugins = _interopRequireWildcard(require("../util/plugins.cjs"));
9
+ var _ResolveError = _interopRequireDefault(require("../errors/ResolveError.cjs"));
10
+ var _UnmatchedResolverError = _interopRequireDefault(require("../errors/UnmatchedResolverError.cjs"));
11
+ /**
12
+ * Reads the given file, using the configured resolver plugins.
13
+ */
14
+
15
+ const readFile = async (file, options) => {
16
+ const optsBoundResolvers = options.resolve.resolvers.map(resolver => {
17
+ const clonedResolver = Object.create(resolver);
18
+ return Object.assign(clonedResolver, options.resolve.resolverOpts);
19
+ });
20
+ const resolvers = await plugins.filter('canRead', [file, options], optsBoundResolvers);
21
+
22
+ // we couldn't find any resolver for this File
23
+ if ((0, _ramda.isEmpty)(resolvers)) {
24
+ throw new _UnmatchedResolverError.default(file.uri);
25
+ }
26
+ try {
27
+ const {
28
+ result
29
+ } = await plugins.run('read', [file], resolvers);
30
+ return result;
31
+ } catch (error) {
32
+ throw new _ResolveError.default(`Error while reading file "${file.uri}"`, {
33
+ cause: error
34
+ });
35
+ }
36
+ };
37
+ exports.readFile = readFile;
@@ -0,0 +1,30 @@
1
+ import { isEmpty } from 'ramda';
2
+ import * as plugins from "../util/plugins.mjs";
3
+ import ResolveError from "../errors/ResolveError.mjs";
4
+ import UnmatchedResolverError from "../errors/UnmatchedResolverError.mjs";
5
+ /**
6
+ * Reads the given file, using the configured resolver plugins.
7
+ */
8
+
9
+ export const readFile = async (file, options) => {
10
+ const optsBoundResolvers = options.resolve.resolvers.map(resolver => {
11
+ const clonedResolver = Object.create(resolver);
12
+ return Object.assign(clonedResolver, options.resolve.resolverOpts);
13
+ });
14
+ const resolvers = await plugins.filter('canRead', [file, options], optsBoundResolvers);
15
+
16
+ // we couldn't find any resolver for this File
17
+ if (isEmpty(resolvers)) {
18
+ throw new UnmatchedResolverError(file.uri);
19
+ }
20
+ try {
21
+ const {
22
+ result
23
+ } = await plugins.run('read', [file], resolvers);
24
+ return result;
25
+ } catch (error) {
26
+ throw new ResolveError(`Error while reading file "${file.uri}"`, {
27
+ cause: error
28
+ });
29
+ }
30
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.run = exports.filter = void 0;
6
+ var _ramdaAdjunct = require("ramda-adjunct");
7
+ var _PluginError = _interopRequireDefault(require("../errors/PluginError.cjs"));
8
+ /**
9
+ * Filters the given plugins, returning only the ones return `true` for the given method.
10
+ */
11
+ const filter = async (method, parameters, plugins) => {
12
+ const pluginResults = await Promise.all(plugins.map((0, _ramdaAdjunct.invokeArgs)([method], parameters)));
13
+ return plugins.filter((plugin, index) => pluginResults[index]);
14
+ };
15
+
16
+ /**
17
+ * Runs the specified method of the given plugins, in order,
18
+ * until one of them returns a successful result.
19
+ * Each method can return a synchronous value or a Promise.
20
+ * If the promise resolves successfully then the result
21
+ * is immediately returned and no further plugins are called.
22
+ * If the promise rejects then the next plugin is called.
23
+ * If ALL plugins fail, then the last error is thrown.
24
+ */
25
+ exports.filter = filter;
26
+ const run = async (method, parameters, plugins) => {
27
+ let lastError;
28
+ for (const plugin of plugins) {
29
+ try {
30
+ const result = await plugin[method].call(plugin, ...parameters);
31
+ return {
32
+ plugin,
33
+ result
34
+ };
35
+ } catch (error) {
36
+ lastError = new _PluginError.default('Error while running plugin', {
37
+ cause: error,
38
+ plugin
39
+ });
40
+ }
41
+ }
42
+ return Promise.reject(lastError);
43
+ };
44
+ exports.run = run;
@@ -0,0 +1,37 @@
1
+ import { invokeArgs } from 'ramda-adjunct';
2
+ import PluginError from "../errors/PluginError.mjs";
3
+ /**
4
+ * Filters the given plugins, returning only the ones return `true` for the given method.
5
+ */
6
+ export const filter = async (method, parameters, plugins) => {
7
+ const pluginResults = await Promise.all(plugins.map(invokeArgs([method], parameters)));
8
+ return plugins.filter((plugin, index) => pluginResults[index]);
9
+ };
10
+
11
+ /**
12
+ * Runs the specified method of the given plugins, in order,
13
+ * until one of them returns a successful result.
14
+ * Each method can return a synchronous value or a Promise.
15
+ * If the promise resolves successfully then the result
16
+ * is immediately returned and no further plugins are called.
17
+ * If the promise rejects then the next plugin is called.
18
+ * If ALL plugins fail, then the last error is thrown.
19
+ */
20
+ export const run = async (method, parameters, plugins) => {
21
+ let lastError;
22
+ for (const plugin of plugins) {
23
+ try {
24
+ const result = await plugin[method].call(plugin, ...parameters);
25
+ return {
26
+ plugin,
27
+ result
28
+ };
29
+ } catch (error) {
30
+ lastError = new PluginError('Error while running plugin', {
31
+ cause: error,
32
+ plugin
33
+ });
34
+ }
35
+ }
36
+ return Promise.reject(lastError);
37
+ };
@@ -0,0 +1,288 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4
+ exports.__esModule = true;
5
+ exports.unsanitize = exports.toFileSystemPath = exports.stripHash = exports.sanitize = exports.resolve = exports.isURI = exports.isHttpUrl = exports.isFileSystemPath = exports.hasProtocol = exports.getProtocol = exports.getHash = exports.getExtension = exports.fromFileSystemPath = exports.cwd = void 0;
6
+ var _process = _interopRequireDefault(require("process"));
7
+ var _ramda = require("ramda");
8
+ var _ramdaAdjunct = require("ramda-adjunct");
9
+ /**
10
+ * SPDX-FileCopyrightText: Copyright (c) 2015 James Messinger
11
+ *
12
+ * SPDX-License-Identifier: MIT
13
+ */
14
+
15
+ /**
16
+ * @public
17
+ */
18
+
19
+ const isWindows = () => (0, _ramda.pathSatisfies)((0, _ramda.test)(/^win/), ['platform'], _process.default);
20
+
21
+ /**
22
+ * Returns the protocol of the given URL, or `undefined` if it has no protocol.
23
+ * @public
24
+ */
25
+ const getProtocol = url => {
26
+ try {
27
+ const parsedUrl = new URL(url);
28
+ return (0, _ramdaAdjunct.trimCharsEnd)(':', parsedUrl.protocol);
29
+ } catch {
30
+ return undefined;
31
+ }
32
+ };
33
+
34
+ /**
35
+ * Returns true if given URL has protocol.
36
+ * @public
37
+ */
38
+ exports.getProtocol = getProtocol;
39
+ const hasProtocol = exports.hasProtocol = (0, _ramda.pipe)(getProtocol, _ramdaAdjunct.isNotUndefined);
40
+
41
+ /**
42
+ * Returns the lower-cased file extension of the given URL,
43
+ * or an empty string if it has no extension.
44
+ * @public
45
+ */
46
+ const getExtension = url => {
47
+ const lastDotPosition = url.lastIndexOf('.');
48
+ if (lastDotPosition >= 0) {
49
+ return url.substring(lastDotPosition).toLowerCase();
50
+ }
51
+ return '';
52
+ };
53
+
54
+ /**
55
+ * Determines whether the given path is a filesystem path.
56
+ * This includes "file://" URLs.
57
+ * @public
58
+ */
59
+ exports.getExtension = getExtension;
60
+ const isFileSystemPath = uri => {
61
+ const protocol = getProtocol(uri);
62
+ return (0, _ramdaAdjunct.isUndefined)(protocol) || protocol === 'file' || /^[a-zA-Z]$/.test(protocol);
63
+ };
64
+
65
+ /**
66
+ * Determines whether the given URI is an HTTP(S) URL.
67
+ * @public
68
+ */
69
+ exports.isFileSystemPath = isFileSystemPath;
70
+ const isHttpUrl = url => {
71
+ const protocol = getProtocol(url);
72
+ return protocol === 'http' || protocol === 'https';
73
+ };
74
+
75
+ /**
76
+ * Determines whether the given URI
77
+ * @public
78
+ */
79
+ exports.isHttpUrl = isHttpUrl;
80
+ const isURI = uri => {
81
+ try {
82
+ new URL(uri);
83
+ return true;
84
+ } catch {
85
+ return false;
86
+ }
87
+ };
88
+
89
+ /**
90
+ * @public
91
+ */
92
+ exports.isURI = isURI;
93
+ /**
94
+ * Converts a URL to a local filesystem path.
95
+ * @public
96
+ */
97
+ const toFileSystemPath = (uri, options) => {
98
+ // RegExp patterns to URL-decode special characters for local filesystem paths
99
+ const urlDecodePatterns = [/%23/g, '#', /%24/g, '$', /%26/g, '&', /%2C/g, ',', /%40/g, '@'];
100
+ const keepFileProtocol = (0, _ramda.propOr)(false, 'keepFileProtocol', options);
101
+ const isWindowsPredicate = (0, _ramda.propOr)(isWindows, 'isWindows', options);
102
+
103
+ // Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
104
+ let path = decodeURI(uri);
105
+
106
+ // Step 2: Manually decode characters that are not decoded by `decodeURI`.
107
+ // This includes characters such as "#" and "?", which have special meaning in URLs,
108
+ // but are just normal characters in a filesystem path.
109
+ for (let i = 0; i < urlDecodePatterns.length; i += 2) {
110
+ // @ts-ignore
111
+ path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
112
+ }
113
+
114
+ // Step 3: If it's a "file://" URL, then format it consistently
115
+ // or convert it to a local filesystem path
116
+ let isFileUrl = path.substring(0, 7).toLowerCase() === 'file://';
117
+ if (isFileUrl) {
118
+ // Strip-off the protocol, and the initial "/", if there is one
119
+ path = path[7] === '/' ? path.substring(8) : path.substring(7);
120
+
121
+ // insert a colon (":") after the drive letter on Windows
122
+ if (isWindowsPredicate() && path[1] === '/') {
123
+ path = `${path[0]}:${path.substring(1)}`;
124
+ }
125
+ if (keepFileProtocol) {
126
+ // Return the consistently-formatted "file://" URL
127
+ path = `file:///${path}`;
128
+ } else {
129
+ // Convert the "file://" URL to a local filesystem path.
130
+ // On Windows, it will start with something like "C:/".
131
+ // On Posix, it will start with "/"
132
+ isFileUrl = false;
133
+ path = isWindowsPredicate() ? path : `/${path}`;
134
+ }
135
+ }
136
+
137
+ // Step 4: Normalize Windows paths (unless it's a "file://" URL)
138
+ if (isWindowsPredicate() && !isFileUrl) {
139
+ // Replace forward slashes with backslashes
140
+ path = (0, _ramdaAdjunct.replaceAll)('/', '\\', path);
141
+
142
+ // Capitalize the drive letter
143
+ if (path.substring(1, 3) === ':\\') {
144
+ path = path[0].toUpperCase() + path.substring(1);
145
+ }
146
+ }
147
+ return path;
148
+ };
149
+
150
+ /**
151
+ * Converts a filesystem path to a properly-encoded URL.
152
+ *
153
+ * This is intended to handle situations where resolver is called
154
+ * with a filesystem path that contains characters which are not allowed in URLs.
155
+ *
156
+ * @example
157
+ * The following filesystem paths would be converted to the following URLs:
158
+ *```
159
+ * <"!@#$%^&*+=?'>.json ==> %3C%22!@%23$%25%5E&*+=%3F\'%3E.json
160
+ * C:\\My Documents\\File (1).json ==> C:/My%20Documents/File%20(1).json
161
+ * file://Project #42/file.json ==> file://Project%20%2342/file.json
162
+ * ```
163
+ * @public
164
+ */
165
+ exports.toFileSystemPath = toFileSystemPath;
166
+ const fromFileSystemPath = uri => {
167
+ const urlEncodePatterns = [/\?/g, '%3F', /#/g, '%23'];
168
+ let path = uri;
169
+
170
+ // Step 1: On Windows, replace backslashes with forward slashes,
171
+ // rather than encoding them as "%5C"
172
+ if (isWindows()) {
173
+ path = path.replace(/\\/g, '/');
174
+ }
175
+
176
+ // Step 2: `encodeURI` will take care of MOST characters
177
+ path = encodeURI(path);
178
+
179
+ // Step 3: Manually encode characters that are not encoded by `encodeURI`.
180
+ // This includes characters such as "#" and "?", which have special meaning in URLs,
181
+ // but are just normal characters in a filesystem path.
182
+ for (let i = 0; i < urlEncodePatterns.length; i += 2) {
183
+ // @ts-ignore
184
+ path = path.replace(urlEncodePatterns[i], urlEncodePatterns[i + 1]);
185
+ }
186
+ return path;
187
+ };
188
+
189
+ /**
190
+ * Returns the hash (URL fragment), of the given path.
191
+ * If there is no hash, then the root hash ("#") is returned.
192
+ * @public
193
+ */
194
+ exports.fromFileSystemPath = fromFileSystemPath;
195
+ const getHash = uri => {
196
+ const hashIndex = uri.indexOf('#');
197
+ if (hashIndex !== -1) {
198
+ return uri.substring(hashIndex);
199
+ }
200
+ return '#';
201
+ };
202
+
203
+ /**
204
+ * Removes the hash (URL fragment), if any, from the given path.
205
+ * @public
206
+ */
207
+ exports.getHash = getHash;
208
+ const stripHash = uri => {
209
+ const hashIndex = uri.indexOf('#');
210
+ let hashStrippedUri = uri;
211
+ if (hashIndex >= 0) {
212
+ hashStrippedUri = uri.substring(0, hashIndex);
213
+ }
214
+ return hashStrippedUri;
215
+ };
216
+
217
+ /**
218
+ * Returns the current working directory (in Node) or the current page URL (in browsers).
219
+ * @public
220
+ */
221
+ exports.stripHash = stripHash;
222
+ const cwd = () => {
223
+ // @ts-ignore
224
+ if (_process.default.browser) {
225
+ return stripHash(globalThis.location.href);
226
+ }
227
+ const path = _process.default.cwd();
228
+ const lastChar = (0, _ramda.last)(path);
229
+ if (['/', '\\'].includes(lastChar)) {
230
+ return path;
231
+ }
232
+ return path + (isWindows() ? '\\' : '/');
233
+ };
234
+
235
+ /**
236
+ * Resolves a target URI relative to a base URI in a manner similar to that of a Web browser resolving an anchor tag HREF.
237
+ * @public
238
+ */
239
+ exports.cwd = cwd;
240
+ const resolve = (from, to) => {
241
+ const resolvedUrl = new URL(to, new URL(from, 'resolve://'));
242
+ if (resolvedUrl.protocol === 'resolve:') {
243
+ // `from` is a relative URL.
244
+ const {
245
+ pathname,
246
+ search,
247
+ hash
248
+ } = resolvedUrl;
249
+ return pathname + search + hash;
250
+ }
251
+ return resolvedUrl.toString();
252
+ };
253
+
254
+ /**
255
+ * Sanitizes/Encodes URI to it's url encoded form.
256
+ *
257
+ * The functional will compensate with the usecase when
258
+ * already sanitized URI is passed to it,
259
+ * by first unsatizing it and then performing sanitization again.
260
+ * @public
261
+ */
262
+ exports.resolve = resolve;
263
+ const sanitize = uri => {
264
+ if (isFileSystemPath(uri)) {
265
+ return fromFileSystemPath(toFileSystemPath(uri));
266
+ }
267
+ try {
268
+ return new URL(uri).toString();
269
+ } catch {
270
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI#encoding_for_ipv6
271
+ return encodeURI(decodeURI(uri)).replace(/%5B/g, '[').replace(/%5D/g, ']');
272
+ }
273
+ };
274
+
275
+ /**
276
+ * Unsanitizes/Decodes URI to it's url encoded form.
277
+ * This function already assumes that hash part of the URI
278
+ * has been removed prior to transforming it to it's sanitized form.
279
+ * @public
280
+ */
281
+ exports.sanitize = sanitize;
282
+ const unsanitize = uri => {
283
+ if (isFileSystemPath(uri)) {
284
+ return toFileSystemPath(uri);
285
+ }
286
+ return decodeURI(uri);
287
+ };
288
+ exports.unsanitize = unsanitize;