-
Notifications
You must be signed in to change notification settings - Fork 223
fix: migrate to js-yaml v5 #2908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f1f35c8
1fdd598
d66efec
76e9c7e
9deaa81
a35a1fc
5f7d2b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| '@redocly/openapi-core': patch | ||
| '@redocly/cli': patch | ||
| --- | ||
|
|
||
| Updated js-yaml from `4.2.0` to `5.2.1`. | ||
| Fixed an issue where strings that look like numbers with underscores (for example `'12_34'`) had quotation marks removed by the `bundle` command. | ||
| These strings stay quoted in the output. | ||
|
|
||
| **Note**: YAML parsing is stricter: a multi-line flow collection whose closing bracket is not indented deeper than its parent key is now a parse error. | ||
| Parse errors are reported at the offending token instead of the end of the document. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,34 @@ | ||
| // TODO: add a type for "types" https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/js-yaml/index.d.ts | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| import { JSON_SCHEMA, types, load, dump, type LoadOptions, type DumpOptions } from 'js-yaml'; | ||
| import { | ||
| CORE_SCHEMA, | ||
| mergeTag, | ||
| binaryTag, | ||
| omapTag, | ||
| pairsTag, | ||
| setTag, | ||
| loadAll, | ||
| dump, | ||
| YAMLException, | ||
| type LoadOptions, | ||
| type DumpOptions, | ||
| } from 'js-yaml'; | ||
|
|
||
| const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = JSON_SCHEMA.extend({ | ||
| implicit: [types.merge], | ||
| explicit: [types.binary, types.omap, types.pairs, types.set], | ||
| }); | ||
| const DEFAULT_SCHEMA_WITHOUT_TIMESTAMP = CORE_SCHEMA.withTags( | ||
| mergeTag, | ||
| binaryTag, | ||
| omapTag, | ||
| pairsTag, | ||
| setTag | ||
| ); | ||
|
|
||
| export const parseYaml = (str: string, opts?: LoadOptions): unknown => | ||
| load(str, { schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP, ...opts }); | ||
| export const parseYaml = (str: string, opts?: LoadOptions): unknown => { | ||
| const documents = loadAll(str, { schema: DEFAULT_SCHEMA_WITHOUT_TIMESTAMP, ...opts }); | ||
| if (documents.length === 0) { | ||
| return str.trim() === '' ? undefined : null; | ||
| } | ||
| if (documents.length > 1) { | ||
| throw new YAMLException('expected a single document in the stream, but found more'); | ||
| } | ||
| return documents[0]; | ||
| }; | ||
|
|
||
| export const stringifyYaml = (obj: any, opts?: DumpOptions): string => dump(obj, opts); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,12 +85,12 @@ describe('oas3 boolean-parameter-prefixes', () => { | |
| "reportOnKey": false, | ||
| "source": "fixtures/invalid-yaml.yaml", | ||
| "start": { | ||
| "col": 1, | ||
| "line": 2, | ||
| "col": 8, | ||
| "line": 1, | ||
| }, | ||
| }, | ||
| ], | ||
| "message": "Failed to parse: unexpected end of the stream within a single quoted scalar in "fixtures/invalid-yaml.yaml" (2:1)", | ||
| "message": "Failed to parse: unexpected end of the stream within a single quoted scalar in "fixtures/invalid-yaml.yaml" (1:8)", | ||
| "ruleId": "no-unresolved-refs", | ||
| "severity": "error", | ||
| "suggest": [], | ||
|
|
@@ -103,7 +103,7 @@ describe('oas3 boolean-parameter-prefixes', () => { | |
| "source": "foobar.yaml", | ||
| }, | ||
| ], | ||
| "message": "Can't resolve $ref: unexpected end of the stream within a single quoted scalar in "fixtures/invalid-yaml.yaml" (2:1)", | ||
| "message": "Can't resolve $ref: unexpected end of the stream within a single quoted scalar in "fixtures/invalid-yaml.yaml" (1:8)", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please test this in the VSCE.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vadyvas please take a look. |
||
| "reference": "https://redocly.com/docs/cli/rules/oas/no-unresolved-refs", | ||
| "ruleId": "no-unresolved-refs", | ||
| "severity": "error", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,3 +37,5 @@ paths: | |
| object: | ||
| key1: 1 | ||
| key2: 2 | ||
| underscoreNumberTransformedToString: 12_34 | ||
| underscoreNumberString: '12_34' | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multi-doc YAML loses error location
Low Severity
When
parseYamlsees more than one YAML document, it throws a hand-writtenYAMLExceptionwithout a(line:col)suffix.YamlParseErrorparses location from that suffix, so unresolved-ref and parse diagnostics for multi-document streams getNaNline/column instead of pointing at the extra---separator.Reviewed by Cursor Bugbot for commit e4aecb4. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a regression:
js-yamlv4 load() threw the same exceptionper the oas/AsyncAPI specs a description is a single document