Skip to content

feature: validate array with fixed length #2496

Open
@ndomx-mig

Description

@ndomx-mig

Description

Unlike strings, array fields often contain a fixed number of elements (i.e. consider the case where the coordinates are received as an array of size 2), and I usually have to validate this manually by checking the minimum size and the maximum size simultaneously. Although this issue is easy to overcome, a more direct approach would improve readability and produce cleaner code.

Proposed solution

I propose creating the @ArraySize decorator that validates the array's size against the provided argument

// proposed implementation
class Example {
  @ArraySize(2) // accept only arrays with 2 entries
  coordinates: number[];
}

// same feature with current tools
class Example {
  @ArrayMinSize(2)
  @ArrayMaxSize(2)
  coordinates: number[]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    flag: needs discussionIssues which needs discussion before implementation.type: featureIssues related to new features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions