Skip to content

Commit

Permalink
Support for element type ref attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
xinhuang327 committed Jan 25, 2016
1 parent eca931b commit a55bfe7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 12 additions & 0 deletions gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func (g *GoWSDL) genTypes() ([]byte, error) {
"replaceReservedWords": replaceReservedWords,
"makePublic": makePublic,
"comment": comment,
"removeNS": removeNS,
}

//TODO resolve element refs in place.
Expand Down Expand Up @@ -375,6 +376,17 @@ var xsd2GoTypes = map[string]string{
"anytype": "interface{}",
}

func removeNS(xsdType string) string {
// Handles name space, ie. xsd:string, xs:string
r := strings.Split(xsdType, ":")

if len(r) == 2 {
return r[1]
} else {
return r[0]
}
}

func toGoType(xsdType string) string {
// Handles name space, ie. xsd:string, xs:string
r := strings.Split(xsdType, ":")
Expand Down
13 changes: 12 additions & 1 deletion types_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ var typesTmpl = `
{{end}}
{{define "Elements"}}
{{range .}} {{if not .Type}} {{template "ComplexTypeInline" .}} {{else}} {{if .Doc}} {{.Doc | comment}} {{"\n"}} {{end}} {{replaceReservedWords .Name | makePublic}} {{if eq .MaxOccurs "unbounded"}}[]{{end}}{{.Type | toGoType}} ` + "`" + `xml:"{{.Name}},omitempty"` + "`" + ` {{end}}
{{range .}}
{{if ne .Ref ""}}
{{removeNS .Ref | replaceReservedWords | makePublic}} {{if eq .MaxOccurs "unbounded"}}[]{{end}}{{.Ref | toGoType}} ` + "`" + `xml:"{{.Ref | removeNS}},omitempty"` + "`" + `
{{else}}
{{if not .Type}}
{{template "ComplexTypeInline" .}}
{{else}}
{{if .Doc}}
{{.Doc | comment}} {{"\n"}}
{{end}}
{{replaceReservedWords .Name | makePublic}} {{if eq .MaxOccurs "unbounded"}}[]{{end}}{{.Type | toGoType}} ` + "`" + `xml:"{{.Name}},omitempty"` + "`" + ` {{end}}
{{end}}
{{end}}
{{end}}
Expand Down

0 comments on commit a55bfe7

Please sign in to comment.