@usearazzo/parser 1.0.1-alpha.1 → 1.0.1-alpha.3

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": "@usearazzo/parser",
3
- "version": "1.0.1-alpha.1",
3
+ "version": "1.0.1-alpha.3",
4
4
  "description": "Parser for the Arazzo Specification language: documents, runtime expressions, and criterion conditions.",
5
5
  "keywords": [
6
6
  "arazzo",
@@ -52,26 +52,26 @@
52
52
  "author": "Vladimir Gorej <vladimir.gorej@gmail.com>",
53
53
  "license": "Apache-2.0",
54
54
  "dependencies": {
55
- "@babel/runtime-corejs3": "^8.0.0",
56
- "@speclynx/apidom-datamodel": "^5.2.2",
57
- "@speclynx/apidom-error": "^5.2.2",
58
- "@speclynx/apidom-ns-arazzo-1": "^5.2.2",
59
- "@speclynx/apidom-parser-adapter-arazzo-json-1": "^5.2.2",
60
- "@speclynx/apidom-parser-adapter-arazzo-yaml-1": "^5.2.2",
61
- "@speclynx/apidom-parser-adapter-openapi-json-2": "^5.2.2",
62
- "@speclynx/apidom-parser-adapter-openapi-json-3-0": "^5.2.2",
63
- "@speclynx/apidom-parser-adapter-openapi-json-3-1": "^5.2.2",
64
- "@speclynx/apidom-parser-adapter-openapi-yaml-2": "^5.2.2",
65
- "@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "^5.2.2",
66
- "@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "^5.2.2",
67
- "@speclynx/apidom-reference": "^5.2.2",
55
+ "@babel/runtime-corejs3": "^8.0.5",
56
+ "@speclynx/apidom-datamodel": "^5.2.6",
57
+ "@speclynx/apidom-error": "^5.2.6",
58
+ "@speclynx/apidom-ns-arazzo-1": "^5.2.6",
59
+ "@speclynx/apidom-parser-adapter-arazzo-json-1": "^5.2.6",
60
+ "@speclynx/apidom-parser-adapter-arazzo-yaml-1": "^5.2.6",
61
+ "@speclynx/apidom-parser-adapter-openapi-json-2": "^5.2.6",
62
+ "@speclynx/apidom-parser-adapter-openapi-json-3-0": "^5.2.6",
63
+ "@speclynx/apidom-parser-adapter-openapi-json-3-1": "^5.2.6",
64
+ "@speclynx/apidom-parser-adapter-openapi-yaml-2": "^5.2.6",
65
+ "@speclynx/apidom-parser-adapter-openapi-yaml-3-0": "^5.2.6",
66
+ "@speclynx/apidom-parser-adapter-openapi-yaml-3-1": "^5.2.6",
67
+ "@speclynx/apidom-reference": "^5.2.6",
68
68
  "@swaggerexpert/arazzo-criterion": "^1.0.1",
69
69
  "@swaggerexpert/arazzo-runtime-expression": "^3.2.0",
70
70
  "ramda-adjunct": "^6.0.0",
71
71
  "type-fest": "^5.4.4"
72
72
  },
73
73
  "devDependencies": {
74
- "@speclynx/apidom-core": "^5.2.2"
74
+ "@speclynx/apidom-core": "^5.2.6"
75
75
  },
76
76
  "files": [
77
77
  "src/**/*.mjs",
@@ -83,5 +83,5 @@
83
83
  "README.md",
84
84
  "CHANGELOG.md"
85
85
  ],
86
- "gitHead": "fcbec52d36dee98bdf11fa6a96c9f3a5c39811b1"
86
+ "gitHead": "a2e566eb717faeba184c4c41f7b65a7c508bad7c"
87
87
  }
@@ -108,9 +108,11 @@ const defaultOptions = exports.defaultOptions = {
108
108
  * The function handles three types of input:
109
109
  * 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
110
110
  * 2. String content - uses Arazzo detection to identify and parse inline JSON or YAML content
111
- * 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL
111
+ * 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL.
112
+ * A relative file system path resolves against the current working directory.
112
113
  *
113
- * @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
114
+ * @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL.
115
+ * A relative file system path resolves against the current working directory.
114
116
  * @param options - Reference options (uses defaultOptions when not provided)
115
117
  * @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
116
118
  * @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
@@ -169,6 +171,18 @@ async function parse(source, options = {}) {
169
171
  sourceProvenance = '[inline YAML]';
170
172
  } else {
171
173
  sourceProvenance = _empty.url.isHttpUrl(source) || _empty.url.getProtocol(source) === 'file' || _empty.url.isURI(`file://${source}`) ? source : '[inline CONTENT]';
174
+
175
+ // a relative file system path resolves against the current working directory; the string
176
+ // doubles as the base URI for relative source description URLs, where a relative base
177
+ // resolves against the filesystem root instead of the document. Not gated on the
178
+ // provenance above: isURI(`file://${source}`) rejects a first segment with a space,
179
+ // which is a valid relative path. A leading slash or backslash (UNC, drive-rooted) is
180
+ // already rooted and passes through untouched. RegExp.test coerces a null/undefined
181
+ // passed at runtime despite the string type, deferring to parseURI below for a proper
182
+ // ParseError instead of throwing here.
183
+ if (!_empty.url.isHttpUrl(source) && _empty.url.getProtocol(source) !== 'file' && !/^[\\/]/.test(source)) {
184
+ source = _empty.url.resolve(_empty.url.fromFileSystemPath(_empty.url.cwd()), source);
185
+ }
172
186
  }
173
187
 
174
188
  // in-memory documents are served under their synthetic memory:// URI, or under the
@@ -99,9 +99,11 @@ export const defaultOptions = {
99
99
  * The function handles three types of input:
100
100
  * 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
101
101
  * 2. String content - uses Arazzo detection to identify and parse inline JSON or YAML content
102
- * 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL
102
+ * 3. URI string - if not detected as Arazzo content, treats as file system path or HTTP(S) URL.
103
+ * A relative file system path resolves against the current working directory.
103
104
  *
104
- * @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL
105
+ * @param source - The Arazzo Document as an object, string content, or a file system path / HTTP(S) URL.
106
+ * A relative file system path resolves against the current working directory.
105
107
  * @param options - Reference options (uses defaultOptions when not provided)
106
108
  * @returns A promise that resolves to the parsed Arazzo Document as ApiDOM data model
107
109
  * @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
@@ -160,6 +162,18 @@ export async function parse(source, options = {}) {
160
162
  sourceProvenance = '[inline YAML]';
161
163
  } else {
162
164
  sourceProvenance = url.isHttpUrl(source) || url.getProtocol(source) === 'file' || url.isURI(`file://${source}`) ? source : '[inline CONTENT]';
165
+
166
+ // a relative file system path resolves against the current working directory; the string
167
+ // doubles as the base URI for relative source description URLs, where a relative base
168
+ // resolves against the filesystem root instead of the document. Not gated on the
169
+ // provenance above: isURI(`file://${source}`) rejects a first segment with a space,
170
+ // which is a valid relative path. A leading slash or backslash (UNC, drive-rooted) is
171
+ // already rooted and passes through untouched. RegExp.test coerces a null/undefined
172
+ // passed at runtime despite the string type, deferring to parseURI below for a proper
173
+ // ParseError instead of throwing here.
174
+ if (!url.isHttpUrl(source) && url.getProtocol(source) !== 'file' && !/^[\\/]/.test(source)) {
175
+ source = url.resolve(url.fromFileSystemPath(url.cwd()), source);
176
+ }
163
177
  }
164
178
 
165
179
  // in-memory documents are served under their synthetic memory:// URI, or under the
@@ -91,9 +91,11 @@ const defaultOptions = exports.defaultOptions = {
91
91
  * The function handles three types of input:
92
92
  * 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
93
93
  * 2. String content - uses OpenAPI detection to identify and parse inline JSON or YAML content
94
- * 3. URI string - if not detected as OpenAPI content, treats as file system path or HTTP(S) URL
94
+ * 3. URI string - if not detected as OpenAPI content, treats as file system path or HTTP(S) URL.
95
+ * A relative file system path resolves against the current working directory.
95
96
  *
96
- * @param source - The OpenAPI Document as an object, string content, or a file system path / HTTP(S) URL
97
+ * @param source - The OpenAPI Document as an object, string content, or a file system path / HTTP(S) URL.
98
+ * A relative file system path resolves against the current working directory.
97
99
  * @param options - Reference options (uses defaultOptions when not provided)
98
100
  * @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
99
101
  * @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
@@ -176,6 +178,16 @@ async function parse(source, options = {}) {
176
178
  sourceProvenance = '[inline YAML]';
177
179
  } else {
178
180
  sourceProvenance = source;
181
+
182
+ // a relative file system path resolves against the current working directory; the string
183
+ // doubles as the base URI for relative references, where a relative base resolves against
184
+ // the filesystem root instead of the document. A leading slash or backslash (UNC,
185
+ // drive-rooted) is already rooted and passes through untouched. RegExp.test coerces a
186
+ // null/undefined passed at runtime despite the string type, deferring to parseURI below
187
+ // for a proper ParseError instead of throwing here.
188
+ if (!_empty.url.isHttpUrl(source) && _empty.url.getProtocol(source) !== 'file' && !/^[\\/]/.test(source)) {
189
+ source = _empty.url.resolve(_empty.url.fromFileSystemPath(_empty.url.cwd()), source);
190
+ }
179
191
  }
180
192
 
181
193
  // in-memory documents are served under their synthetic memory:// URI, or under the
@@ -1,4 +1,4 @@
1
- import { parse as parseURI } from '@speclynx/apidom-reference/configuration/empty';
1
+ import { url, parse as parseURI } from '@speclynx/apidom-reference/configuration/empty';
2
2
  import OpenApiJSON2Parser from '@speclynx/apidom-reference/parse/parsers/openapi-json-2';
3
3
  import OpenApiYAML2Parser from '@speclynx/apidom-reference/parse/parsers/openapi-yaml-2';
4
4
  import OpenApiJSON3_0Parser from '@speclynx/apidom-reference/parse/parsers/openapi-json-3-0';
@@ -82,9 +82,11 @@ export const defaultOptions = {
82
82
  * The function handles three types of input:
83
83
  * 1. Object - converts to JSON string and parses (source maps supported with `strict: false`)
84
84
  * 2. String content - uses OpenAPI detection to identify and parse inline JSON or YAML content
85
- * 3. URI string - if not detected as OpenAPI content, treats as file system path or HTTP(S) URL
85
+ * 3. URI string - if not detected as OpenAPI content, treats as file system path or HTTP(S) URL.
86
+ * A relative file system path resolves against the current working directory.
86
87
  *
87
- * @param source - The OpenAPI Document as an object, string content, or a file system path / HTTP(S) URL
88
+ * @param source - The OpenAPI Document as an object, string content, or a file system path / HTTP(S) URL.
89
+ * A relative file system path resolves against the current working directory.
88
90
  * @param options - Reference options (uses defaultOptions when not provided)
89
91
  * @returns A promise that resolves to the parsed OpenAPI Document as ApiDOM data model
90
92
  * @throws ParseError - When parsing fails for any reason. The original error is available via the `cause` property.
@@ -167,6 +169,16 @@ export async function parse(source, options = {}) {
167
169
  sourceProvenance = '[inline YAML]';
168
170
  } else {
169
171
  sourceProvenance = source;
172
+
173
+ // a relative file system path resolves against the current working directory; the string
174
+ // doubles as the base URI for relative references, where a relative base resolves against
175
+ // the filesystem root instead of the document. A leading slash or backslash (UNC,
176
+ // drive-rooted) is already rooted and passes through untouched. RegExp.test coerces a
177
+ // null/undefined passed at runtime despite the string type, deferring to parseURI below
178
+ // for a proper ParseError instead of throwing here.
179
+ if (!url.isHttpUrl(source) && url.getProtocol(source) !== 'file' && !/^[\\/]/.test(source)) {
180
+ source = url.resolve(url.fromFileSystemPath(url.cwd()), source);
181
+ }
170
182
  }
171
183
 
172
184
  // in-memory documents are served under their synthetic memory:// URI, or under the