xeipuuv / gojsonschema

An implementation of JSON Schema, draft v4 v6 & v7 - Go language
2.56k stars 358 forks source link

Support `errorMessage` so as to customise validation errors #371

Open jobinkavalam opened 11 months ago

jobinkavalam commented 11 months ago

Currently, the following schema definition,

        {
          "type": "string",
          "pattern": "^\\d+$"
        }

is expected to give errors such as:

Does not match pattern '^\d+$'

Clearly, in the given context a more friendlier message can be used.

Implementations such as ajv support this feature through the errorMessage field, i.e.

        {
          "type": "string",
          "pattern": "^\\d+$",
          "errorMessage": "should be a number"
        }

It will be great to have gojsonschema support that.

Also really appreciate if there is a better alternative to achieve this in gojsonschema.