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

Commit

Permalink
fix(oas3): prevent throwing during freeze for required annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Jun 23, 2020
1 parent 47223e4 commit 6824791
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/openapi3-parser/lib/parser/parseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const hasMember = R.curry((object, key) => {
const validateObjectContainsRequiredKeys = R.curry((namespace, path, requiredKeys, sendWarning, object) => {
const missingKeys = R.reject(hasMember(object), requiredKeys);
const createAnnotation = sendWarning ? createWarning : createError;
const annotationFromKey = key => createAnnotation(namespace, `'${path}' is missing required property '${key}'`, object);
const annotationFromKey = key => createAnnotation(namespace, `'${path}' is missing required property '${key}'`, object.clone());

if (missingKeys.length > 0) {
return new namespace.elements.ParseResult(
Expand Down
10 changes: 10 additions & 0 deletions packages/openapi3-parser/test/unit/parser/parseObject-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ describe('#parseObject', () => {
name: 'Doe',
message: 'Hello',
});
object.attributes.set('sourceMap', [
new namespace.elements.SourceMap([[0, 10]]),
]);
});

it('provides warning when given element is non-object', () => {
Expand Down Expand Up @@ -141,6 +144,13 @@ describe('#parseObject', () => {
"'Example Object' is missing required property 'required1'",
"'Example Object' is missing required property 'required2'",
]);

// assert errors can be frozen (we're testing that the source map
// for object was cloned instead of referenced)
parseResult.freeze();

expect(parseResult.errors.get(0)).to.have.sourceMap([[0, 10]]);
expect(parseResult.errors.get(1)).to.have.sourceMap([[0, 10]]);
});

it('fails object parsing when member parse cannot parse required key', () => {
Expand Down

0 comments on commit 6824791

Please sign in to comment.