skip number validator on zero-default
This commit is contained in:
parent
3b9a9df171
commit
341bcc4a0e
|
@ -135,7 +135,7 @@ func (validator *RecordDataValidator) checkFieldValue(field *schema.SchemaField,
|
||||||
func (validator *RecordDataValidator) checkTextValue(field *schema.SchemaField, value any) error {
|
func (validator *RecordDataValidator) checkTextValue(field *schema.SchemaField, value any) error {
|
||||||
val, _ := value.(string)
|
val, _ := value.(string)
|
||||||
if val == "" {
|
if val == "" {
|
||||||
return nil // nothing to check
|
return nil // nothing to check (skip zero-defaults)
|
||||||
}
|
}
|
||||||
|
|
||||||
options, _ := field.Options.(*schema.TextOptions)
|
options, _ := field.Options.(*schema.TextOptions)
|
||||||
|
@ -159,11 +159,11 @@ func (validator *RecordDataValidator) checkTextValue(field *schema.SchemaField,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (validator *RecordDataValidator) checkNumberValue(field *schema.SchemaField, value any) error {
|
func (validator *RecordDataValidator) checkNumberValue(field *schema.SchemaField, value any) error {
|
||||||
if value == nil {
|
val, _ := value.(float64)
|
||||||
return nil // nothing to check
|
if val == 0 {
|
||||||
|
return nil // nothing to check (skip zero-defaults)
|
||||||
}
|
}
|
||||||
|
|
||||||
val, _ := value.(float64)
|
|
||||||
options, _ := field.Options.(*schema.NumberOptions)
|
options, _ := field.Options.(*schema.NumberOptions)
|
||||||
|
|
||||||
if options.Min != nil && val < *options.Min {
|
if options.Min != nil && val < *options.Min {
|
||||||
|
|
|
@ -168,7 +168,7 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||||
// create new test collection
|
// create new test collection
|
||||||
collection := &models.Collection{}
|
collection := &models.Collection{}
|
||||||
collection.Name = "validate_test"
|
collection.Name = "validate_test"
|
||||||
min := 0.0
|
min := 2.0
|
||||||
max := 150.0
|
max := 150.0
|
||||||
collection.Schema = schema.NewSchema(
|
collection.Schema = schema.NewSchema(
|
||||||
&schema.SchemaField{
|
&schema.SchemaField{
|
||||||
|
@ -244,6 +244,15 @@ func TestRecordDataValidatorValidateNumber(t *testing.T) {
|
||||||
nil,
|
nil,
|
||||||
[]string{"field3"},
|
[]string{"field3"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"(number) check min with zero-default",
|
||||||
|
map[string]any{
|
||||||
|
"field2": 1,
|
||||||
|
"field3": 0,
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
[]string{},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"(number) check max constraint",
|
"(number) check max constraint",
|
||||||
map[string]any{
|
map[string]any{
|
||||||
|
|
Loading…
Reference in New Issue