Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/codegen/templates/convert.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ func {{ .Name }}ToXML(ctx context.Context, model *{{ .Name }}Model) (*libvirtxml
return nil, fmt.Errorf("converting {{ .GoName }} to List: %s", diags.Errors()[0].Summary())
}
model.{{ .GoName }} = listVal
} else if plan != nil && !plan.{{ .GoName }}.IsNull() {
// User explicitly set an empty list - return empty list to preserve intent
listVal, diags := types.ListValueFrom(ctx, types.ObjectType{AttrTypes: {{ .NestedStruct.Name }}AttributeTypes()}, []{{ .NestedStruct.Name }}Model{})
if diags.HasError() {
return nil, fmt.Errorf("converting {{ .GoName }} to List: %s", diags.Errors()[0].Summary())
}
model.{{ .GoName }} = listVal
} else {
model.{{ .GoName }} = types.ListNull(types.ObjectType{AttrTypes: {{ .NestedStruct.Name }}AttributeTypes()})
}
Expand All @@ -251,6 +258,13 @@ func {{ .Name }}ToXML(ctx context.Context, model *{{ .Name }}Model) (*libvirtxml
return nil, fmt.Errorf("converting {{ .GoName }} to List: %s", diags.Errors()[0].Summary())
}
model.{{ .GoName }} = listVal
} else if plan != nil && !plan.{{ .GoName }}.IsNull() {
// User explicitly set an empty list - return empty list to preserve intent
listVal, diags := types.ListValueFrom(ctx, {{ .ElementType }}, xml.{{ .GoName }})
if diags.HasError() {
return nil, fmt.Errorf("converting {{ .GoName }} to List: %s", diags.Errors()[0].Summary())
}
model.{{ .GoName }} = listVal
} else {
model.{{ .GoName }} = types.ListNull({{ .ElementType }})
}
Expand Down