@jentic/arazzo-parser 1.0.0-alpha.23 → 1.0.0-alpha.25
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.
- package/CHANGELOG.md +10 -0
- package/dist/jentic-arazzo-parser.browser.js +24 -20
- package/package.json +16 -17
- package/src/errors/ParseError.cjs +11 -0
- package/src/errors/ParseError.mjs +7 -0
- package/src/index.cjs +10 -0
- package/src/index.mjs +2 -0
- package/src/parse-arazzo.cjs +204 -0
- package/src/parse-arazzo.mjs +197 -0
- package/src/parse-openapi.cjs +234 -0
- package/src/parse-openapi.mjs +227 -0
- package/src/resolve/resolvers/memory/index.cjs +29 -0
- package/src/resolve/resolvers/memory/index.mjs +25 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
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
|
+
# [1.0.0-alpha.25](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.24...v1.0.0-alpha.25) (2026-03-11)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **release:** fix issue in lerna not publishing _.cjs|_.mjs files ([8982184](https://github.com/jentic/jentic-arazzo-tools/commit/8982184ddae167b6f2a772114f9a9321f3b67d14))
|
|
11
|
+
|
|
12
|
+
# [1.0.0-alpha.24](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.23...v1.0.0-alpha.24) (2026-03-11)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @jentic/arazzo-parser
|
|
15
|
+
|
|
6
16
|
# [1.0.0-alpha.23](https://github.com/jentic/jentic-arazzo-tools/compare/v1.0.0-alpha.22...v1.0.0-alpha.23) (2026-03-11)
|
|
7
17
|
|
|
8
18
|
### Features
|
|
@@ -38197,7 +38197,9 @@ class Path {
|
|
|
38197
38197
|
*
|
|
38198
38198
|
* @example
|
|
38199
38199
|
* // For a path to $.paths['/pets'].get in an OpenAPI document:
|
|
38200
|
+
* ```
|
|
38200
38201
|
* path.getPathKeys(); // => ['paths', '/pets', 'get']
|
|
38202
|
+
* ```
|
|
38201
38203
|
*/
|
|
38202
38204
|
getPathKeys() {
|
|
38203
38205
|
const keys = [];
|
|
@@ -38232,18 +38234,22 @@ class Path {
|
|
|
38232
38234
|
* or Normalized JSONPath like "$['paths']['/pets']['get']['responses']['200']"
|
|
38233
38235
|
*
|
|
38234
38236
|
* @example
|
|
38237
|
+
* ```
|
|
38235
38238
|
* // JSON Pointer examples:
|
|
38236
38239
|
* path.formatPath(); // "" (root)
|
|
38237
38240
|
* path.formatPath(); // "/info"
|
|
38238
38241
|
* path.formatPath(); // "/paths/~1pets/get"
|
|
38239
38242
|
* path.formatPath(); // "/paths/~1users~1{id}/parameters/0"
|
|
38243
|
+
* ```
|
|
38240
38244
|
*
|
|
38241
38245
|
* @example
|
|
38246
|
+
* ```
|
|
38242
38247
|
* // JSONPath examples:
|
|
38243
38248
|
* path.formatPath('jsonpath'); // "$" (root)
|
|
38244
38249
|
* path.formatPath('jsonpath'); // "$['info']"
|
|
38245
38250
|
* path.formatPath('jsonpath'); // "$['paths']['/pets']['get']"
|
|
38246
38251
|
* path.formatPath('jsonpath'); // "$['paths']['/users/{id}']['parameters'][0]"
|
|
38252
|
+
* ```
|
|
38247
38253
|
*/
|
|
38248
38254
|
formatPath(pathFormat = 'jsonpointer') {
|
|
38249
38255
|
const parts = this.getPathKeys();
|
|
@@ -38453,15 +38459,15 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
38453
38459
|
/* harmony import */ var _traversal_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66061);
|
|
38454
38460
|
|
|
38455
38461
|
/**
|
|
38456
|
-
* Finds all elements
|
|
38462
|
+
* Finds all paths whose elements match the predicate.
|
|
38457
38463
|
* @public
|
|
38458
38464
|
*/
|
|
38459
38465
|
const filter = (element, predicate) => {
|
|
38460
38466
|
const result = [];
|
|
38461
38467
|
(0,_traversal_mjs__WEBPACK_IMPORTED_MODULE_0__.traverse)(element, {
|
|
38462
38468
|
enter(path) {
|
|
38463
|
-
if (predicate(path
|
|
38464
|
-
result.push(path
|
|
38469
|
+
if (predicate(path)) {
|
|
38470
|
+
result.push(path);
|
|
38465
38471
|
}
|
|
38466
38472
|
}
|
|
38467
38473
|
});
|
|
@@ -38487,7 +38493,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
38487
38493
|
* @public
|
|
38488
38494
|
*/
|
|
38489
38495
|
/**
|
|
38490
|
-
* Finds the most inner node at the given offset.
|
|
38496
|
+
* Finds the path of the most inner node at the given offset.
|
|
38491
38497
|
* If includeRightBound is set, also finds nodes that end at the given offset.
|
|
38492
38498
|
* @public
|
|
38493
38499
|
*/
|
|
@@ -38512,7 +38518,7 @@ const findAtOffset = (element, options) => {
|
|
|
38512
38518
|
const endOffset = node.endOffset;
|
|
38513
38519
|
const isWithinOffsetRange = offset >= startOffset && (offset < endOffset || includeRightBound && offset <= endOffset);
|
|
38514
38520
|
if (isWithinOffsetRange) {
|
|
38515
|
-
result.push(
|
|
38521
|
+
result.push(path);
|
|
38516
38522
|
return; // push to stack and dive in
|
|
38517
38523
|
}
|
|
38518
38524
|
path.skip(); // skip entire sub-tree
|
|
@@ -38535,15 +38541,15 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
38535
38541
|
/* harmony import */ var _traversal_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66061);
|
|
38536
38542
|
|
|
38537
38543
|
/**
|
|
38538
|
-
*
|
|
38544
|
+
* Finds first path whose element satisfies the provided predicate.
|
|
38539
38545
|
* @public
|
|
38540
38546
|
*/
|
|
38541
38547
|
const find = (element, predicate) => {
|
|
38542
38548
|
let result;
|
|
38543
38549
|
(0,_traversal_mjs__WEBPACK_IMPORTED_MODULE_0__.traverse)(element, {
|
|
38544
38550
|
enter(path) {
|
|
38545
|
-
if (predicate(path
|
|
38546
|
-
result = path
|
|
38551
|
+
if (predicate(path)) {
|
|
38552
|
+
result = path;
|
|
38547
38553
|
path.stop();
|
|
38548
38554
|
}
|
|
38549
38555
|
}
|
|
@@ -38562,9 +38568,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
38562
38568
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
38563
38569
|
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
|
|
38564
38570
|
/* harmony export */ });
|
|
38565
|
-
/* harmony import */ var
|
|
38566
|
-
/* harmony import */ var _traversal_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(66061);
|
|
38567
|
-
|
|
38571
|
+
/* harmony import */ var _traversal_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66061);
|
|
38568
38572
|
|
|
38569
38573
|
/**
|
|
38570
38574
|
* @public
|
|
@@ -38573,7 +38577,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
38573
38577
|
* @public
|
|
38574
38578
|
*/
|
|
38575
38579
|
/**
|
|
38576
|
-
* Executes the callback on this element and all
|
|
38580
|
+
* Executes the callback on this element's path and all descendant paths.
|
|
38577
38581
|
* @public
|
|
38578
38582
|
*/
|
|
38579
38583
|
const forEach = (element, options) => {
|
|
@@ -38581,15 +38585,15 @@ const forEach = (element, options) => {
|
|
|
38581
38585
|
let predicate;
|
|
38582
38586
|
if (typeof options === 'function') {
|
|
38583
38587
|
callback = options;
|
|
38584
|
-
predicate =
|
|
38588
|
+
predicate = () => true;
|
|
38585
38589
|
} else {
|
|
38586
38590
|
callback = options.callback ?? (() => {});
|
|
38587
|
-
predicate = options.predicate ??
|
|
38591
|
+
predicate = options.predicate ?? (() => true);
|
|
38588
38592
|
}
|
|
38589
|
-
(0,
|
|
38593
|
+
(0,_traversal_mjs__WEBPACK_IMPORTED_MODULE_0__.traverse)(element, {
|
|
38590
38594
|
enter(path) {
|
|
38591
|
-
if (predicate(path
|
|
38592
|
-
callback(path
|
|
38595
|
+
if (predicate(path)) {
|
|
38596
|
+
callback(path);
|
|
38593
38597
|
}
|
|
38594
38598
|
}
|
|
38595
38599
|
});
|
|
@@ -38638,11 +38642,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
38638
38642
|
/* harmony import */ var _filter_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5800);
|
|
38639
38643
|
|
|
38640
38644
|
/**
|
|
38641
|
-
* Complement of filter. Finds all elements NOT
|
|
38645
|
+
* Complement of filter. Finds all paths whose elements do NOT match the predicate.
|
|
38642
38646
|
* @public
|
|
38643
38647
|
*/
|
|
38644
38648
|
const reject = (element, predicate) => {
|
|
38645
|
-
return (0,_filter_mjs__WEBPACK_IMPORTED_MODULE_0__["default"])(element,
|
|
38649
|
+
return (0,_filter_mjs__WEBPACK_IMPORTED_MODULE_0__["default"])(element, path => !predicate(path));
|
|
38646
38650
|
};
|
|
38647
38651
|
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (reject);
|
|
38648
38652
|
|
|
@@ -38659,7 +38663,7 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
38659
38663
|
/* harmony import */ var _find_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(66919);
|
|
38660
38664
|
|
|
38661
38665
|
/**
|
|
38662
|
-
* Tests whether at least one element passes the predicate.
|
|
38666
|
+
* Tests whether at least one path's element passes the predicate.
|
|
38663
38667
|
* @public
|
|
38664
38668
|
*/
|
|
38665
38669
|
const some = (element, predicate) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jentic/arazzo-parser",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.25",
|
|
4
4
|
"description": "Parser for Arazzo Documents producing SpecLynx ApiDOM data model.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arazzo",
|
|
@@ -48,27 +48,26 @@
|
|
|
48
48
|
"license": "Apache-2.0",
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
51
|
-
"@speclynx/apidom-datamodel": "^
|
|
52
|
-
"@speclynx/apidom-error": "^
|
|
53
|
-
"@speclynx/apidom-ns-arazzo-1": "^
|
|
54
|
-
"@speclynx/apidom-parser-adapter-arazzo-json-1": "^
|
|
55
|
-
"@speclynx/apidom-parser-adapter-arazzo-yaml-1": "^
|
|
56
|
-
"@speclynx/apidom-parser-adapter-openapi-json-2": "^
|
|
57
|
-
"@speclynx/apidom-parser-adapter-openapi-json-3-0": "^
|
|
58
|
-
"@speclynx/apidom-parser-adapter-openapi-json-3-1": "^
|
|
59
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-2": "^
|
|
60
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "^
|
|
61
|
-
"@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "^
|
|
62
|
-
"@speclynx/apidom-reference": "^
|
|
51
|
+
"@speclynx/apidom-datamodel": "^4.0.3",
|
|
52
|
+
"@speclynx/apidom-error": "^4.0.3",
|
|
53
|
+
"@speclynx/apidom-ns-arazzo-1": "^4.0.3",
|
|
54
|
+
"@speclynx/apidom-parser-adapter-arazzo-json-1": "^4.0.3",
|
|
55
|
+
"@speclynx/apidom-parser-adapter-arazzo-yaml-1": "^4.0.3",
|
|
56
|
+
"@speclynx/apidom-parser-adapter-openapi-json-2": "^4.0.3",
|
|
57
|
+
"@speclynx/apidom-parser-adapter-openapi-json-3-0": "^4.0.3",
|
|
58
|
+
"@speclynx/apidom-parser-adapter-openapi-json-3-1": "^4.0.3",
|
|
59
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-2": "^4.0.3",
|
|
60
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "^4.0.3",
|
|
61
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "^4.0.3",
|
|
62
|
+
"@speclynx/apidom-reference": "^4.0.3",
|
|
63
63
|
"ramda-adjunct": "^6.0.0",
|
|
64
64
|
"type-fest": "^5.4.3"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@speclynx/apidom-core": "^
|
|
67
|
+
"@speclynx/apidom-core": "^4.0.3"
|
|
68
68
|
},
|
|
69
69
|
"files": [
|
|
70
|
-
"src
|
|
71
|
-
"src/**/*.cjs",
|
|
70
|
+
"src/",
|
|
72
71
|
"dist/",
|
|
73
72
|
"types/arazzo-parser.d.ts",
|
|
74
73
|
"LICENSE",
|
|
@@ -76,5 +75,5 @@
|
|
|
76
75
|
"README.md",
|
|
77
76
|
"CHANGELOG.md"
|
|
78
77
|
],
|
|
79
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "b9a3213b0561fc58e0491c7e638d6a96383befff"
|
|
80
79
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _apidomError = require("@speclynx/apidom-error");
|
|
6
|
+
class ParseError extends _apidomError.ApiDOMError {
|
|
7
|
+
constructor(message, options) {
|
|
8
|
+
super(message, options);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
var _default = exports.default = ParseError;
|
package/src/index.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.parseOpenAPI = exports.parseArazzo = exports.defaultOpenAPIOptions = exports.defaultArazzoOptions = void 0;
|
|
5
|
+
var _parseArazzo = require("./parse-arazzo.cjs");
|
|
6
|
+
exports.parseArazzo = _parseArazzo.parse;
|
|
7
|
+
exports.defaultArazzoOptions = _parseArazzo.defaultOptions;
|
|
8
|
+
var _parseOpenapi = require("./parse-openapi.cjs");
|
|
9
|
+
exports.parseOpenAPI = _parseOpenapi.parse;
|
|
10
|
+
exports.defaultOpenAPIOptions = _parseOpenapi.defaultOptions;
|
package/src/index.mjs
ADDED
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.defaultOptions = void 0;
|
|
6
|
+
exports.parse = parse;
|
|
7
|
+
var _empty = require("@speclynx/apidom-reference/configuration/empty");
|
|
8
|
+
var _arazzoJson = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/arazzo-json-1"));
|
|
9
|
+
var _arazzoYaml = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/arazzo-yaml-1"));
|
|
10
|
+
var _openapiJson = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-json-2"));
|
|
11
|
+
var _openapiYaml = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-yaml-2"));
|
|
12
|
+
var _openapiJson2 = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-json-3-0"));
|
|
13
|
+
var _openapiYaml2 = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-yaml-3-0"));
|
|
14
|
+
var _openapiJson3 = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-json-3-1"));
|
|
15
|
+
var _openapiYaml3 = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-yaml-3-1"));
|
|
16
|
+
var _file = _interopRequireDefault(require("@speclynx/apidom-reference/resolve/resolvers/file"));
|
|
17
|
+
var _httpAxios = _interopRequireDefault(require("@speclynx/apidom-reference/resolve/resolvers/http-axios"));
|
|
18
|
+
var _apidomParserAdapterArazzoJson = require("@speclynx/apidom-parser-adapter-arazzo-json-1");
|
|
19
|
+
var _apidomNsArazzo = require("@speclynx/apidom-ns-arazzo-1");
|
|
20
|
+
var _apidomParserAdapterArazzoYaml = require("@speclynx/apidom-parser-adapter-arazzo-yaml-1");
|
|
21
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
22
|
+
var _ParseError = _interopRequireDefault(require("./errors/ParseError.cjs"));
|
|
23
|
+
var _index = _interopRequireDefault(require("./resolve/resolvers/memory/index.cjs"));
|
|
24
|
+
/**
|
|
25
|
+
* Options for parsing Arazzo Documents.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Default reference options for parsing Arazzo Documents.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
const defaultOptions = exports.defaultOptions = {
|
|
34
|
+
parse: {
|
|
35
|
+
parsers: [new _arazzoJson.default({
|
|
36
|
+
allowEmpty: false
|
|
37
|
+
}), new _arazzoYaml.default({
|
|
38
|
+
allowEmpty: false
|
|
39
|
+
}), new _openapiJson.default({
|
|
40
|
+
allowEmpty: false
|
|
41
|
+
}), new _openapiYaml.default({
|
|
42
|
+
allowEmpty: false
|
|
43
|
+
}), new _openapiJson2.default({
|
|
44
|
+
allowEmpty: false
|
|
45
|
+
}), new _openapiYaml2.default({
|
|
46
|
+
allowEmpty: false
|
|
47
|
+
}), new _openapiJson3.default({
|
|
48
|
+
allowEmpty: false
|
|
49
|
+
}), new _openapiYaml3.default({
|
|
50
|
+
allowEmpty: false
|
|
51
|
+
})],
|
|
52
|
+
parserOpts: {
|
|
53
|
+
sourceMap: false,
|
|
54
|
+
style: false,
|
|
55
|
+
strict: true,
|
|
56
|
+
sourceDescriptions: false
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
resolve: {
|
|
60
|
+
resolvers: [new _index.default(), new _file.default({
|
|
61
|
+
fileAllowList: ['*.json', '*.yaml', '*.yml']
|
|
62
|
+
}), new _httpAxios.default({
|
|
63
|
+
timeout: 15000,
|
|
64
|
+
redirects: 5,
|
|
65
|
+
withCredentials: false
|
|
66
|
+
})],
|
|
67
|
+
resolverOpts: {}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Parses an Arazzo Document from an object.
|
|
73
|
+
* @param source - The Arazzo Document as a plain object
|
|
74
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
75
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
76
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Parses an Arazzo Document from a string or URI.
|
|
82
|
+
* @param source - The Arazzo Document as string content, or a file system path / HTTP(S) URL
|
|
83
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
84
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
85
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Parses an Arazzo Document from a string, object, or URI.
|
|
91
|
+
* @param source - The Arazzo Document as a plain object, string content, or URI
|
|
92
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
93
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
94
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
95
|
+
* @public
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Parses an Arazzo Document from a string, object, or URI.
|
|
100
|
+
*
|
|
101
|
+
* The function handles three types of input:
|
|
102
|
+
* 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
|
|
103
|
+
* 2. String content - uses Arazzo detection to identify and parse inline JSON or YAML content
|
|
104
|
+
* 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL
|
|
105
|
+
*
|
|
106
|
+
* @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
|
|
107
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
108
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
109
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* Parse from object
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const result = await parseArazzo({ arazzo: '1.0.1', info: {...} });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* Parse inline JSON
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const result = await parseArazzo('{"arazzo": "1.0.1", "info": {...}}');
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* Parse from file
|
|
125
|
+
* ```typescript
|
|
126
|
+
* const result = await parseArazzo('/path/to/arazzo.json');
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* Parse from URL
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const result = await parseArazzo('https://example.com/arazzo.yaml');
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* Parse with custom options
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const result = await parseArazzo('/path/to/arazzo.json', customOptions);
|
|
139
|
+
* ```
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
async function parse(source, options = {}) {
|
|
143
|
+
let mergedOptions = (0, _empty.mergeOptions)(defaultOptions, options);
|
|
144
|
+
const strict = mergedOptions.parse?.parserOpts?.strict ?? true;
|
|
145
|
+
let sourceProvenance;
|
|
146
|
+
if ((0, _ramdaAdjunct.isPlainObject)(source)) {
|
|
147
|
+
const document = JSON.stringify(source, null, 2);
|
|
148
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
149
|
+
resolve: {
|
|
150
|
+
resolverOpts: {
|
|
151
|
+
document
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
source = 'memory://arazzo.json';
|
|
156
|
+
sourceProvenance = '[object]';
|
|
157
|
+
} else if (await (0, _apidomParserAdapterArazzoJson.detect)(source, {
|
|
158
|
+
strict
|
|
159
|
+
})) {
|
|
160
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
161
|
+
resolve: {
|
|
162
|
+
resolverOpts: {
|
|
163
|
+
document: source
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
source = 'memory://arazzo.json';
|
|
168
|
+
sourceProvenance = '[inline JSON]';
|
|
169
|
+
} else if (await (0, _apidomParserAdapterArazzoYaml.detect)(source, {
|
|
170
|
+
strict
|
|
171
|
+
})) {
|
|
172
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
173
|
+
resolve: {
|
|
174
|
+
resolverOpts: {
|
|
175
|
+
document: source
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
source = 'memory://arazzo.yaml';
|
|
180
|
+
sourceProvenance = '[inline YAML]';
|
|
181
|
+
} else {
|
|
182
|
+
sourceProvenance = source;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// next we assume that source is either file system URI or HTTP(S) URL
|
|
186
|
+
try {
|
|
187
|
+
const parseResult = await (0, _empty.parse)(source, mergedOptions);
|
|
188
|
+
|
|
189
|
+
// set retrievalURI metadata for file/URL sources (not for inline content)
|
|
190
|
+
if (!source.startsWith('memory://')) {
|
|
191
|
+
parseResult.meta.set('retrievalURI', source);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// validate that the parsed document is an Arazzo specification
|
|
195
|
+
if (!(0, _apidomNsArazzo.isArazzoSpecification1Element)(parseResult.api)) {
|
|
196
|
+
throw new _empty.UnmatchedParserError(`Could not find a parser that can parse "${sourceProvenance}" as an Arazzo specification`);
|
|
197
|
+
}
|
|
198
|
+
return parseResult;
|
|
199
|
+
} catch (error) {
|
|
200
|
+
throw new _ParseError.default(`Failed to parse Arazzo Document from "${sourceProvenance}"`, {
|
|
201
|
+
cause: error
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { parse as parseURI, mergeOptions, UnmatchedParserError } from '@speclynx/apidom-reference/configuration/empty';
|
|
2
|
+
import ArazzoJSON1Parser from '@speclynx/apidom-reference/parse/parsers/arazzo-json-1';
|
|
3
|
+
import ArazzoYAML1Parser from '@speclynx/apidom-reference/parse/parsers/arazzo-yaml-1';
|
|
4
|
+
import OpenApiJSON2Parser from '@speclynx/apidom-reference/parse/parsers/openapi-json-2';
|
|
5
|
+
import OpenApiYAML2Parser from '@speclynx/apidom-reference/parse/parsers/openapi-yaml-2';
|
|
6
|
+
import OpenApiJSON3_0Parser from '@speclynx/apidom-reference/parse/parsers/openapi-json-3-0';
|
|
7
|
+
import OpenApiYAML3_0Parser from '@speclynx/apidom-reference/parse/parsers/openapi-yaml-3-0';
|
|
8
|
+
import OpenApiJSON3_1Parser from '@speclynx/apidom-reference/parse/parsers/openapi-json-3-1';
|
|
9
|
+
import OpenApiYAML3_1Parser from '@speclynx/apidom-reference/parse/parsers/openapi-yaml-3-1';
|
|
10
|
+
import FileResolver from '@speclynx/apidom-reference/resolve/resolvers/file';
|
|
11
|
+
import HTTPResolverAxios from '@speclynx/apidom-reference/resolve/resolvers/http-axios';
|
|
12
|
+
import { detect as detectArazzoJSON } from '@speclynx/apidom-parser-adapter-arazzo-json-1';
|
|
13
|
+
import { isArazzoSpecification1Element } from '@speclynx/apidom-ns-arazzo-1';
|
|
14
|
+
import { detect as detectArazzoYAML } from '@speclynx/apidom-parser-adapter-arazzo-yaml-1';
|
|
15
|
+
import { isPlainObject } from 'ramda-adjunct';
|
|
16
|
+
import ParseError from "./errors/ParseError.mjs";
|
|
17
|
+
import MemoryResolver from "./resolve/resolvers/memory/index.mjs";
|
|
18
|
+
/**
|
|
19
|
+
* Options for parsing Arazzo Documents.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Default reference options for parsing Arazzo Documents.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export const defaultOptions = {
|
|
27
|
+
parse: {
|
|
28
|
+
parsers: [new ArazzoJSON1Parser({
|
|
29
|
+
allowEmpty: false
|
|
30
|
+
}), new ArazzoYAML1Parser({
|
|
31
|
+
allowEmpty: false
|
|
32
|
+
}), new OpenApiJSON2Parser({
|
|
33
|
+
allowEmpty: false
|
|
34
|
+
}), new OpenApiYAML2Parser({
|
|
35
|
+
allowEmpty: false
|
|
36
|
+
}), new OpenApiJSON3_0Parser({
|
|
37
|
+
allowEmpty: false
|
|
38
|
+
}), new OpenApiYAML3_0Parser({
|
|
39
|
+
allowEmpty: false
|
|
40
|
+
}), new OpenApiJSON3_1Parser({
|
|
41
|
+
allowEmpty: false
|
|
42
|
+
}), new OpenApiYAML3_1Parser({
|
|
43
|
+
allowEmpty: false
|
|
44
|
+
})],
|
|
45
|
+
parserOpts: {
|
|
46
|
+
sourceMap: false,
|
|
47
|
+
style: false,
|
|
48
|
+
strict: true,
|
|
49
|
+
sourceDescriptions: false
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
resolve: {
|
|
53
|
+
resolvers: [new MemoryResolver(), new FileResolver({
|
|
54
|
+
fileAllowList: ['*.json', '*.yaml', '*.yml']
|
|
55
|
+
}), new HTTPResolverAxios({
|
|
56
|
+
timeout: 15000,
|
|
57
|
+
redirects: 5,
|
|
58
|
+
withCredentials: false
|
|
59
|
+
})],
|
|
60
|
+
resolverOpts: {}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Parses an Arazzo Document from an object.
|
|
66
|
+
* @param source - The Arazzo Document as a plain object
|
|
67
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
68
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
69
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Parses an Arazzo Document from a string or URI.
|
|
75
|
+
* @param source - The Arazzo Document as string content, or a file system path / HTTP(S) URL
|
|
76
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
77
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
78
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Parses an Arazzo Document from a string, object, or URI.
|
|
84
|
+
* @param source - The Arazzo Document as a plain object, string content, or URI
|
|
85
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
86
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
87
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
88
|
+
* @public
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Parses an Arazzo Document from a string, object, or URI.
|
|
93
|
+
*
|
|
94
|
+
* The function handles three types of input:
|
|
95
|
+
* 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
|
|
96
|
+
* 2. String content - uses Arazzo detection to identify and parse inline JSON or YAML content
|
|
97
|
+
* 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL
|
|
98
|
+
*
|
|
99
|
+
* @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
|
|
100
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
101
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
102
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* Parse from object
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const result = await parseArazzo({ arazzo: '1.0.1', info: {...} });
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* Parse inline JSON
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const result = await parseArazzo('{"arazzo": "1.0.1", "info": {...}}');
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* Parse from file
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const result = await parseArazzo('/path/to/arazzo.json');
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* Parse from URL
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const result = await parseArazzo('https://example.com/arazzo.yaml');
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* Parse with custom options
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const result = await parseArazzo('/path/to/arazzo.json', customOptions);
|
|
132
|
+
* ```
|
|
133
|
+
* @public
|
|
134
|
+
*/
|
|
135
|
+
export async function parse(source, options = {}) {
|
|
136
|
+
let mergedOptions = mergeOptions(defaultOptions, options);
|
|
137
|
+
const strict = mergedOptions.parse?.parserOpts?.strict ?? true;
|
|
138
|
+
let sourceProvenance;
|
|
139
|
+
if (isPlainObject(source)) {
|
|
140
|
+
const document = JSON.stringify(source, null, 2);
|
|
141
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
142
|
+
resolve: {
|
|
143
|
+
resolverOpts: {
|
|
144
|
+
document
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
source = 'memory://arazzo.json';
|
|
149
|
+
sourceProvenance = '[object]';
|
|
150
|
+
} else if (await detectArazzoJSON(source, {
|
|
151
|
+
strict
|
|
152
|
+
})) {
|
|
153
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
154
|
+
resolve: {
|
|
155
|
+
resolverOpts: {
|
|
156
|
+
document: source
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
source = 'memory://arazzo.json';
|
|
161
|
+
sourceProvenance = '[inline JSON]';
|
|
162
|
+
} else if (await detectArazzoYAML(source, {
|
|
163
|
+
strict
|
|
164
|
+
})) {
|
|
165
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
166
|
+
resolve: {
|
|
167
|
+
resolverOpts: {
|
|
168
|
+
document: source
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
source = 'memory://arazzo.yaml';
|
|
173
|
+
sourceProvenance = '[inline YAML]';
|
|
174
|
+
} else {
|
|
175
|
+
sourceProvenance = source;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// next we assume that source is either file system URI or HTTP(S) URL
|
|
179
|
+
try {
|
|
180
|
+
const parseResult = await parseURI(source, mergedOptions);
|
|
181
|
+
|
|
182
|
+
// set retrievalURI metadata for file/URL sources (not for inline content)
|
|
183
|
+
if (!source.startsWith('memory://')) {
|
|
184
|
+
parseResult.meta.set('retrievalURI', source);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// validate that the parsed document is an Arazzo specification
|
|
188
|
+
if (!isArazzoSpecification1Element(parseResult.api)) {
|
|
189
|
+
throw new UnmatchedParserError(`Could not find a parser that can parse "${sourceProvenance}" as an Arazzo specification`);
|
|
190
|
+
}
|
|
191
|
+
return parseResult;
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw new ParseError(`Failed to parse Arazzo Document from "${sourceProvenance}"`, {
|
|
194
|
+
cause: error
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
+
exports.__esModule = true;
|
|
5
|
+
exports.defaultOptions = void 0;
|
|
6
|
+
exports.parse = parse;
|
|
7
|
+
var _empty = require("@speclynx/apidom-reference/configuration/empty");
|
|
8
|
+
var _openapiJson = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-json-2"));
|
|
9
|
+
var _openapiYaml = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-yaml-2"));
|
|
10
|
+
var _openapiJson2 = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-json-3-0"));
|
|
11
|
+
var _openapiYaml2 = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-yaml-3-0"));
|
|
12
|
+
var _openapiJson3 = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-json-3-1"));
|
|
13
|
+
var _openapiYaml3 = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/openapi-yaml-3-1"));
|
|
14
|
+
var _apidomParserAdapterOpenapiJson = require("@speclynx/apidom-parser-adapter-openapi-json-3-1");
|
|
15
|
+
var _apidomParserAdapterOpenapiYaml = require("@speclynx/apidom-parser-adapter-openapi-yaml-3-1");
|
|
16
|
+
var _apidomParserAdapterOpenapiJson2 = require("@speclynx/apidom-parser-adapter-openapi-json-3-0");
|
|
17
|
+
var _apidomParserAdapterOpenapiYaml2 = require("@speclynx/apidom-parser-adapter-openapi-yaml-3-0");
|
|
18
|
+
var _apidomParserAdapterOpenapiJson3 = require("@speclynx/apidom-parser-adapter-openapi-json-2");
|
|
19
|
+
var _apidomParserAdapterOpenapiYaml3 = require("@speclynx/apidom-parser-adapter-openapi-yaml-2");
|
|
20
|
+
var _ramdaAdjunct = require("ramda-adjunct");
|
|
21
|
+
var _ParseError = _interopRequireDefault(require("./errors/ParseError.cjs"));
|
|
22
|
+
var _index = _interopRequireDefault(require("./resolve/resolvers/memory/index.cjs"));
|
|
23
|
+
var _parseArazzo = require("./parse-arazzo.cjs");
|
|
24
|
+
/**
|
|
25
|
+
* Options for parsing OpenAPI Documents.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Default reference options for parsing OpenAPI Documents.
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
const defaultOptions = exports.defaultOptions = {
|
|
34
|
+
parse: {
|
|
35
|
+
parsers: [new _openapiJson.default({
|
|
36
|
+
allowEmpty: false
|
|
37
|
+
}), new _openapiYaml.default({
|
|
38
|
+
allowEmpty: false
|
|
39
|
+
}), new _openapiJson2.default({
|
|
40
|
+
allowEmpty: false
|
|
41
|
+
}), new _openapiYaml2.default({
|
|
42
|
+
allowEmpty: false
|
|
43
|
+
}), new _openapiJson3.default({
|
|
44
|
+
allowEmpty: false
|
|
45
|
+
}), new _openapiYaml3.default({
|
|
46
|
+
allowEmpty: false
|
|
47
|
+
})],
|
|
48
|
+
parserOpts: {
|
|
49
|
+
..._parseArazzo.defaultOptions.parse.parserOpts
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
resolve: {
|
|
53
|
+
resolvers: [new _index.default(), ..._parseArazzo.defaultOptions.resolve.resolvers.filter(r => r.name !== 'memory')],
|
|
54
|
+
resolverOpts: {}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Parses an OpenAPI Document from an object.
|
|
60
|
+
* @param source - The OpenAPI Document as a plain object
|
|
61
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
62
|
+
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
63
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Parses an OpenAPI Document from a string or URI.
|
|
69
|
+
* @param source - The OpenAPI Document as string content, or a file system path / HTTP(S) URL
|
|
70
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
71
|
+
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
72
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Parses an OpenAPI Document from a string, object, or URI.
|
|
78
|
+
* @param source - The OpenAPI Document as a plain object, string content, or URI
|
|
79
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
80
|
+
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
81
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Parses an OpenAPI Document from a string, object, or URI.
|
|
87
|
+
*
|
|
88
|
+
* The function handles three types of input:
|
|
89
|
+
* 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
|
|
90
|
+
* 2. String content - uses OpenAPI detection to identify and parse inline JSON or YAML content
|
|
91
|
+
* 3. URI string - if not detected as OpenAPI content, treats as file system path or HTTP(S) URL
|
|
92
|
+
*
|
|
93
|
+
* @param source - The OpenAPI Document as an object, string content, or a file system path / HTTP(S) URL
|
|
94
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
95
|
+
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
96
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* Parse from object
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const result = await parseOpenAPI({ openapi: '3.1.0', info: {...} });
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* Parse inline JSON
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const result = await parseOpenAPI('{"openapi": "3.1.0", "info": {...}}');
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* Parse from file
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const result = await parseOpenAPI('/path/to/openapi.json');
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* Parse from URL
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const result = await parseOpenAPI('https://example.com/openapi.yaml');
|
|
120
|
+
* ```
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* Parse with custom options
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const result = await parseOpenAPI('/path/to/openapi.json', customOptions);
|
|
126
|
+
* ```
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
async function parse(source, options = {}) {
|
|
130
|
+
let mergedOptions = (0, _empty.mergeOptions)(defaultOptions, options);
|
|
131
|
+
const strict = mergedOptions.parse?.parserOpts?.strict ?? true;
|
|
132
|
+
let sourceProvenance;
|
|
133
|
+
if ((0, _ramdaAdjunct.isPlainObject)(source)) {
|
|
134
|
+
const document = JSON.stringify(source, null, 2);
|
|
135
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
136
|
+
resolve: {
|
|
137
|
+
resolverOpts: {
|
|
138
|
+
document
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
source = 'memory://openapi.json';
|
|
143
|
+
sourceProvenance = '[object]';
|
|
144
|
+
} else if (await (0, _apidomParserAdapterOpenapiJson3.detect)(source, {
|
|
145
|
+
strict
|
|
146
|
+
})) {
|
|
147
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
148
|
+
resolve: {
|
|
149
|
+
resolverOpts: {
|
|
150
|
+
document: source
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
source = 'memory://openapi.json';
|
|
155
|
+
sourceProvenance = '[inline JSON]';
|
|
156
|
+
} else if (await (0, _apidomParserAdapterOpenapiYaml3.detect)(source, {
|
|
157
|
+
strict
|
|
158
|
+
})) {
|
|
159
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
160
|
+
resolve: {
|
|
161
|
+
resolverOpts: {
|
|
162
|
+
document: source
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
source = 'memory://openapi.yaml';
|
|
167
|
+
sourceProvenance = '[inline YAML]';
|
|
168
|
+
} else if (await (0, _apidomParserAdapterOpenapiJson2.detect)(source, {
|
|
169
|
+
strict
|
|
170
|
+
})) {
|
|
171
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
172
|
+
resolve: {
|
|
173
|
+
resolverOpts: {
|
|
174
|
+
document: source
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
source = 'memory://openapi.json';
|
|
179
|
+
sourceProvenance = '[inline JSON]';
|
|
180
|
+
} else if (await (0, _apidomParserAdapterOpenapiYaml2.detect)(source, {
|
|
181
|
+
strict
|
|
182
|
+
})) {
|
|
183
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
184
|
+
resolve: {
|
|
185
|
+
resolverOpts: {
|
|
186
|
+
document: source
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
source = 'memory://openapi.yaml';
|
|
191
|
+
sourceProvenance = '[inline YAML]';
|
|
192
|
+
} else if (await (0, _apidomParserAdapterOpenapiJson.detect)(source, {
|
|
193
|
+
strict
|
|
194
|
+
})) {
|
|
195
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
196
|
+
resolve: {
|
|
197
|
+
resolverOpts: {
|
|
198
|
+
document: source
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
source = 'memory://openapi.json';
|
|
203
|
+
sourceProvenance = '[inline JSON]';
|
|
204
|
+
} else if (await (0, _apidomParserAdapterOpenapiYaml.detect)(source, {
|
|
205
|
+
strict
|
|
206
|
+
})) {
|
|
207
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
208
|
+
resolve: {
|
|
209
|
+
resolverOpts: {
|
|
210
|
+
document: source
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
source = 'memory://openapi.yaml';
|
|
215
|
+
sourceProvenance = '[inline YAML]';
|
|
216
|
+
} else {
|
|
217
|
+
sourceProvenance = source;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// next we assume that source is either file system URI or HTTP(S) URL
|
|
221
|
+
try {
|
|
222
|
+
const parseResult = await (0, _empty.parse)(source, mergedOptions);
|
|
223
|
+
|
|
224
|
+
// set retrievalURI metadata for file/URL sources (not for inline content)
|
|
225
|
+
if (!source.startsWith('memory://')) {
|
|
226
|
+
parseResult.meta.set('retrievalURI', source);
|
|
227
|
+
}
|
|
228
|
+
return parseResult;
|
|
229
|
+
} catch (error) {
|
|
230
|
+
throw new _ParseError.default(`Failed to parse OpenAPI Document from "${sourceProvenance}"`, {
|
|
231
|
+
cause: error
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { parse as parseURI, mergeOptions } from '@speclynx/apidom-reference/configuration/empty';
|
|
2
|
+
import OpenApiJSON2Parser from '@speclynx/apidom-reference/parse/parsers/openapi-json-2';
|
|
3
|
+
import OpenApiYAML2Parser from '@speclynx/apidom-reference/parse/parsers/openapi-yaml-2';
|
|
4
|
+
import OpenApiJSON3_0Parser from '@speclynx/apidom-reference/parse/parsers/openapi-json-3-0';
|
|
5
|
+
import OpenApiYAML3_0Parser from '@speclynx/apidom-reference/parse/parsers/openapi-yaml-3-0';
|
|
6
|
+
import OpenApiJSON3_1Parser from '@speclynx/apidom-reference/parse/parsers/openapi-json-3-1';
|
|
7
|
+
import OpenApiYAML3_1Parser from '@speclynx/apidom-reference/parse/parsers/openapi-yaml-3-1';
|
|
8
|
+
import { detect as detectOpenApiJSON3_1 } from '@speclynx/apidom-parser-adapter-openapi-json-3-1';
|
|
9
|
+
import { detect as detectOpenApiYAML3_1 } from '@speclynx/apidom-parser-adapter-openapi-yaml-3-1';
|
|
10
|
+
import { detect as detectOpenApiJSON3_0 } from '@speclynx/apidom-parser-adapter-openapi-json-3-0';
|
|
11
|
+
import { detect as detectOpenApiYAML3_0 } from '@speclynx/apidom-parser-adapter-openapi-yaml-3-0';
|
|
12
|
+
import { detect as detectOpenApiJSON2 } from '@speclynx/apidom-parser-adapter-openapi-json-2';
|
|
13
|
+
import { detect as detectOpenApiYAML2 } from '@speclynx/apidom-parser-adapter-openapi-yaml-2';
|
|
14
|
+
import { isPlainObject } from 'ramda-adjunct';
|
|
15
|
+
import ParseError from "./errors/ParseError.mjs";
|
|
16
|
+
import MemoryResolver from "./resolve/resolvers/memory/index.mjs";
|
|
17
|
+
import { defaultOptions as arazzoDefaultOptions } from "./parse-arazzo.mjs";
|
|
18
|
+
/**
|
|
19
|
+
* Options for parsing OpenAPI Documents.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Default reference options for parsing OpenAPI Documents.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export const defaultOptions = {
|
|
27
|
+
parse: {
|
|
28
|
+
parsers: [new OpenApiJSON2Parser({
|
|
29
|
+
allowEmpty: false
|
|
30
|
+
}), new OpenApiYAML2Parser({
|
|
31
|
+
allowEmpty: false
|
|
32
|
+
}), new OpenApiJSON3_0Parser({
|
|
33
|
+
allowEmpty: false
|
|
34
|
+
}), new OpenApiYAML3_0Parser({
|
|
35
|
+
allowEmpty: false
|
|
36
|
+
}), new OpenApiJSON3_1Parser({
|
|
37
|
+
allowEmpty: false
|
|
38
|
+
}), new OpenApiYAML3_1Parser({
|
|
39
|
+
allowEmpty: false
|
|
40
|
+
})],
|
|
41
|
+
parserOpts: {
|
|
42
|
+
...arazzoDefaultOptions.parse.parserOpts
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
resolve: {
|
|
46
|
+
resolvers: [new MemoryResolver(), ...arazzoDefaultOptions.resolve.resolvers.filter(r => r.name !== 'memory')],
|
|
47
|
+
resolverOpts: {}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Parses an OpenAPI Document from an object.
|
|
53
|
+
* @param source - The OpenAPI Document as a plain object
|
|
54
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
55
|
+
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
56
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Parses an OpenAPI Document from a string or URI.
|
|
62
|
+
* @param source - The OpenAPI Document as string content, or a file system path / HTTP(S) URL
|
|
63
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
64
|
+
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
65
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Parses an OpenAPI Document from a string, object, or URI.
|
|
71
|
+
* @param source - The OpenAPI Document as a plain object, string content, or URI
|
|
72
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
73
|
+
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
74
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
75
|
+
* @public
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Parses an OpenAPI Document from a string, object, or URI.
|
|
80
|
+
*
|
|
81
|
+
* The function handles three types of input:
|
|
82
|
+
* 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
|
|
83
|
+
* 2. String content - uses OpenAPI detection to identify and parse inline JSON or YAML content
|
|
84
|
+
* 3. URI string - if not detected as OpenAPI content, treats as file system path or HTTP(S) URL
|
|
85
|
+
*
|
|
86
|
+
* @param source - The OpenAPI Document as an object, string content, or a file system path / HTTP(S) URL
|
|
87
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
88
|
+
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
89
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* Parse from object
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const result = await parseOpenAPI({ openapi: '3.1.0', info: {...} });
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* Parse inline JSON
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const result = await parseOpenAPI('{"openapi": "3.1.0", "info": {...}}');
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* Parse from file
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const result = await parseOpenAPI('/path/to/openapi.json');
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* Parse from URL
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const result = await parseOpenAPI('https://example.com/openapi.yaml');
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* Parse with custom options
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const result = await parseOpenAPI('/path/to/openapi.json', customOptions);
|
|
119
|
+
* ```
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
export async function parse(source, options = {}) {
|
|
123
|
+
let mergedOptions = mergeOptions(defaultOptions, options);
|
|
124
|
+
const strict = mergedOptions.parse?.parserOpts?.strict ?? true;
|
|
125
|
+
let sourceProvenance;
|
|
126
|
+
if (isPlainObject(source)) {
|
|
127
|
+
const document = JSON.stringify(source, null, 2);
|
|
128
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
129
|
+
resolve: {
|
|
130
|
+
resolverOpts: {
|
|
131
|
+
document
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
source = 'memory://openapi.json';
|
|
136
|
+
sourceProvenance = '[object]';
|
|
137
|
+
} else if (await detectOpenApiJSON2(source, {
|
|
138
|
+
strict
|
|
139
|
+
})) {
|
|
140
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
141
|
+
resolve: {
|
|
142
|
+
resolverOpts: {
|
|
143
|
+
document: source
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
source = 'memory://openapi.json';
|
|
148
|
+
sourceProvenance = '[inline JSON]';
|
|
149
|
+
} else if (await detectOpenApiYAML2(source, {
|
|
150
|
+
strict
|
|
151
|
+
})) {
|
|
152
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
153
|
+
resolve: {
|
|
154
|
+
resolverOpts: {
|
|
155
|
+
document: source
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
source = 'memory://openapi.yaml';
|
|
160
|
+
sourceProvenance = '[inline YAML]';
|
|
161
|
+
} else if (await detectOpenApiJSON3_0(source, {
|
|
162
|
+
strict
|
|
163
|
+
})) {
|
|
164
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
165
|
+
resolve: {
|
|
166
|
+
resolverOpts: {
|
|
167
|
+
document: source
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
source = 'memory://openapi.json';
|
|
172
|
+
sourceProvenance = '[inline JSON]';
|
|
173
|
+
} else if (await detectOpenApiYAML3_0(source, {
|
|
174
|
+
strict
|
|
175
|
+
})) {
|
|
176
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
177
|
+
resolve: {
|
|
178
|
+
resolverOpts: {
|
|
179
|
+
document: source
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
source = 'memory://openapi.yaml';
|
|
184
|
+
sourceProvenance = '[inline YAML]';
|
|
185
|
+
} else if (await detectOpenApiJSON3_1(source, {
|
|
186
|
+
strict
|
|
187
|
+
})) {
|
|
188
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
189
|
+
resolve: {
|
|
190
|
+
resolverOpts: {
|
|
191
|
+
document: source
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
source = 'memory://openapi.json';
|
|
196
|
+
sourceProvenance = '[inline JSON]';
|
|
197
|
+
} else if (await detectOpenApiYAML3_1(source, {
|
|
198
|
+
strict
|
|
199
|
+
})) {
|
|
200
|
+
mergedOptions = mergeOptions(mergedOptions, {
|
|
201
|
+
resolve: {
|
|
202
|
+
resolverOpts: {
|
|
203
|
+
document: source
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
source = 'memory://openapi.yaml';
|
|
208
|
+
sourceProvenance = '[inline YAML]';
|
|
209
|
+
} else {
|
|
210
|
+
sourceProvenance = source;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// next we assume that source is either file system URI or HTTP(S) URL
|
|
214
|
+
try {
|
|
215
|
+
const parseResult = await parseURI(source, mergedOptions);
|
|
216
|
+
|
|
217
|
+
// set retrievalURI metadata for file/URL sources (not for inline content)
|
|
218
|
+
if (!source.startsWith('memory://')) {
|
|
219
|
+
parseResult.meta.set('retrievalURI', source);
|
|
220
|
+
}
|
|
221
|
+
return parseResult;
|
|
222
|
+
} catch (error) {
|
|
223
|
+
throw new ParseError(`Failed to parse OpenAPI Document from "${sourceProvenance}"`, {
|
|
224
|
+
cause: error
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var _empty = require("@speclynx/apidom-reference/configuration/empty");
|
|
6
|
+
/**
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
class MemoryResolver extends _empty.Resolver {
|
|
10
|
+
constructor() {
|
|
11
|
+
super({
|
|
12
|
+
name: 'memory'
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
canRead(file) {
|
|
16
|
+
return file.uri.startsWith('memory://') && this.document !== undefined;
|
|
17
|
+
}
|
|
18
|
+
async read(file) {
|
|
19
|
+
try {
|
|
20
|
+
const encoder = new TextEncoder();
|
|
21
|
+
return encoder.encode(this.document);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throw new _empty.ResolverError(`Error opening file "${file.uri}"`, {
|
|
24
|
+
cause: error
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var _default = exports.default = MemoryResolver;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Resolver, ResolverError } from '@speclynx/apidom-reference/configuration/empty';
|
|
2
|
+
/**
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
class MemoryResolver extends Resolver {
|
|
6
|
+
constructor() {
|
|
7
|
+
super({
|
|
8
|
+
name: 'memory'
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
canRead(file) {
|
|
12
|
+
return file.uri.startsWith('memory://') && this.document !== undefined;
|
|
13
|
+
}
|
|
14
|
+
async read(file) {
|
|
15
|
+
try {
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
return encoder.encode(this.document);
|
|
18
|
+
} catch (error) {
|
|
19
|
+
throw new ResolverError(`Error opening file "${file.uri}"`, {
|
|
20
|
+
cause: error
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export default MemoryResolver;
|