Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 1c4b145

Browse files
committed
fix(oas3): handle unknown YAML tags
1 parent ab08f52 commit 1c4b145

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

packages/openapi3-parser/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
type: object
2323
```
2424
25+
- Prevents the parser from throwing an error upon encountering an unknown or
26+
invalid YAML node tag, such as `!!unknown`.
27+
2528
## 0.13.1 (2020-06-22)
2629

2730
### Bug Fixes

packages/openapi3-parser/lib/parser/parseYAML.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,11 @@ function convert(node, annotations, context) {
9090
copySourceMap(node.start_mark, node.end_mark, warning, namespace);
9191
annotations.push(warning);
9292
} else {
93-
throw new Error(`Unsupported YAML node '${node.tag}'`);
93+
const error = new namespace.elements.Annotation(`YAML Syntax: Unsupported YAML node ${node.tag}`, { classes: ['error'] });
94+
copySourceMap(node.start_mark, node.end_mark, error, namespace);
95+
annotations.push(error);
96+
97+
element = new namespace.elements.Null();
9498
}
9599

96100
copySourceMap(node.start_mark, node.end_mark, element, namespace);

packages/openapi3-parser/test/unit/parser/parseYAML-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ describe('#parseYAML', () => {
3232
expect(parseResult).contain.error('YAML Syntax: found character \\t that cannot start any token, while scanning for the next token').with.sourceMap([[14, 0]]);
3333
});
3434

35+
it('fails to parse YAML document with unknown tags', () => {
36+
const parseResult = parseYAML('!!unknown\n', context);
37+
38+
expect(parseResult).to.be.instanceof(namespace.elements.ParseResult);
39+
expect(parseResult.errors.length).to.equal(1);
40+
41+
expect(parseResult).contain.error('YAML Syntax: Unsupported YAML node tag:yaml.org,2002:unknown').with.sourceMap([[0, 9]]);
42+
});
43+
3544
it('can handle internal YAML parser error', () => {
3645
// Protection against YAML parser bug where source map information isn't available
3746
// Particular case: https://github.com/connec/yaml-js/issues/46

0 commit comments

Comments
 (0)