Skip to content

Make certain rules override themselves #1127

@dwelle

Description

@dwelle

Context

  • joi version: 10.2.2

What are you trying to achieve or the steps to reproduce ?

Currently, calling e.g. .min() multiple times just accumulates the rules (as it should), but in this case it doesn't make sense.

Suppose I have a library of schemas, and the default for some array is .min(1).. if I want to re-use the schema but override it to allow 0 members, I can't AFAIK.

Joi.array().min(0).min(1)

should IMO override the 0 with 1.

I understand that for some rules it'd be hard to determine what should override what -- particularly when trying to override one rule with a different one (e.g. min(1).allow([])), but I think that it might not be hard to specify a list of rules which override themselves (min, max etc.).

Thoughts?

Metadata

Metadata

Assignees

Labels

breaking changesChange that can breaking existing codefeatureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions