Skip to content

Commit

Permalink
Rewrite ParamSpec SetDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
chuangw6 committed May 1, 2022
1 parent 136e04d commit 9f28404
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
51 changes: 28 additions & 23 deletions pkg/apis/pipeline/v1beta1/param_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,37 @@ type PropertySpec struct {

// SetDefaults set the default type
func (pp *ParamSpec) SetDefaults(ctx context.Context) {
if pp != nil && pp.Type == "" {
// if the properties section is not empty, set object as the parameter type
if pp.Properties != nil {
pp.Type = ParamTypeObject
for _, property := range pp.Properties {
property.Type = ParamTypeString
}
} else if pp.Default != nil {
// propagate the parsed ArrayOrString's type to the parent ParamSpec's type
if pp.Default.Type != "" {
// propagate the default type if specified
pp.Type = pp.Default.Type
if pp == nil || pp.Type != "" {
return
}

// if the properties section is not empty, set object as the parameter type
if pp.Properties != nil {
pp.Type = ParamTypeObject
for _, property := range pp.Properties {
property.Type = ParamTypeString
}
return
}

if pp.Default != nil {
// propagate the parsed ArrayOrString's type to the parent ParamSpec's type
if pp.Default.Type != "" {
// propagate the default type if specified
pp.Type = pp.Default.Type
} else {
// determine the type based on the array or string values when default value is specified but not the type
if pp.Default.ArrayVal != nil {
pp.Type = ParamTypeArray
} else if pp.Default.ObjectVal != nil {
pp.Type = ParamTypeObject
} else {
// determine the type based on the array or string values when default value is specified but not the type
if pp.Default.ArrayVal != nil {
pp.Type = ParamTypeArray
} else if pp.Default.ObjectVal != nil {
pp.Type = ParamTypeObject
} else {
pp.Type = ParamTypeString
}
pp.Type = ParamTypeString
}
} else {
// ParamTypeString is the default value (when no type can be inferred from the default value)
pp.Type = ParamTypeString
}
} else {
// ParamTypeString is the default value (when no type can be inferred from the default value)
pp.Type = ParamTypeString
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/pipeline/v1beta1/taskrun_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func validateNoDuplicateNames(names []string, byIndex bool) (errs *apis.FieldErr
errs = errs.Also(apis.ErrMultipleOneOf("name").ViaKey(n))
}
}
seen.Insert(strings.ToLower(n))
seen.Insert(n)
}
return errs
}

0 comments on commit 9f28404

Please sign in to comment.