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 request: @Optional decorator #48

Open
koldoon opened this issue Oct 17, 2024 · 2 comments
Open

Feature request: @Optional decorator #48

koldoon opened this issue Oct 17, 2024 · 2 comments

Comments

@koldoon
Copy link

koldoon commented Oct 17, 2024

@optional decorator would be a great addition to collection, instead of property like at the moment

@AmauryD
Copy link
Owner

AmauryD commented Oct 17, 2024

Hello, do you mean something like this ?

@Schema()
class Entity2 {
  @UUID()
  prop1: string;

  @Enum({ values: ["one", "two"] })
  prop2: "one" | "two";

  @Email()
  @Optional()
  prop3: string;

  @Number({ positive: true })
  @Optional()
  prop4: number;

  @Nested()
  prop5: Entity1;
}

@koldoon
Copy link
Author

koldoon commented Oct 17, 2024

@AmauryD Yepp, exactly. This is especially useful with implicit "multi" rule, where it is not very clear how to define the whole property optional (I personally apply {optional:true} to each validator decorator just in case):

export class ActionParams {
  @String({ optional: true })
  @Array({ optional: true, items: 'string' })
  code?: string | string[];
}

Better would be:

export class ActionParams {
  @Optional()
  @String()
  @Array({ items: 'string' })
  code?: string | string[];
}

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

2 participants