FoalTS / foal

Full-featured Node.js framework, with no complexity. 🚀 Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.89k stars 139 forks source link

[AJV] Custom validation errors #809

Closed Sharlaan closed 3 years ago

Sharlaan commented 3 years ago

I'm trying to implement custom error messages for AJV validation objects in @ValidateBody, using plugin ajv-errors (as suggested in AJV docs)

but FoalTS seems to ignore any errorMessage ?

LoicPoullain commented 3 years ago

The framework needs to be updated to support the settings.ajv.jsonPointers configuration. This can be done just after the release of v2.

LoicPoullain commented 3 years ago

It seems that ajv-errors do not require anymore the jsonPointers option: https://github.com/ajv-validator/ajv-errors#usage.

So settings allErrors: true in the configuration and calling require("ajv-errors")(getAjvInstance()) before createApp should work.

getAjvInstance can be imported from @foal/core.

Let me know if this works.

LoicPoullain commented 3 years ago

@Sharlaan I added some documentation on this. Feel free to re-open the issue if you still need help.