-
Notifications
You must be signed in to change notification settings - Fork 55
Description
In 1 of my 15 production pods for one service, the validation is invalid out of no where.
account_id is invalid: type should be �K, got string
This pod run around 60 days before this event. It run just fine before this from log/tracing. After that it always fail to validate.
account_id is normal string '23982400' but any string got the same error which is correct for 'got string'. But �K part is incorrect.
The schema is simple:
...
"account_id": {
"type": "string",
"format_ex": "integer"
},
format_ex is nothing complex, it just check after validate string by implement "ValidateKeyword"
if !integerPattern.MatchString(integer) {//`^\d+$`
return fmt.Errorf("invalid integer: %v", integer)
}
But "format_ex" should not be the cause because it's different error message. I can't find root cause why "type": "string" is evaluate as �K. Some non-printable binary may follow this.
I load rootSchema (rs) once and use it after that
schemaData, err := os.ReadFile(path.Join(RootDir(), "internal/schema/"+fileSchema+".json"))
if err != nil {
err = NewErrConfig(fmt.Sprintf("Validation schema file not found: %v", fileSchema), err.Error())
return err
}
rs = new(jsonschema.Schema)
// Keep rootSchemas
rootSchemas[fileSchema] = rs
if err := json.Unmarshal(schemaData, rs); err != nil {
err = NewErrConfig(fmt.Sprintf("Validation schema file is invalid"), err.Error())
return err
}
Then validate by
keyErrors, err := rs.ValidateBytes(context.Background(), jsonStr)
version: v0.2.1
Do anyone may know or can guess the cause?