-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
I have this in my schema:
"amount": {
"type": "number",
"multipleOf": 0.01
},
The generated Validate function is
if math.Mod(*m.Amount, 0.01) != 0 {
return &validationError{
errType: "multipleOf",
path: []interface{}{"Amount"},
jsonPath: []interface{}{"amount"},
message: fmt.Sprintf("must be a multiple of 0.01 but was %v", *m.Amount),
}
}
So for the amount 2000, it reported the error as must be a multiple of 0.01 but was 2000
I understand the floating point characteristic makes an integer won't always return 0 when calculating math.Mod(integer, 0.01)
I have to modify it manually to correct the validation.
if math.Mod(*m.Amount*100, 1) != 0 {
return &validationError{
errType: "multipleOf",
path: []interface{}{"Amount"},
jsonPath: []interface{}{"amount"},
message: fmt.Sprintf("must be a multiple of 0.01 but was %v", *m.Amount),
}
}
Metadata
Metadata
Assignees
Labels
No labels