Closed AndrewJo closed 5 years ago
If I am not wrong, at-least one of the values has to match from the given subset right?
Yes as long as it doesn't contain any values that's not in the superset. For example, if you have a rule:
const rule = {
numbers: 'subset:1,2,3,4,5'
}
Matches:
const data = {
numbers: [2, 1, 5]
}
But will throw validation message on:
const data = {
// 6 is not an element in the original array
numbers: [1, 4, 3, 6]
}
It's most useful for matching whether multiple values are in a whitelist (versus in
rule which only validates a single value in a list).
Looks beautiful 😄
Cool! Any news about this feature?
@RomainLanz I just noticed you approved the PR. When can we expect to see this merged in?
Hey @AndrewJo! 👋
I don't have the right to merge this PR. @thetutlage will probably do it when he has time to review it.
Ah, got it. Thank you for the clarification! @RomainLanz
Sorry for getting late. At times, it's hard to look at Github notifications coz of all other work you have in life :)
@thetutlage No worries 😄 I totally understand. I have few open source projects myself that I forget to check sometimes. :wink:
Proposed changes
This PR adds support for adding
subset
validator which is useful for validating theinclude
query string in JSONAPI:Example usage:
Here's a contrived example:
If for example, the query string looks like:
include=author,comments.author
, the validation will pass. If however, the query string looks like:include=invalid-relationship
, the validation will fail.Types of changes
What types of changes does your code introduce?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
@thetutlage I only read the Contributing guidelines only after I finished this implementation and created this PR. I hope it's okay that I didn't create an RFC first as I wasn't aware before submitting this PR.