16 lines
805 B
JavaScript
16 lines
805 B
JavaScript
import ajvErrors from "ajv-errors";
|
||
import { isLowerCase, isTrim } from "#utils/ajv/method";
|
||
export const ajvConfig = {
|
||
customOptions: {
|
||
removeAdditional: true, // 自动删除schema未定义的额外属性
|
||
useDefaults: true, // 使用schema中定义的默认值填充缺失字段
|
||
coerceTypes: true, // 自动转换数据类型(如字符串"123"→数字123)
|
||
allErrors: true, // 收集所有验证错误(不止第一个错误)
|
||
allowUnionTypes: true // 允许联合类型(如 type: ["string", "number"])
|
||
},
|
||
plugins: [
|
||
ajvErrors, // 支持自定义错误消息
|
||
isLowerCase, // 自定义验证:强制小写(如用户名)
|
||
isTrim, // 自定义验证:自动trim字符串
|
||
]
|
||
} |