@jentic/arazzo-parser 1.0.0-alpha.24 → 1.0.0-alpha.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jentic/arazzo-parser",
3
- "version": "1.0.0-alpha.24",
3
+ "version": "1.0.0-alpha.26",
4
4
  "description": "Parser for Arazzo Documents producing SpecLynx ApiDOM data model.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -67,8 +67,7 @@
67
67
  "@speclynx/apidom-core": "^4.0.3"
68
68
  },
69
69
  "files": [
70
- "src/**/*.mjs",
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": "4d69c9a6c690d8fac8938c7032f57258948d76ce"
78
+ "gitHead": "fa8637a6e4ad80e321a5808da52e4346a1a1f0d7"
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;
@@ -0,0 +1,7 @@
1
+ import { ApiDOMError } from '@speclynx/apidom-error';
2
+ class ParseError extends ApiDOMError {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ }
6
+ }
7
+ export 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.defaultParseOpenAPIOptions = exports.defaultParseArazzoOptions = void 0;
5
+ var _parseArazzo = require("./parse-arazzo.cjs");
6
+ exports.parseArazzo = _parseArazzo.parse;
7
+ exports.defaultParseArazzoOptions = _parseArazzo.defaultOptions;
8
+ var _parseOpenapi = require("./parse-openapi.cjs");
9
+ exports.parseOpenAPI = _parseOpenapi.parse;
10
+ exports.defaultParseOpenAPIOptions = _parseOpenapi.defaultOptions;
package/src/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export { parse as parseArazzo, defaultOptions as defaultParseArazzoOptions } from "./parse-arazzo.mjs";
2
+ export { parse as parseOpenAPI, defaultOptions as defaultParseOpenAPIOptions } from "./parse-openapi.mjs";
@@ -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
+ }