@usearazzo/parser 1.0.1-alpha.1 → 1.0.1-alpha.2
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 +6 -0
- package/README.md +2 -0
- package/dist/arazzo-parser.browser.js +67 -40
- package/dist/arazzo-parser.browser.min.js +1 -1
- package/package.json +2 -2
- package/src/parse-arazzo.cjs +16 -2
- package/src/parse-arazzo.mjs +16 -2
- package/src/parse-openapi.cjs +14 -2
- package/src/parse-openapi.mjs +15 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
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.1-alpha.2](https://github.com/usearazzo/arazzo-toolkit/compare/v1.0.1-alpha.1...v1.0.1-alpha.2) (2026-09-08)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **parser:** resolve relative file paths against working directory ([#148](https://github.com/usearazzo/arazzo-toolkit/issues/148)) ([41b5b22](https://github.com/usearazzo/arazzo-toolkit/commit/41b5b22ff1940b13b5c6419ac8787c1d722483b2)), closes [#147](https://github.com/usearazzo/arazzo-toolkit/issues/147)
|
|
11
|
+
|
|
6
12
|
## 1.0.1-alpha.1 (2026-09-08)
|
|
7
13
|
|
|
8
14
|
- refactor(validator)!: remove CLI layer and fix URI resolution (#11) ([76f8556](https://github.com/usearazzo/arazzo-toolkit/commit/76f8556bbece403c38dc8f68e020ab359fee563c)), closes [#11](https://github.com/usearazzo/arazzo-toolkit/issues/11)
|
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ The expression and condition parsers are pure syntax parsers: a string in, an AS
|
|
|
37
37
|
|
|
38
38
|
Documents come back as ApiDOM, so source positions for editor tooling, formatting-preserving round trips, and one-call parsing of every source description an Arazzo document points at are all options away.
|
|
39
39
|
|
|
40
|
+
A relative file system path resolves against the current working directory, so `./samples/onboarding.arazzo.yaml` and `path.resolve('samples/onboarding.arazzo.yaml')` are equivalent.
|
|
41
|
+
|
|
40
42
|
## Installation
|
|
41
43
|
|
|
42
44
|
```sh
|
|
@@ -204,9 +204,11 @@ const defaultOptions = {
|
|
|
204
204
|
* The function handles three types of input:
|
|
205
205
|
* 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
|
|
206
206
|
* 2. String content - uses Arazzo detection to identify and parse inline JSON or YAML content
|
|
207
|
-
* 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL
|
|
207
|
+
* 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL.
|
|
208
|
+
* A relative file system path resolves against the current working directory.
|
|
208
209
|
*
|
|
209
|
-
* @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
|
|
210
|
+
* @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL.
|
|
211
|
+
* A relative file system path resolves against the current working directory.
|
|
210
212
|
* @param options - Reference options (uses defaultOptions when not provided)
|
|
211
213
|
* @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
|
|
212
214
|
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
@@ -265,6 +267,18 @@ async function parse(source, options = {}) {
|
|
|
265
267
|
sourceProvenance = '[inline YAML]';
|
|
266
268
|
} else {
|
|
267
269
|
sourceProvenance = _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.isHttpUrl(source) || _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.getProtocol(source) === 'file' || _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.isURI(`file://${source}`) ? source : '[inline CONTENT]';
|
|
270
|
+
|
|
271
|
+
// a relative file system path resolves against the current working directory; the string
|
|
272
|
+
// doubles as the base URI for relative source description URLs, where a relative base
|
|
273
|
+
// resolves against the filesystem root instead of the document. Not gated on the
|
|
274
|
+
// provenance above: isURI(`file://${source}`) rejects a first segment with a space,
|
|
275
|
+
// which is a valid relative path. A leading slash or backslash (UNC, drive-rooted) is
|
|
276
|
+
// already rooted and passes through untouched. RegExp.test coerces a null/undefined
|
|
277
|
+
// passed at runtime despite the string type, deferring to parseURI below for a proper
|
|
278
|
+
// ParseError instead of throwing here.
|
|
279
|
+
if (!_speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.isHttpUrl(source) && _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.getProtocol(source) !== 'file' && !/^[\\/]/.test(source)) {
|
|
280
|
+
source = _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.resolve(_speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.fromFileSystemPath(_speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.cwd()), source);
|
|
281
|
+
}
|
|
268
282
|
}
|
|
269
283
|
|
|
270
284
|
// in-memory documents are served under their synthetic memory:// URI, or under the
|
|
@@ -407,23 +421,24 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
407
421
|
/* harmony export */ parse: () => (/* binding */ parse)
|
|
408
422
|
/* harmony export */ });
|
|
409
423
|
/* harmony import */ var _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(212);
|
|
410
|
-
/* harmony import */ var
|
|
411
|
-
/* harmony import */ var
|
|
412
|
-
/* harmony import */ var
|
|
413
|
-
/* harmony import */ var
|
|
414
|
-
/* harmony import */ var
|
|
415
|
-
/* harmony import */ var
|
|
416
|
-
/* harmony import */ var
|
|
417
|
-
/* harmony import */ var
|
|
418
|
-
/* harmony import */ var
|
|
419
|
-
/* harmony import */ var
|
|
420
|
-
/* harmony import */ var
|
|
421
|
-
/* harmony import */ var
|
|
422
|
-
/* harmony import */ var
|
|
423
|
-
/* harmony import */ var
|
|
424
|
-
/* harmony import */ var
|
|
425
|
-
/* harmony import */ var
|
|
426
|
-
/* harmony import */ var
|
|
424
|
+
/* harmony import */ var _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(30698);
|
|
425
|
+
/* harmony import */ var _speclynx_apidom_reference_parse_parsers_openapi_json_2__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(76680);
|
|
426
|
+
/* harmony import */ var _speclynx_apidom_reference_parse_parsers_openapi_yaml_2__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(41643);
|
|
427
|
+
/* harmony import */ var _speclynx_apidom_reference_parse_parsers_openapi_json_3_0__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(48834);
|
|
428
|
+
/* harmony import */ var _speclynx_apidom_reference_parse_parsers_openapi_yaml_3_0__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(52393);
|
|
429
|
+
/* harmony import */ var _speclynx_apidom_reference_parse_parsers_openapi_json_3_1__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(61275);
|
|
430
|
+
/* harmony import */ var _speclynx_apidom_reference_parse_parsers_openapi_yaml_3_1__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(28208);
|
|
431
|
+
/* harmony import */ var _speclynx_apidom_parser_adapter_openapi_json_3_1__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(10343);
|
|
432
|
+
/* harmony import */ var _speclynx_apidom_parser_adapter_openapi_yaml_3_1__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(43244);
|
|
433
|
+
/* harmony import */ var _speclynx_apidom_parser_adapter_openapi_json_3_0__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(50142);
|
|
434
|
+
/* harmony import */ var _speclynx_apidom_parser_adapter_openapi_yaml_3_0__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(99474);
|
|
435
|
+
/* harmony import */ var _speclynx_apidom_parser_adapter_openapi_json_2__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(64820);
|
|
436
|
+
/* harmony import */ var _speclynx_apidom_parser_adapter_openapi_yaml_2__WEBPACK_IMPORTED_MODULE_13__ = __webpack_require__(71527);
|
|
437
|
+
/* harmony import */ var ramda_adjunct__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(34606);
|
|
438
|
+
/* harmony import */ var _errors_ParseError_ts__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(10425);
|
|
439
|
+
/* harmony import */ var _options_util_ts__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(86547);
|
|
440
|
+
/* harmony import */ var _resolve_resolvers_memory_index_ts__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(30513);
|
|
441
|
+
/* harmony import */ var _parse_arazzo_ts__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(30089);
|
|
427
442
|
|
|
428
443
|
|
|
429
444
|
|
|
@@ -454,25 +469,25 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
454
469
|
*/
|
|
455
470
|
const defaultOptions = {
|
|
456
471
|
parse: {
|
|
457
|
-
parsers: [new
|
|
472
|
+
parsers: [new _speclynx_apidom_reference_parse_parsers_openapi_json_2__WEBPACK_IMPORTED_MODULE_2__["default"]({
|
|
458
473
|
allowEmpty: false
|
|
459
|
-
}), new
|
|
474
|
+
}), new _speclynx_apidom_reference_parse_parsers_openapi_yaml_2__WEBPACK_IMPORTED_MODULE_3__["default"]({
|
|
460
475
|
allowEmpty: false
|
|
461
|
-
}), new
|
|
476
|
+
}), new _speclynx_apidom_reference_parse_parsers_openapi_json_3_0__WEBPACK_IMPORTED_MODULE_4__["default"]({
|
|
462
477
|
allowEmpty: false
|
|
463
|
-
}), new
|
|
478
|
+
}), new _speclynx_apidom_reference_parse_parsers_openapi_yaml_3_0__WEBPACK_IMPORTED_MODULE_5__["default"]({
|
|
464
479
|
allowEmpty: false
|
|
465
|
-
}), new
|
|
480
|
+
}), new _speclynx_apidom_reference_parse_parsers_openapi_json_3_1__WEBPACK_IMPORTED_MODULE_6__["default"]({
|
|
466
481
|
allowEmpty: false
|
|
467
|
-
}), new
|
|
482
|
+
}), new _speclynx_apidom_reference_parse_parsers_openapi_yaml_3_1__WEBPACK_IMPORTED_MODULE_7__["default"]({
|
|
468
483
|
allowEmpty: false
|
|
469
484
|
})],
|
|
470
485
|
parserOpts: {
|
|
471
|
-
...
|
|
486
|
+
..._parse_arazzo_ts__WEBPACK_IMPORTED_MODULE_18__.defaultOptions.parse.parserOpts
|
|
472
487
|
}
|
|
473
488
|
},
|
|
474
489
|
resolve: {
|
|
475
|
-
resolvers: [...
|
|
490
|
+
resolvers: [..._parse_arazzo_ts__WEBPACK_IMPORTED_MODULE_18__.defaultOptions.resolve.resolvers],
|
|
476
491
|
resolverOpts: {}
|
|
477
492
|
}
|
|
478
493
|
};
|
|
@@ -510,9 +525,11 @@ const defaultOptions = {
|
|
|
510
525
|
* The function handles three types of input:
|
|
511
526
|
* 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
|
|
512
527
|
* 2. String content - uses OpenAPI detection to identify and parse inline JSON or YAML content
|
|
513
|
-
* 3. URI string - if not detected as OpenAPI content, treats as file system path or HTTP(S) URL
|
|
528
|
+
* 3. URI string - if not detected as OpenAPI content, treats as file system path or HTTP(S) URL.
|
|
529
|
+
* A relative file system path resolves against the current working directory.
|
|
514
530
|
*
|
|
515
|
-
* @param source - The OpenAPI Document as an object, string content, or a file system path / HTTP(S) URL
|
|
531
|
+
* @param source - The OpenAPI Document as an object, string content, or a file system path / HTTP(S) URL.
|
|
532
|
+
* A relative file system path resolves against the current working directory.
|
|
516
533
|
* @param options - Reference options (uses defaultOptions when not provided)
|
|
517
534
|
* @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
|
|
518
535
|
* @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
|
|
@@ -549,45 +566,45 @@ const defaultOptions = {
|
|
|
549
566
|
* @public
|
|
550
567
|
*/
|
|
551
568
|
async function parse(source, options = {}) {
|
|
552
|
-
let mergedOptions = (0,
|
|
569
|
+
let mergedOptions = (0,_options_util_ts__WEBPACK_IMPORTED_MODULE_16__.mergeOptions)(defaultOptions, options);
|
|
553
570
|
const strict = mergedOptions.parse?.parserOpts?.strict ?? true;
|
|
554
571
|
let sourceProvenance;
|
|
555
572
|
let document;
|
|
556
|
-
if ((0,
|
|
573
|
+
if ((0,ramda_adjunct__WEBPACK_IMPORTED_MODULE_14__["default"])(source)) {
|
|
557
574
|
document = JSON.stringify(source, null, 2);
|
|
558
575
|
source = 'memory://openapi.json';
|
|
559
576
|
sourceProvenance = '[object]';
|
|
560
|
-
} else if (await (0,
|
|
577
|
+
} else if (await (0,_speclynx_apidom_parser_adapter_openapi_json_2__WEBPACK_IMPORTED_MODULE_12__.detect)(source, {
|
|
561
578
|
strict
|
|
562
579
|
})) {
|
|
563
580
|
document = source;
|
|
564
581
|
source = 'memory://openapi.json';
|
|
565
582
|
sourceProvenance = '[inline JSON]';
|
|
566
|
-
} else if (await (0,
|
|
583
|
+
} else if (await (0,_speclynx_apidom_parser_adapter_openapi_yaml_2__WEBPACK_IMPORTED_MODULE_13__.detect)(source, {
|
|
567
584
|
strict
|
|
568
585
|
})) {
|
|
569
586
|
document = source;
|
|
570
587
|
source = 'memory://openapi.yaml';
|
|
571
588
|
sourceProvenance = '[inline YAML]';
|
|
572
|
-
} else if (await (0,
|
|
589
|
+
} else if (await (0,_speclynx_apidom_parser_adapter_openapi_json_3_0__WEBPACK_IMPORTED_MODULE_10__.detect)(source, {
|
|
573
590
|
strict
|
|
574
591
|
})) {
|
|
575
592
|
document = source;
|
|
576
593
|
source = 'memory://openapi.json';
|
|
577
594
|
sourceProvenance = '[inline JSON]';
|
|
578
|
-
} else if (await (0,
|
|
595
|
+
} else if (await (0,_speclynx_apidom_parser_adapter_openapi_yaml_3_0__WEBPACK_IMPORTED_MODULE_11__.detect)(source, {
|
|
579
596
|
strict
|
|
580
597
|
})) {
|
|
581
598
|
document = source;
|
|
582
599
|
source = 'memory://openapi.yaml';
|
|
583
600
|
sourceProvenance = '[inline YAML]';
|
|
584
|
-
} else if (await (0,
|
|
601
|
+
} else if (await (0,_speclynx_apidom_parser_adapter_openapi_json_3_1__WEBPACK_IMPORTED_MODULE_8__.detect)(source, {
|
|
585
602
|
strict
|
|
586
603
|
})) {
|
|
587
604
|
document = source;
|
|
588
605
|
source = 'memory://openapi.json';
|
|
589
606
|
sourceProvenance = '[inline JSON]';
|
|
590
|
-
} else if (await (0,
|
|
607
|
+
} else if (await (0,_speclynx_apidom_parser_adapter_openapi_yaml_3_1__WEBPACK_IMPORTED_MODULE_9__.detect)(source, {
|
|
591
608
|
strict
|
|
592
609
|
})) {
|
|
593
610
|
document = source;
|
|
@@ -595,6 +612,16 @@ async function parse(source, options = {}) {
|
|
|
595
612
|
sourceProvenance = '[inline YAML]';
|
|
596
613
|
} else {
|
|
597
614
|
sourceProvenance = source;
|
|
615
|
+
|
|
616
|
+
// a relative file system path resolves against the current working directory; the string
|
|
617
|
+
// doubles as the base URI for relative references, where a relative base resolves against
|
|
618
|
+
// the filesystem root instead of the document. A leading slash or backslash (UNC,
|
|
619
|
+
// drive-rooted) is already rooted and passes through untouched. RegExp.test coerces a
|
|
620
|
+
// null/undefined passed at runtime despite the string type, deferring to parseURI below
|
|
621
|
+
// for a proper ParseError instead of throwing here.
|
|
622
|
+
if (!_speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.isHttpUrl(source) && _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.getProtocol(source) !== 'file' && !/^[\\/]/.test(source)) {
|
|
623
|
+
source = _speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.resolve(_speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.fromFileSystemPath(_speclynx_apidom_reference_configuration_empty__WEBPACK_IMPORTED_MODULE_1__.cwd()), source);
|
|
624
|
+
}
|
|
598
625
|
}
|
|
599
626
|
|
|
600
627
|
// in-memory documents are served under their synthetic memory:// URI, or under the
|
|
@@ -602,9 +629,9 @@ async function parse(source, options = {}) {
|
|
|
602
629
|
if (document !== undefined) {
|
|
603
630
|
// raw options, not merged: mergeOptions defaults baseURI to the current working directory
|
|
604
631
|
source = options.resolve?.baseURI || source;
|
|
605
|
-
mergedOptions = (0,
|
|
632
|
+
mergedOptions = (0,_options_util_ts__WEBPACK_IMPORTED_MODULE_16__.mergeOptions)(mergedOptions, {
|
|
606
633
|
resolve: {
|
|
607
|
-
resolvers: [...mergedOptions.resolve.resolvers, new
|
|
634
|
+
resolvers: [...mergedOptions.resolve.resolvers, new _resolve_resolvers_memory_index_ts__WEBPACK_IMPORTED_MODULE_17__["default"]({
|
|
608
635
|
document,
|
|
609
636
|
uri: source
|
|
610
637
|
})]
|
|
@@ -622,7 +649,7 @@ async function parse(source, options = {}) {
|
|
|
622
649
|
}
|
|
623
650
|
return parseResult;
|
|
624
651
|
} catch (error) {
|
|
625
|
-
throw new
|
|
652
|
+
throw new _errors_ParseError_ts__WEBPACK_IMPORTED_MODULE_15__["default"](`Failed to parse OpenAPI Document from "${sourceProvenance}"`, {
|
|
626
653
|
cause: error
|
|
627
654
|
});
|
|
628
655
|
}
|