Skip to content

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

Merged
merged 1 commit into from
Apr 27, 2021
Merged

added support to additionalItems property in array object #322

merged 1 commit into from
Apr 27, 2021

Conversation

KiraPC
Copy link
Contributor

@KiraPC KiraPC commented Apr 26, 2021

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


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.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@zekth zekth left a 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))
Copy link
Member

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]}

Copy link
Member

@climba03003 climba03003 Apr 27, 2021

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification.

Copy link
Contributor Author

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 :)

Copy link
Member

@zekth zekth left a 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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification.

Copy link
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@mcollina mcollina merged commit 4ddffe5 into fastify:master Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants