Skip to content

Commit

Permalink
Remove CopyMiscFrom(), fix issues with nested & versioned params
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianczech committed Mar 29, 2024
1 parent 09d149b commit a40bf23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
18 changes: 10 additions & 8 deletions pkg/translate/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ func appendSpecObjectAssignment(param *properties.SpecParam, objectType string,
func defineNestedObject(parent []string, param *properties.SpecParam, objectType string, version, prefix, suffix string, builder *strings.Builder) {
declareRootOfNestedObject(parent, builder, version, prefix, suffix)

builder.WriteString(fmt.Sprintf("if o.%s != nil {\n", strings.Join(parent, ".")))
if param.Spec != nil {
assignEmptyStructForNestedObject(parent, builder, objectType, version, prefix, suffix)
defineNestedObjectForChildParams(parent, param.Spec.Params, objectType, version, prefix, suffix, builder)
defineNestedObjectForChildParams(parent, param.Spec.OneOf, objectType, version, prefix, suffix, builder)
} else {
assignValueForNestedObject(parent, builder)
if ParamSupportedInVersion(param, version) {
builder.WriteString(fmt.Sprintf("if o.%s != nil {\n", strings.Join(parent, ".")))
if param.Spec != nil {
assignEmptyStructForNestedObject(parent, builder, objectType, version, prefix, suffix)
defineNestedObjectForChildParams(parent, param.Spec.Params, objectType, version, prefix, suffix, builder)
defineNestedObjectForChildParams(parent, param.Spec.OneOf, objectType, version, prefix, suffix, builder)
} else {
assignValueForNestedObject(parent, builder)
}
builder.WriteString("}\n")
}
builder.WriteString("}\n")
}

func declareRootOfNestedObject(parent []string, builder *strings.Builder, version, prefix, suffix string) {
Expand Down
11 changes: 0 additions & 11 deletions templates/sdk/entry.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,6 @@
{{- end}}
{{- end}}

func (e *Entry) CopyMiscFrom(v *Entry) {
if v == nil || len(v.Misc) == 0 {
return
}

e.Misc = make(map[string][]generic.Xml)
for key := range v.Misc {
e.Misc[key] = append([]generic.Xml(nil), v.Misc[key]...)
}
}

func (e *Entry) Field(v string) (any, error) {
if v == "name" || v == "Name" {
return e.Name, nil
Expand Down

0 comments on commit a40bf23

Please sign in to comment.