Skip to content
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

Proposal: Be able to validate top-level arrays as well #38

Open
Tandashi opened this issue Oct 19, 2022 · 0 comments
Open

Proposal: Be able to validate top-level arrays as well #38

Tandashi opened this issue Oct 19, 2022 · 0 comments

Comments

@Tandashi
Copy link

Currently, it is only possible to validate top-level objects using validate().
However, there are some use-cases where validating a single value like an array would be needed handy.

Example:
Imagine you have a RESTful API where you have an Endpoint that updates a Resource. The body for this request looks as follows:

[
  "value 1",
  "value 2",
  // ...
]

What's currently 'possible'
Currently, there is no easy way to validate the body of the request. A workaround would be to use validateValue but then you would need to implement a lot around that yourselves since it returns a InvalidPayload[] rather than a ValidationResult.
validateData is also not useable since it requires the input to be of type InputData which is not compatible with array.

What would be nice to have
To have something like this:

validateTopLevelArray(input: any[], rules: Rule[]): Promise<ValidationResult>

validateTopLevelArray(['value 1', 'value 2'], validateArray([isString]))
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

No branches or pull requests

1 participant