diff --git a/pkg/translate/funcs.go b/pkg/translate/funcs.go index b2e6f6b4..fd8b039f 100644 --- a/pkg/translate/funcs.go +++ b/pkg/translate/funcs.go @@ -96,6 +96,24 @@ func assignEmptyStructForNestedObject(parent []string, builder *strings.Builder, builder.WriteString(fmt.Sprintf("nested%s = &Spec%s%s{}\n", strings.Join(parent, "."), strings.Join(parent, ""), suffix)) + + if suffix == "Xml" { + builder.WriteString(fmt.Sprintf("if o.%s.Misc != nil {\n", strings.Join(parent, "."))) + builder.WriteString(fmt.Sprintf("nested%s.Misc = o.%s.Misc[\"%s\"]\n", + strings.Join(parent, "."), + strings.Join(parent, "."), + strings.Join(parent, ""), + )) + builder.WriteString("}\n") + } else { + builder.WriteString(fmt.Sprintf("if o.%s.Misc != nil {\n", strings.Join(parent, "."))) + builder.WriteString(fmt.Sprintf("nested%s.Misc[\"%s\"] = o.%s.Misc\n", + strings.Join(parent, "."), + strings.Join(parent, ""), + strings.Join(parent, "."), + )) + builder.WriteString("}\n") + } } } diff --git a/templates/sdk/config.tmpl b/templates/sdk/config.tmpl index a927fd4c..b941e47f 100644 --- a/templates/sdk/config.tmpl +++ b/templates/sdk/config.tmpl @@ -30,6 +30,8 @@ type Spec{{$name}} struct { {{- range $_, $param := $spec.OneOf}} {{$param.Name.CamelCase}} {{specParamType $name $param}} {{- end}} + + Misc map[string][]generic.Xml } {{- end}} @@ -57,7 +59,7 @@ type Spec{{$name}}Xml struct { {{$param.Name.CamelCase}} {{xmlParamType $name $param}} {{xmlTag $param}} {{- end}} - Misc []generic.Xml `xml:",any" + Misc []generic.Xml `xml:",any"` } {{- end}} @@ -106,7 +108,7 @@ func SpecifyConfig(o Config) (any, error) { {{specifyEntryAssignment "config" $param}} {{- end}} - config.Misc = o.Misc[fmt.Sprintf("%s", "Config")] + config.Misc = o.Misc["Config"] return config, nil } @@ -124,7 +126,7 @@ func (c *ConfigXmlContainer) Normalize() ([]Config, error) { {{normalizeAssignment "config" $param}} {{- end}} - config.Misc[fmt.Sprintf("%s", "Config")] = o.Misc + config.Misc["Config"] = o.Misc configList = append(configList, config) } diff --git a/templates/sdk/entry.tmpl b/templates/sdk/entry.tmpl index c006d6f2..4f4b1d36 100644 --- a/templates/sdk/entry.tmpl +++ b/templates/sdk/entry.tmpl @@ -43,6 +43,8 @@ type Spec{{$name}} struct { {{- range $_, $param := $spec.OneOf}} {{$param.Name.CamelCase}} {{specParamType $name $param}} {{- end}} + + Misc map[string][]generic.Xml } {{- end}} @@ -118,7 +120,7 @@ func Versioning(vn version.Number) (Specifier, Normalizer, error) { // TODO: think if struct EntryXml1 / E_0_0 has to be public or not ??? // maybe it's good to make it hidden and do not have in public documentation ... -func SpecifyEntry(o Entry) (any, +func SpecifyEntry(o Entry) (any, error) { entry := EntryXml{} entry.Name = o.Name @@ -129,9 +131,7 @@ func SpecifyEntry(o Entry) (any, {{specifyEntryAssignment "entry" $param}} {{- end}} - entry.Misc = o.Misc[fmt.Sprintf("%s\n%s", "Entry", o.Name)] - - // TODO: we use name of the struct for single objects, but if we have a list, we combine name of the struct + index + entry.Misc = o.Misc["Entry"] return entry, nil } @@ -150,9 +150,7 @@ func (c *EntryXmlContainer) Normalize() ([]Entry, error) { {{normalizeAssignment "entry" $param}} {{- end}} - entry.Misc[fmt.Sprintf("%s\n%s", "Entry", o.Name)] = o.Misc - - // TODO: similary as for SpecifyEntry(), it has to be name of the struct e.g. EntryXml for address + entry.Misc["Entry"] = o.Misc // TODO: start thinking about versioning e.g: // 1 approach: EntryXml1, EntryXml2, EntryXml3, ...