Skip to content

✨ Proposal: Support errorMessage #1725

Description

@ya7010

Describe the inspiration for your proposal

Support "errorMessage" for user custom error messages.

Describe the proposal

Keywords like not, then, and else can cause errors where the explanation depends on the library, but they are generally difficult to understand.

Therefore, we need a field that allows JSON Schema creators to provide more specific error messages.

{
  "type": "integer",
  "minimum": 1,
  "errorMessage": {
    "type": "value must be an integer.",
    "minimum": "value must be greater than or equal to 1."
  }
}

Describe alternatives you've considered

Add message values for each error type. However, this method will increase the number of reserved keywords.

{
  "type": "integer",
  "minimum": 1,
  "typeErrorMessage": "value must be an integer.",
  "minimumErrorMessage": "value must be greater than or equal to 1."
}

Additional context

This shares a similar background to the deprecationMessage I submitted #1716, but this proposal applies to error messages.
To ensure consistency in the specification, we should start considering these needs as well.

Also, this proposal is based on Ajv-errors and is intended to facilitate an easy transition for some users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalInitial discussion of a new idea. A project will be created once a proposal document is created.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions