yuheng/src/utils/ajv/index.js

16 lines
805 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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字符串
]
}