@jentic/arazzo-parser 1.0.0-alpha.2 → 1.0.0-alpha.21
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 +104 -0
- package/README.md +453 -49
- package/dist/jentic-arazzo-parser.browser.js +70344 -46424
- package/dist/jentic-arazzo-parser.browser.min.js +1 -1
- package/package.json +25 -10
- package/src/index.cjs +7 -152
- package/src/index.mjs +2 -147
- package/src/parse-arazzo.cjs +195 -0
- package/src/parse-arazzo.mjs +188 -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/types/arazzo-parser.d.ts +43 -30
- package/dist/937fc7a248317278ae14.wasm +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jentic/arazzo-parser",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.21",
|
|
4
4
|
"description": "Parser for Arazzo Documents producing SpecLynx ApiDOM data model.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"arazzo",
|
|
7
|
+
"arazzo-specification",
|
|
8
|
+
"parser",
|
|
9
|
+
"datamodel",
|
|
10
|
+
"workflow",
|
|
11
|
+
"workflows"
|
|
12
|
+
],
|
|
5
13
|
"publishConfig": {
|
|
6
14
|
"access": "public",
|
|
7
15
|
"registry": "https://registry.npmjs.org",
|
|
@@ -40,14 +48,21 @@
|
|
|
40
48
|
"license": "Apache-2.0",
|
|
41
49
|
"dependencies": {
|
|
42
50
|
"@babel/runtime-corejs3": "^7.28.4",
|
|
43
|
-
"@speclynx/apidom-
|
|
44
|
-
"@speclynx/apidom-
|
|
45
|
-
"@speclynx/apidom-
|
|
46
|
-
"@speclynx/apidom-
|
|
47
|
-
"@speclynx/apidom-parser-adapter-arazzo-json-1": "^2.
|
|
48
|
-
"@speclynx/apidom-parser-adapter-arazzo-yaml-1": "^2.
|
|
49
|
-
"@speclynx/apidom-
|
|
50
|
-
"
|
|
51
|
+
"@speclynx/apidom-core": "^2.12.4",
|
|
52
|
+
"@speclynx/apidom-datamodel": "^2.12.4",
|
|
53
|
+
"@speclynx/apidom-error": "^2.12.4",
|
|
54
|
+
"@speclynx/apidom-ns-arazzo-1": "^2.12.4",
|
|
55
|
+
"@speclynx/apidom-parser-adapter-arazzo-json-1": "^2.12.4",
|
|
56
|
+
"@speclynx/apidom-parser-adapter-arazzo-yaml-1": "^2.12.4",
|
|
57
|
+
"@speclynx/apidom-parser-adapter-openapi-json-2": "^2.12.4",
|
|
58
|
+
"@speclynx/apidom-parser-adapter-openapi-json-3-0": "^2.12.4",
|
|
59
|
+
"@speclynx/apidom-parser-adapter-openapi-json-3-1": "^2.12.4",
|
|
60
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-2": "^2.12.4",
|
|
61
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "^2.12.4",
|
|
62
|
+
"@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "^2.12.4",
|
|
63
|
+
"@speclynx/apidom-reference": "^2.12.4",
|
|
64
|
+
"ramda-adjunct": "^6.0.0",
|
|
65
|
+
"type-fest": "^5.4.3"
|
|
51
66
|
},
|
|
52
67
|
"files": [
|
|
53
68
|
"src/**/*.mjs",
|
|
@@ -59,5 +74,5 @@
|
|
|
59
74
|
"README.md",
|
|
60
75
|
"CHANGELOG.md"
|
|
61
76
|
],
|
|
62
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "1f72bd8cba7381dba030eafa719724a56354f290"
|
|
63
78
|
}
|
package/src/index.cjs
CHANGED
|
@@ -1,155 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
|
|
4
|
-
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
|
5
3
|
exports.__esModule = true;
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var _empty = require("@speclynx/apidom-reference/configuration/empty");
|
|
14
|
-
var _arazzoJson = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/arazzo-json-1"));
|
|
15
|
-
var _arazzoYaml = _interopRequireDefault(require("@speclynx/apidom-reference/parse/parsers/arazzo-yaml-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 _ramdaAdjunct = require("ramda-adjunct");
|
|
19
|
-
var _ParseError = _interopRequireDefault(require("./errors/ParseError.cjs"));
|
|
20
|
-
/**
|
|
21
|
-
* Options for parsing Arazzo Documents.
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Default options for parsing Arazzo Documents.
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
const defaultParseOptions = exports.defaultParseOptions = {
|
|
30
|
-
strict: true,
|
|
31
|
-
sourceMap: false,
|
|
32
|
-
parserOpts: {},
|
|
33
|
-
resolverOpts: {}
|
|
34
|
-
};
|
|
35
|
-
const parser = new _apidomParser.default();
|
|
36
|
-
parser.use(jsonParserAdapter);
|
|
37
|
-
parser.use(yamlParserAdapter);
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Parses an Arazzo Document from an object.
|
|
41
|
-
* @param source - The Arazzo Document as a plain object
|
|
42
|
-
* @param options - Parsing options
|
|
43
|
-
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
44
|
-
* @public
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Parses an Arazzo Document from a string or URI.
|
|
49
|
-
* @param source - The Arazzo Document as string content, or a file system path / HTTP(S) URL
|
|
50
|
-
* @param options - Parsing options
|
|
51
|
-
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
52
|
-
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
53
|
-
* @public
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Parses an Arazzo Document from a string, object, or URI.
|
|
58
|
-
*
|
|
59
|
-
* The function handles three types of input:
|
|
60
|
-
* 1. Object - directly refracts the object into an Arazzo specification element
|
|
61
|
-
* 2. String content - attempts to parse as an inline Arazzo Document (JSON or YAML)
|
|
62
|
-
* 3. URI string - treats as a file system path or HTTP(S) URL and resolves the document
|
|
63
|
-
*
|
|
64
|
-
* @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
|
|
65
|
-
* @param options - Parsing options
|
|
66
|
-
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
67
|
-
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* // Parse from object
|
|
71
|
-
* const result = await parse(\{ arazzo: '1.0.1', info: \{...\} \});
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* // Parse inline JSON
|
|
75
|
-
* const result = await parse('\{"arazzo": "1.0.1", "info": \{...\}\}');
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* // Parse from file
|
|
79
|
-
* const result = await parse('/path/to/arazzo.json');
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* // Parse from URL
|
|
83
|
-
* const result = await parse('https://example.com/arazzo.yaml');
|
|
84
|
-
* @public
|
|
85
|
-
*/
|
|
86
|
-
async function parse(source, options = {}) {
|
|
87
|
-
const mergedOptions = {
|
|
88
|
-
...defaultParseOptions,
|
|
89
|
-
...options
|
|
90
|
-
};
|
|
91
|
-
const {
|
|
92
|
-
strict,
|
|
93
|
-
sourceMap,
|
|
94
|
-
parserOpts,
|
|
95
|
-
resolverOpts
|
|
96
|
-
} = mergedOptions;
|
|
97
|
-
|
|
98
|
-
// attempt to parse source as plain object
|
|
99
|
-
if ((0, _ramdaAdjunct.isPlainObject)(source)) {
|
|
100
|
-
if (sourceMap) {
|
|
101
|
-
throw new _ParseError.default('sourceMap option is not supported when parsing from object: source maps cannot be inferred from plain objects');
|
|
102
|
-
}
|
|
103
|
-
const parseResult = new _apidomDatamodel.ParseResultElement();
|
|
104
|
-
const element = (0, _apidomNsArazzo.refractArazzoSpecification1)(source);
|
|
105
|
-
element.classes.push('result');
|
|
106
|
-
parseResult.push(element);
|
|
107
|
-
return parseResult;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// next try to parse the source assuming it contains Arazzo Document
|
|
111
|
-
try {
|
|
112
|
-
return await parser.parse(source, {
|
|
113
|
-
sourceMap,
|
|
114
|
-
strict
|
|
115
|
-
});
|
|
116
|
-
} catch (error) {
|
|
117
|
-
if (error instanceof _apidomParser.ParserError && error.message !== 'Source did not match any registered parsers') {
|
|
118
|
-
throw new _ParseError.default('Failed to parse Arazzo Document', {
|
|
119
|
-
cause: error
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// next we assume that source is either file system URI or HTTP(S) URL
|
|
125
|
-
try {
|
|
126
|
-
return await (0, _empty.parse)(source, {
|
|
127
|
-
parse: {
|
|
128
|
-
parsers: [new _arazzoJson.default({
|
|
129
|
-
allowEmpty: false,
|
|
130
|
-
sourceMap,
|
|
131
|
-
strict
|
|
132
|
-
}), new _arazzoYaml.default({
|
|
133
|
-
allowEmpty: false,
|
|
134
|
-
sourceMap,
|
|
135
|
-
strict
|
|
136
|
-
})],
|
|
137
|
-
parserOpts
|
|
138
|
-
},
|
|
139
|
-
resolve: {
|
|
140
|
-
resolvers: [new _file.default({
|
|
141
|
-
fileAllowList: ['*.json', '*.yaml', '*.yml']
|
|
142
|
-
}), new _httpAxios.default({
|
|
143
|
-
timeout: 5000,
|
|
144
|
-
redirects: 5,
|
|
145
|
-
withCredentials: false
|
|
146
|
-
})],
|
|
147
|
-
resolverOpts
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
} catch (error) {
|
|
151
|
-
throw new _ParseError.default('Failed to parse Arazzo Document from URI', {
|
|
152
|
-
cause: error
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
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
CHANGED
|
@@ -1,147 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import ApiDOMParser, { ParserError } from '@speclynx/apidom-parser';
|
|
4
|
-
import * as jsonParserAdapter from '@speclynx/apidom-parser-adapter-arazzo-json-1';
|
|
5
|
-
import * as yamlParserAdapter from '@speclynx/apidom-parser-adapter-arazzo-yaml-1';
|
|
6
|
-
import { parse as parseURI } from '@speclynx/apidom-reference/configuration/empty';
|
|
7
|
-
import ArazzoJSON1Parser from '@speclynx/apidom-reference/parse/parsers/arazzo-json-1';
|
|
8
|
-
import ArazzoYAML1Parser from '@speclynx/apidom-reference/parse/parsers/arazzo-yaml-1';
|
|
9
|
-
import FileResolver from '@speclynx/apidom-reference/resolve/resolvers/file';
|
|
10
|
-
import HTTPResolverAxios from '@speclynx/apidom-reference/resolve/resolvers/http-axios';
|
|
11
|
-
import { isPlainObject } from 'ramda-adjunct';
|
|
12
|
-
import ParseError from "./errors/ParseError.mjs";
|
|
13
|
-
/**
|
|
14
|
-
* Options for parsing Arazzo Documents.
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* Default options for parsing Arazzo Documents.
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
|
-
export const defaultParseOptions = {
|
|
22
|
-
strict: true,
|
|
23
|
-
sourceMap: false,
|
|
24
|
-
parserOpts: {},
|
|
25
|
-
resolverOpts: {}
|
|
26
|
-
};
|
|
27
|
-
const parser = new ApiDOMParser();
|
|
28
|
-
parser.use(jsonParserAdapter);
|
|
29
|
-
parser.use(yamlParserAdapter);
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Parses an Arazzo Document from an object.
|
|
33
|
-
* @param source - The Arazzo Document as a plain object
|
|
34
|
-
* @param options - Parsing options
|
|
35
|
-
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Parses an Arazzo Document from a string or URI.
|
|
41
|
-
* @param source - The Arazzo Document as string content, or a file system path / HTTP(S) URL
|
|
42
|
-
* @param options - Parsing options
|
|
43
|
-
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
44
|
-
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
45
|
-
* @public
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Parses an Arazzo Document from a string, object, or URI.
|
|
50
|
-
*
|
|
51
|
-
* The function handles three types of input:
|
|
52
|
-
* 1. Object - directly refracts the object into an Arazzo specification element
|
|
53
|
-
* 2. String content - attempts to parse as an inline Arazzo Document (JSON or YAML)
|
|
54
|
-
* 3. URI string - treats as a file system path or HTTP(S) URL and resolves the document
|
|
55
|
-
*
|
|
56
|
-
* @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
|
|
57
|
-
* @param options - Parsing options
|
|
58
|
-
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
59
|
-
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
60
|
-
*
|
|
61
|
-
* @example
|
|
62
|
-
* // Parse from object
|
|
63
|
-
* const result = await parse(\{ arazzo: '1.0.1', info: \{...\} \});
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* // Parse inline JSON
|
|
67
|
-
* const result = await parse('\{"arazzo": "1.0.1", "info": \{...\}\}');
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* // Parse from file
|
|
71
|
-
* const result = await parse('/path/to/arazzo.json');
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* // Parse from URL
|
|
75
|
-
* const result = await parse('https://example.com/arazzo.yaml');
|
|
76
|
-
* @public
|
|
77
|
-
*/
|
|
78
|
-
export async function parse(source, options = {}) {
|
|
79
|
-
const mergedOptions = {
|
|
80
|
-
...defaultParseOptions,
|
|
81
|
-
...options
|
|
82
|
-
};
|
|
83
|
-
const {
|
|
84
|
-
strict,
|
|
85
|
-
sourceMap,
|
|
86
|
-
parserOpts,
|
|
87
|
-
resolverOpts
|
|
88
|
-
} = mergedOptions;
|
|
89
|
-
|
|
90
|
-
// attempt to parse source as plain object
|
|
91
|
-
if (isPlainObject(source)) {
|
|
92
|
-
if (sourceMap) {
|
|
93
|
-
throw new ParseError('sourceMap option is not supported when parsing from object: source maps cannot be inferred from plain objects');
|
|
94
|
-
}
|
|
95
|
-
const parseResult = new ParseResultElement();
|
|
96
|
-
const element = refractArazzoSpecification1(source);
|
|
97
|
-
element.classes.push('result');
|
|
98
|
-
parseResult.push(element);
|
|
99
|
-
return parseResult;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// next try to parse the source assuming it contains Arazzo Document
|
|
103
|
-
try {
|
|
104
|
-
return await parser.parse(source, {
|
|
105
|
-
sourceMap,
|
|
106
|
-
strict
|
|
107
|
-
});
|
|
108
|
-
} catch (error) {
|
|
109
|
-
if (error instanceof ParserError && error.message !== 'Source did not match any registered parsers') {
|
|
110
|
-
throw new ParseError('Failed to parse Arazzo Document', {
|
|
111
|
-
cause: error
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// next we assume that source is either file system URI or HTTP(S) URL
|
|
117
|
-
try {
|
|
118
|
-
return await parseURI(source, {
|
|
119
|
-
parse: {
|
|
120
|
-
parsers: [new ArazzoJSON1Parser({
|
|
121
|
-
allowEmpty: false,
|
|
122
|
-
sourceMap,
|
|
123
|
-
strict
|
|
124
|
-
}), new ArazzoYAML1Parser({
|
|
125
|
-
allowEmpty: false,
|
|
126
|
-
sourceMap,
|
|
127
|
-
strict
|
|
128
|
-
})],
|
|
129
|
-
parserOpts
|
|
130
|
-
},
|
|
131
|
-
resolve: {
|
|
132
|
-
resolvers: [new FileResolver({
|
|
133
|
-
fileAllowList: ['*.json', '*.yaml', '*.yml']
|
|
134
|
-
}), new HTTPResolverAxios({
|
|
135
|
-
timeout: 5000,
|
|
136
|
-
redirects: 5,
|
|
137
|
-
withCredentials: false
|
|
138
|
-
})],
|
|
139
|
-
resolverOpts
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
} catch (error) {
|
|
143
|
-
throw new ParseError('Failed to parse Arazzo Document from URI', {
|
|
144
|
-
cause: error
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
}
|
|
1
|
+
export { parse as parseArazzo, defaultOptions as defaultArazzoOptions } from "./parse-arazzo.mjs";
|
|
2
|
+
export { parse as parseOpenAPI, defaultOptions as defaultOpenAPIOptions } from "./parse-openapi.mjs";
|
|
@@ -0,0 +1,195 @@
|
|
|
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: 5000,
|
|
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
|
+
*
|
|
92
|
+
* The function handles three types of input:
|
|
93
|
+
* 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
|
|
94
|
+
* 2. String content - uses Arazzo detection to identify and parse inline JSON or YAML content
|
|
95
|
+
* 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL
|
|
96
|
+
*
|
|
97
|
+
* @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
|
|
98
|
+
* @param options - Reference options (uses defaultOptions when not provided)
|
|
99
|
+
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
100
|
+
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* Parse from object
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const result = await parseArazzo({ arazzo: '1.0.1', info: {...} });
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* Parse inline JSON
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const result = await parseArazzo('{"arazzo": "1.0.1", "info": {...}}');
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* Parse from file
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const result = await parseArazzo('/path/to/arazzo.json');
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* Parse from URL
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const result = await parseArazzo('https://example.com/arazzo.yaml');
|
|
124
|
+
* ```
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* Parse with custom options
|
|
128
|
+
* ```typescript
|
|
129
|
+
* const result = await parseArazzo('/path/to/arazzo.json', customOptions);
|
|
130
|
+
* ```
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
async function parse(source, options = {}) {
|
|
134
|
+
let mergedOptions = (0, _empty.mergeOptions)(defaultOptions, options);
|
|
135
|
+
const strict = mergedOptions.parse?.parserOpts?.strict ?? true;
|
|
136
|
+
let sourceProvenance;
|
|
137
|
+
if ((0, _ramdaAdjunct.isPlainObject)(source)) {
|
|
138
|
+
const document = JSON.stringify(source, null, 2);
|
|
139
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
140
|
+
resolve: {
|
|
141
|
+
resolverOpts: {
|
|
142
|
+
document
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
source = 'memory://arazzo.json';
|
|
147
|
+
sourceProvenance = '[object]';
|
|
148
|
+
} else if (await (0, _apidomParserAdapterArazzoJson.detect)(source, {
|
|
149
|
+
strict
|
|
150
|
+
})) {
|
|
151
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
152
|
+
resolve: {
|
|
153
|
+
resolverOpts: {
|
|
154
|
+
document: source
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
source = 'memory://arazzo.json';
|
|
159
|
+
sourceProvenance = '[inline JSON]';
|
|
160
|
+
} else if (await (0, _apidomParserAdapterArazzoYaml.detect)(source, {
|
|
161
|
+
strict
|
|
162
|
+
})) {
|
|
163
|
+
mergedOptions = (0, _empty.mergeOptions)(mergedOptions, {
|
|
164
|
+
resolve: {
|
|
165
|
+
resolverOpts: {
|
|
166
|
+
document: source
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
source = 'memory://arazzo.yaml';
|
|
171
|
+
sourceProvenance = '[inline YAML]';
|
|
172
|
+
} else {
|
|
173
|
+
sourceProvenance = source;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// next we assume that source is either file system URI or HTTP(S) URL
|
|
177
|
+
try {
|
|
178
|
+
const parseResult = await (0, _empty.parse)(source, mergedOptions);
|
|
179
|
+
|
|
180
|
+
// set retrievalURI metadata for file/URL sources (not for inline content)
|
|
181
|
+
if (!source.startsWith('memory://')) {
|
|
182
|
+
parseResult.meta.set('retrievalURI', source);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// validate that the parsed document is an Arazzo specification
|
|
186
|
+
if (!(0, _apidomNsArazzo.isArazzoSpecification1Element)(parseResult.api)) {
|
|
187
|
+
throw new _empty.UnmatchedParserError(`Could not find a parser that can parse "${sourceProvenance}" as an Arazzo specification`);
|
|
188
|
+
}
|
|
189
|
+
return parseResult;
|
|
190
|
+
} catch (error) {
|
|
191
|
+
throw new _ParseError.default(`Failed to parse Arazzo Document from "${sourceProvenance}"`, {
|
|
192
|
+
cause: error
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|