UNPKG

ajv-i18n

Version:

Internationalised error messages for Ajv JSON validator

57 lines (56 loc) 1.6 kB
"use strict" module.exports = function localize_en(errors) { if (!(errors && errors.length)) return for (const e of errors) { let out switch (e.keyword) { case "discriminator": switch (e.params.error) { case "tag": out = 'tag "' + e.params.tag + '" must be string' break case "mapping": out = 'value of tag "' + e.params.tag + '" must be in mapping' break default: out = "" var t = e.params.type var n = e.params.nullable ? "/null" : "" out += "must be " + (t + n) } break case "enum": out = "must be equal to one of the allowed values" break case "properties": switch (e.params.error) { case "additional": out = "must NOT have additional properties" break case "missing": out = "must have property " + e.params.missingProperty break default: out = "" var t = e.params.type var n = e.params.nullable ? "/null" : "" out += "must be " + (t + n) } break case "type": case "elements": case "values": out = "" var t = e.params.type var n = e.params.nullable ? "/null" : "" out += "must be " + (t + n) break case "union": out = 'must match a schema in "union"' break default: out = 'must pass "' + e.keyword + '" keyword validation' } e.message = out } }