mirror of
https://github.com/rancher/norman.git
synced 2025-09-05 01:00:36 +00:00
Change defaulting logic
This commit is contained in:
@@ -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 != "" {
|
if op.IsList() && field.Type == "date" && value != "" {
|
||||||
ts, err := convert.ToTimestamp(value)
|
ts, err := convert.ToTimestamp(value)
|
||||||
if err == nil {
|
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 {
|
func (b *Builder) checkDefaultAndRequired(schema *types.Schema, input map[string]interface{}, op Operation, result map[string]interface{}) error {
|
||||||
for fieldName, field := range schema.ResourceFields {
|
for fieldName, field := range schema.ResourceFields {
|
||||||
_, hasKey := result[fieldName]
|
val, hasKey := result[fieldName]
|
||||||
if op == Create && !hasKey && field.Default != nil {
|
if op == Create && (!hasKey || val == "") && field.Default != nil {
|
||||||
result[fieldName] = field.Default
|
result[fieldName] = field.Default
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user