validasaur icon indicating copy to clipboard operation
validasaur copied to clipboard

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

Open Tandashi opened this issue 3 years ago • 0 comments

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

Tandashi avatar Oct 19 '22 17:10 Tandashi