ajv-validator / ajv-validator/ajv-i18n

Introduction of the "_defaultMessage" overrides messages defined in schema

Aberta
#232 3 comentários 6 reações 0 responsáveis Ver no GitHub
Linguagem predominante
JavaScript
Estrelas
180
Forks
91
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

Hi!

Thanks for this great library!

I am in the process of upgrading to v8 as well as errors, i18n and formats plugins. I am noticing that one thing that works differently is the uses of default messages in i18n.

```
const schema = {/* ... */} // valid draft-07 schema
const data = {/* ... */} // valid data object, but not validating against the schema

const ajv = new Ajv({ allErrors: true })
const validate = ajv.compile(schema)

if (!validate(data)) {
localize.en(validate.errors)
console.log(validate.errors)
}
```

The console outputs lots of "must pass \"errorMessage\" keyword validation", even though I have defined "errorMessage" in the schema. It used to work in v7 with plugins.

https://github.com/ajv-validator/ajv-i18n/blob/master/messages/index.js#L80 generate a default case to the switch statements that override every single message.

The code definitely works, it is not a bug. However, the behaviour is totally different from the previous version, and wondering if it is the desired behaviour. If it is, wondering how to provide error messages from schema (using "errorMessage") as well as from the i18n plugin. Messages within "errorMessage" in my schema are translated.

EDIT
I am noticing that #220 is probably a similar issue.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.