-
-
Notifications
You must be signed in to change notification settings - Fork 209
added support to additionalItems property in array object #322
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
Conversation
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.
lgtm
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.
I feel the test assertion is wrong or am i missing something?
}) | ||
t.fail() | ||
} catch (error) { | ||
t.ok(/does not match schema definition./.test(error.message)) |
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.
This matches the definition. Should fail if it was {foo:['foo','bar',1]}
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.
This case should pass.
Reference: https://json-schema.org/understanding-json-schema/reference/array.html
The additionalItems
keyword controls whether it’s valid to have additional items in the array beyond what is defined in items
.
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.
@zekth The case pass because additionItems is 'false', and so the schema expect that the array foo should has just one string item.
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.
Missed this line. Thanks for clarify.
Tuple validation is useful when the array is a collection of items where each has a different schema and the ordinal index of each item is meaningful.
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.
@zekth Do you still need some changes?
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.
Thanks for the clarification.
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.
It's a must. I want to contribute, but I don't want you lose much time to understand what I did.
I'll try to be more clear in PR description next time :)
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.
LGTM.
Thanks for clarifying the test case
}) | ||
t.fail() | ||
} catch (error) { | ||
t.ok(/does not match schema definition./.test(error.message)) |
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.
Thanks for the clarification.
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.
LGTM.
It is the first time I saw the code of this lib, I am amazed by the idea and its implementation.
So many compliments!
Checklist
npm run test
andnpm run benchmark
and the Code of conduct
The PR is intended to fix the issue #321
Brief explanation: when the 'items' property of an array object is described as array itself, only the schemas defined are admitted. However, with the property 'additionalItems' defined in the array definition, it should accept more, without validating the type.