Skip to content

Passing values to validate should output warnings when not part of the schema #2

@iamvanja

Description

@iamvanja

Consider

const schema = new Schema({
  id: Is.numeric().positive().integer().required(),
  name: Is.string().ascii().required()
})

and then validating

schema.validate({
  id: 123,
  name: 'John',
  email: 'not.an.email'
})

This validation returns no errors. Which it should not since email is not defined in the schema and by that virtue, email is an optional, free-text value, but I think there are real-time situations where rules could be forgotten to be passed into the schema with potentially serious consequences. This also applies for schema.clone.

Shouldn't validate in this case output a warning about email not being part of the schema?

Perhaps new Schema, schema.clone and/or validate method could take an optional second argument as a configuration object where the option for this would be something like suppressWarnings: false?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions