Skip to content

Name of missing 'required' property. #21

@Aleksandras-Novikovas

Description

@Aleksandras-Novikovas
var schema = {
  type: 'object',
  required: ['foo', 'bar'],
  errorMessage: {
    required: {
      foo: 'missing foo property',
      bar: 'missing bar property'
    }
  }

Processed errors:

[
  {
    keyword: 'errorMessage',
    message: 'missing foo property',
    dataPath: '',
    // ...
  },
  {
    keyword: 'errorMessage',
    message: 'missing bar property',
    dataPath: '',
    // ...
  }
]

It is difficult to know which error message was generated for which property.
It is needed for automatic processing.
Now there are two possible workarounds:

  1. format error message in a special way (include missing property name) and process it afterwards
  2. check param.errors[0].missingProperty - here we have to make sure that param.errors[0].keyword==="required"

Suggestion:
Add name of missing property to dataPath. This is possible only when property specific message is defined.

Another suggestion:
Add option allowing to have separate messages for missing properties (even if single error message is defined for all missing properties). This would allow to have correct dataPath settings for every missing property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions