Skip to content

Commit

Permalink
for item with type object, render []string, which will contain all me…
Browse files Browse the repository at this point in the history
…mbers
  • Loading branch information
sebastianczech committed Mar 13, 2024
1 parent 2939d86 commit b51801b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/properties/normalized.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type SpecParamCount struct {
type SpecParamItems struct {
Type string `json:"type" yaml:"type"`
Length *SpecParamItemsLength `json:"length" yaml:"length"`
Ref []*string `json:"ref" yaml:"ref"`
}

type SpecParamItemsLength struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/properties/normalized_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ spec:
length:
min: null
max: 127
ref: []
profiles:
- xpath:
- tag
Expand Down
4 changes: 2 additions & 2 deletions pkg/translate/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NormalizeAssignment(param *properties.SpecParam) string {
var builder strings.Builder

if param.Type == "list" && param.Profiles != nil && len(param.Profiles) > 0 && param.Profiles[0].Type == "member" {
builder.WriteString(fmt.Sprintf("entry.%s = entryXml.%s", param.Name.CamelCase, param.Name.CamelCase))
builder.WriteString(fmt.Sprintf("entry.%s = o.%s", param.Name.CamelCase, param.Name.CamelCase))
} else if param.Spec != nil {
for _, subParam := range param.Spec.Params {
builder.WriteString(nestedObjectDeclaration([]string{param.Name.CamelCase}, subParam))
Expand All @@ -41,7 +41,7 @@ func NormalizeAssignment(param *properties.SpecParam) string {
}
builder.WriteString("}\n")
} else {
builder.WriteString(fmt.Sprintf("entry.%s = entryXml.%s", param.Name.CamelCase, param.Name.CamelCase))
builder.WriteString(fmt.Sprintf("entry.%s = o.%s", param.Name.CamelCase, param.Name.CamelCase))
}

return builder.String()
Expand Down
6 changes: 5 additions & 1 deletion pkg/translate/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ func SpecParamType(param *properties.SpecParam) string {

calculatedType := ""
if param.Type == "list" && param.Items != nil {
calculatedType = param.Items.Type
if param.Items.Type == "object" && param.Items.Ref != nil {
calculatedType = "string"
} else {
calculatedType = param.Items.Type
}
} else if param.Spec != nil {
calculatedType = fmt.Sprintf("Spec%s", naming.CamelCase("", param.Name.CamelCase, "", true))
} else {
Expand Down
1 change: 1 addition & 0 deletions specs/objects/address-group.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ spec:
type: 'object'
ref:
- '#/specs/objects/address.yaml'
- '#/specs/objects/address-group.yaml'
profiles:
-
type: 'member'
Expand Down

0 comments on commit b51801b

Please sign in to comment.