serby / schemata

Define, create, and validate your business objects based on specified schema.
45 stars 16 forks source link

BREAKING:fix: validate should use all set by default if no specific validator exists #67

Open jack828 opened 3 years ago

jack828 commented 3 years ago

If validators is an array, always run regardless of specified set (because using an array is a shorthand for { all: [...] }) If validators is an object, use the specified set validator, if it doesn't exist, fall back and use the all validator.

Use case:

      firstName: {
        type: String,
        validators: {
          all: [required]
        }
      },
      lastName: {
        type: String,
        validators: [required]
      },
      agency: {
        type: String,
        validators: {
          test: [required]
        }
      },

In schemata's current state, if you validate {} with the test set, it will only fail validation on agency field.

With these changes, it will correctly fail on all fields.

If you need to disable a validator field, you simply:

      agency: {
        type: String,
        validators: {
          all: [],
          test: [required]
        }
      },

Or just omit validators