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

feature: validate array with fixed length #2496

Open
ndomx-mig opened this issue Jun 26, 2024 · 0 comments
Open

feature: validate array with fixed length #2496

ndomx-mig opened this issue Jun 26, 2024 · 0 comments
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.

Comments

@ndomx-mig
Copy link

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[]
}
@ndomx-mig ndomx-mig added flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features. labels Jun 26, 2024
@lou2013 lou2013 mentioned this issue Aug 3, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flag: needs discussion Issues which needs discussion before implementation. type: feature Issues related to new features.
Development

No branches or pull requests

1 participant