0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(schemas): guard string length for default value field (#3868)

should also guard the string length for non-nullable field with a default value as well
This commit is contained in:
simeng-li 2023-05-19 15:43:44 +08:00 committed by GitHub
parent 08a578b4d1
commit a265f1f48e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -47,9 +47,7 @@ export const generateSchema = ({ name, fields }: TableWithType) => {
return ` ${camelcase(name)}: z.${isEnum ? `nativeEnum(${type})` : `${type}()`}${ return ` ${camelcase(name)}: z.${isEnum ? `nativeEnum(${type})` : `${type}()`}${
// Non-nullable strings should have a min length of 1 // Non-nullable strings should have a min length of 1
conditionalString( conditionalString(isString && !(nullable || name === tenantId) && `.min(1)`)
isString && !(nullable || hasDefaultValue || name === tenantId) && `.min(1)`
)
}${ }${
// String types value in DB should have a max length // String types value in DB should have a max length
conditionalString(isString && maxLength && `.max(${maxLength})`) conditionalString(isString && maxLength && `.max(${maxLength})`)