whefter / nestjs-joi

Easy to use JoiPipe as an interface between joi and NestJS with optional decorator-based schema construction.
MIT License
25 stars 12 forks source link

How can i define 'or' when working with DTO object #18

Closed liorzmetis closed 2 years ago

liorzmetis commented 2 years ago

I would like to define 'or' when using DTO classes

image

vs

image
whefter commented 2 years ago

Thank you, that appears to be something that is not easily done yet. One possible implementation would be to add a customizer function argument to @JoiSchemaOption(), similar to the way it works on @JoiSchema(). That function would allow arbitrary customizations of the constructed object schema.

e.g.

@JoiSchemaOptions({}, (schema) => schema.or('prop1', 'prop2')

Would that cover your case?

whefter commented 2 years ago

Another way to do it would be a separate decorator, e.g.

@JoiSchemaCustomizer((schema) => schema.or('prop1', 'prop2'))

That would avoid mixing different concerns. I am leaning towards that one.

whefter commented 2 years ago

Added in new v1.8.0.