@jentic/arazzo-parser 1.0.0-alpha.20 → 1.0.0-alpha.22

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.20",
3
+ "version": "1.0.0-alpha.22",
4
4
  "description": "Parser for Arazzo Documents producing SpecLynx ApiDOM data model.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -48,22 +48,24 @@
48
48
  "license": "Apache-2.0",
49
49
  "dependencies": {
50
50
  "@babel/runtime-corejs3": "^7.28.4",
51
- "@speclynx/apidom-core": "^2.12.2",
52
- "@speclynx/apidom-datamodel": "^2.12.2",
53
- "@speclynx/apidom-error": "^2.12.2",
54
- "@speclynx/apidom-ns-arazzo-1": "^2.12.2",
55
- "@speclynx/apidom-parser-adapter-arazzo-json-1": "^2.12.2",
56
- "@speclynx/apidom-parser-adapter-arazzo-yaml-1": "^2.12.2",
57
- "@speclynx/apidom-parser-adapter-openapi-json-2": "^2.12.2",
58
- "@speclynx/apidom-parser-adapter-openapi-json-3-0": "^2.12.2",
59
- "@speclynx/apidom-parser-adapter-openapi-json-3-1": "^2.12.2",
60
- "@speclynx/apidom-parser-adapter-openapi-yaml-2": "^2.12.2",
61
- "@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "^2.12.2",
62
- "@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "^2.12.2",
63
- "@speclynx/apidom-reference": "^2.12.2",
51
+ "@speclynx/apidom-datamodel": "^3.2.1",
52
+ "@speclynx/apidom-error": "^3.2.1",
53
+ "@speclynx/apidom-ns-arazzo-1": "^3.2.1",
54
+ "@speclynx/apidom-parser-adapter-arazzo-json-1": "^3.2.1",
55
+ "@speclynx/apidom-parser-adapter-arazzo-yaml-1": "^3.2.1",
56
+ "@speclynx/apidom-parser-adapter-openapi-json-2": "^3.2.1",
57
+ "@speclynx/apidom-parser-adapter-openapi-json-3-0": "^3.2.1",
58
+ "@speclynx/apidom-parser-adapter-openapi-json-3-1": "^3.2.1",
59
+ "@speclynx/apidom-parser-adapter-openapi-yaml-2": "^3.2.1",
60
+ "@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "^3.2.1",
61
+ "@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "^3.2.1",
62
+ "@speclynx/apidom-reference": "^3.2.1",
64
63
  "ramda-adjunct": "^6.0.0",
65
64
  "type-fest": "^5.4.3"
66
65
  },
66
+ "devDependencies": {
67
+ "@speclynx/apidom-core": "^3.2.1"
68
+ },
67
69
  "files": [
68
70
  "src/**/*.mjs",
69
71
  "src/**/*.cjs",
@@ -74,5 +76,5 @@
74
76
  "README.md",
75
77
  "CHANGELOG.md"
76
78
  ],
77
- "gitHead": "64f8b4b3109900b622fa7f378e58659a43ab57d8"
79
+ "gitHead": "9f03b72cf574d1e18d83fa85051e2d0e41929491"
78
80
  }
@@ -1,11 +0,0 @@
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;
@@ -1,7 +0,0 @@
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 DELETED
@@ -1,10 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- export { parse as parseArazzo, defaultOptions as defaultArazzoOptions } from "./parse-arazzo.mjs";
2
- export { parse as parseOpenAPI, defaultOptions as defaultOpenAPIOptions } from "./parse-openapi.mjs";
@@ -1,195 +0,0 @@
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
- }
@@ -1,188 +0,0 @@
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: 5000,
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
- *
85
- * The function handles three types of input:
86
- * 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
87
- * 2. String content - uses Arazzo detection to identify and parse inline JSON or YAML content
88
- * 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL
89
- *
90
- * @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
91
- * @param options - Reference options (uses defaultOptions when not provided)
92
- * @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
93
- * @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
94
- *
95
- * @example
96
- * Parse from object
97
- * ```typescript
98
- * const result = await parseArazzo({ arazzo: '1.0.1', info: {...} });
99
- * ```
100
- *
101
- * @example
102
- * Parse inline JSON
103
- * ```typescript
104
- * const result = await parseArazzo('{"arazzo": "1.0.1", "info": {...}}');
105
- * ```
106
- *
107
- * @example
108
- * Parse from file
109
- * ```typescript
110
- * const result = await parseArazzo('/path/to/arazzo.json');
111
- * ```
112
- *
113
- * @example
114
- * Parse from URL
115
- * ```typescript
116
- * const result = await parseArazzo('https://example.com/arazzo.yaml');
117
- * ```
118
- *
119
- * @example
120
- * Parse with custom options
121
- * ```typescript
122
- * const result = await parseArazzo('/path/to/arazzo.json', customOptions);
123
- * ```
124
- * @public
125
- */
126
- export async function parse(source, options = {}) {
127
- let mergedOptions = mergeOptions(defaultOptions, options);
128
- const strict = mergedOptions.parse?.parserOpts?.strict ?? true;
129
- let sourceProvenance;
130
- if (isPlainObject(source)) {
131
- const document = JSON.stringify(source, null, 2);
132
- mergedOptions = mergeOptions(mergedOptions, {
133
- resolve: {
134
- resolverOpts: {
135
- document
136
- }
137
- }
138
- });
139
- source = 'memory://arazzo.json';
140
- sourceProvenance = '[object]';
141
- } else if (await detectArazzoJSON(source, {
142
- strict
143
- })) {
144
- mergedOptions = mergeOptions(mergedOptions, {
145
- resolve: {
146
- resolverOpts: {
147
- document: source
148
- }
149
- }
150
- });
151
- source = 'memory://arazzo.json';
152
- sourceProvenance = '[inline JSON]';
153
- } else if (await detectArazzoYAML(source, {
154
- strict
155
- })) {
156
- mergedOptions = mergeOptions(mergedOptions, {
157
- resolve: {
158
- resolverOpts: {
159
- document: source
160
- }
161
- }
162
- });
163
- source = 'memory://arazzo.yaml';
164
- sourceProvenance = '[inline YAML]';
165
- } else {
166
- sourceProvenance = source;
167
- }
168
-
169
- // next we assume that source is either file system URI or HTTP(S) URL
170
- try {
171
- const parseResult = await parseURI(source, mergedOptions);
172
-
173
- // set retrievalURI metadata for file/URL sources (not for inline content)
174
- if (!source.startsWith('memory://')) {
175
- parseResult.meta.set('retrievalURI', source);
176
- }
177
-
178
- // validate that the parsed document is an Arazzo specification
179
- if (!isArazzoSpecification1Element(parseResult.api)) {
180
- throw new UnmatchedParserError(`Could not find a parser that can parse "${sourceProvenance}" as an Arazzo specification`);
181
- }
182
- return parseResult;
183
- } catch (error) {
184
- throw new ParseError(`Failed to parse Arazzo Document from "${sourceProvenance}"`, {
185
- cause: error
186
- });
187
- }
188
- }