Skip to content

Commit

Permalink
Refactor: Fields should be considered GoStructItems
Browse files Browse the repository at this point in the history
and use this same abstraction
  • Loading branch information
isimluk committed Oct 30, 2020
1 parent 85398c5 commit 68df5f7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 4 additions & 0 deletions metaschema/parser/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func (f *Field) GoTypeName() string {
return f.Def.GoTypeName()
}

func (f *Field) GoTypeNameMultiplexed() string {
return f.GoTypeName()
}

func (f *Field) GoPackageName() string {
if f.Ref == "" {
return ""
Expand Down
7 changes: 5 additions & 2 deletions metaschema/parser/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ type Model struct {
}

func (m *Model) GoStructItems() []GoStructItem {
res := make([]GoStructItem, len(m.Assembly))
res := make([]GoStructItem, len(m.Assembly)+len(m.Field))
for i, _ := range m.Field {
res[i] = &m.Field[i]
}
for i, _ := range m.Assembly {
res[i] = &m.Assembly[i]
res[i+len(m.Field)] = &m.Assembly[i]
}
return res
}
Expand Down
5 changes: 0 additions & 5 deletions metaschema/templates/generated_models.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ type {{.GoTypeName}} struct {
{{.GoName}} {{.GoDatatype}} `xml:"{{.XmlName}},attr,omitempty" json:"{{.JsonName}},omitempty"`
{{- end}}
{{if .Model}}
{{ range .Model.Field}}
// {{ .GoComment }}
{{.GoName}} {{.GoMemLayout}}{{.GoTypeName}} `xml:"{{.XmlAnnotation}}" json:"{{.JsonName}},omitempty"`
{{- end}}

{{- range .Model.GoStructItems}}
// {{ .GoComment }}
{{.GoName}} {{.GoMemLayout}}{{.GoTypeNameMultiplexed}} `xml:"{{.XmlAnnotation}}" json:"{{.JsonName}},omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion metaschema/templates/pkged.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 68df5f7

Please sign in to comment.