1
0
mirror of https://github.com/rancher/norman.git synced 2025-08-02 07:59:20 +00:00

Add default value to float type

Problem:
float type default value are convert to string now

Solution:
add default value for float

Issue:
https://github.com/rancher/rancher/issues/16958
This commit is contained in:
Aiwantaozi 2018-12-07 18:15:20 +08:00
parent dc01b97134
commit b681b841db

View File

@ -289,7 +289,9 @@ func (s *Schemas) readFields(schema *Schema, t reflect.Type) error {
fieldType.Kind() == reflect.Uint32 ||
fieldType.Kind() == reflect.Int32 ||
fieldType.Kind() == reflect.Uint64 ||
fieldType.Kind() == reflect.Int64 {
fieldType.Kind() == reflect.Int64 ||
fieldType.Kind() == reflect.Float32 ||
fieldType.Kind() == reflect.Float64 {
schemaField.Nullable = false
schemaField.Default = 0
}
@ -314,6 +316,12 @@ func (s *Schemas) readFields(schema *Schema, t reflect.Type) error {
return err
}
schemaField.Default = n
case "float":
n, err := convert.ToFloat(schemaField.Default)
if err != nil {
return err
}
schemaField.Default = n
case "boolean":
schemaField.Default = convert.ToBool(schemaField.Default)
}
@ -446,6 +454,10 @@ func (s *Schemas) determineSchemaType(version *APIVersion, t reflect.Type) (stri
fallthrough
case reflect.Int64:
return "int", nil
case reflect.Float32:
fallthrough
case reflect.Float64:
return "float", nil
case reflect.Interface:
return "json", nil
case reflect.Map: