fastify / fastify/help

How to use ajv8 and ajv-errors in fastify 4 project within lerna monorepo?

Open
#715 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
68
Forks
8
Avg merge
11h 2m
Merged PRs (30d)
2

Description

#### You have already researched for similar issues?
It's not uncommon that somebody already opened an issue or in best case it's already fixed but not merged. That's the reason why you should [search](https://github.com/fastify/fastify/issues) at first before submitting a new one.

#### What are you trying to achieve, or the steps to reproduce?

i try to update fastify 3 to fastify 4.
and my old ajv settings is this:
```
/**
* 功能: ajv 设置后才能使用errorMessage自定义错误信息
* TODO:
* -
* DONE:
* -
*/
const localize = require('ajv-i18n') // ajv 国际化
const errorProperties = require('../constants/errorProperties.json') // 错误提示信息 用于schema自动生成错误
module.exports = {
ajv: {
customOptions: { removeAdditional: true, allErrors: true, jsonPointers: true },
plugins: [require('ajv-errors')]
},
schemaErrorFormatter: (errors, dataVar) => {
// params 转中文
errors.map((error) => {
if (errorProperties[error.params.missingProperty]) {
error.params.missingProperty = errorProperties[error.params.missingProperty]
}
if (error.dataPath) {
// 删除斜杠
let value = error.dataPath.substr(1)
error.dataPath = errorProperties[value]
}
return error
})
localize.zh(errors)
const myErrorMessage = errors
.map((err) => {
return err.dataPath ? `${err.dataPath.trim()} ${err.message.trim()}` : err.message.trim()
})
.join(', ')
return new Error(myErrorMessage)
}
}

```
how to make ajv-errors and ajv8 works in new version?

#### What was the result you received?

#### What did you expect?

#### Context

* *node version*: 16
* *fastify version*: >=4
* *os*: Windows
* *any other relevant information*: ajv8 ajv-errors3

**Please read this entire template before posting any issue. If you ignore these instructions
and post an issue here that does not follow the instructions, your issue might be closed,
locked, and assigned the `missing discussion` label.**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.