1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-01 15:18:20 +00:00

Change defaulting logic

This commit is contained in:
Darren Shepherd
2018-03-04 22:05:03 -07:00
parent 1e9982bd45
commit 1f0f16a832

View File

@@ -89,11 +89,6 @@ func (b *Builder) copyInputs(schema *types.Schema, input map[string]interface{},
}
}
// Don't copy empty strings
if !(value == "" && field.Type == "string") {
result[fieldName] = value
}
if op.IsList() && field.Type == "date" && value != "" {
ts, err := convert.ToTimestamp(value)
if err == nil {
@@ -117,8 +112,8 @@ func (b *Builder) copyInputs(schema *types.Schema, input map[string]interface{},
func (b *Builder) checkDefaultAndRequired(schema *types.Schema, input map[string]interface{}, op Operation, result map[string]interface{}) error {
for fieldName, field := range schema.ResourceFields {
_, hasKey := result[fieldName]
if op == Create && !hasKey && field.Default != nil {
val, hasKey := result[fieldName]
if op == Create && (!hasKey || val == "") && field.Default != nil {
result[fieldName] = field.Default
}