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 c8f6c2b
Showing 1 changed file with 28 additions and 23 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

0 comments on commit c8f6c2b

Please sign in to comment.