ajv-validator/ajv-errors

How to set a global error message for required fields in all subschemas

ruscoder opened this issue · 0 comments

Hello, thanks for the library!

My schema looks like:

{
    if: {
        properties: {
            fieldType: {
                const: 'field1',
            },
        },
        required: ['fieldType'],
    },
    then: {
        $ref: '#/definitions/customDefinition',
        required: ['field1'],
        errorMessage: {
            required: 'Required',
        },
    },
    else: {
        $ref: '#/definitions/customDefinition',
        required: ['field2'],
        errorMessage: {
            required: 'Required',
        },
    },
    definitions: {
        customDefinition: {
            type: 'object',
            properties: { date: { format: 'date' } },
            required: ['date'],
            errorMessage: {
                properties: { date: 'Custom error message' },
                required: 'Required',
            },
        },
    },
    errorMessage: {
        required: 'Required',
    },
};

Now I need to copy-paste

    errorMessage: {
        required: 'Required',
    },

in each subschema.

Is there an ability to set a global error message for required fields?