Currently, I am attempting to validate a request using class-validator to check if it is an array.
The inputs are sourced from query parameters like this: /api/items?someTypes=this
This is what my request dto resembles:
(...)
@IsArray()
@IsEnum(SOMETHING, {each: true})
readonly someTypes: keyof typeof SOMETHING[];
(...)
When only one item is provided, the @IsArray validation returns an error, indicating that it is not an array.
I would like for it to be considered an array even when only one item is received via the query parameter, but I'm unsure of how to achieve this.
I am aware that using /api/items?someTypes[]=this
will pass validation.
However, I am curious if there is an alternative method to address this issue.