From a55bfe74d091bd35407c71b0342348cccfb05089 Mon Sep 17 00:00:00 2001 From: Adrian Huang Date: Mon, 25 Jan 2016 16:30:25 +0800 Subject: [PATCH] Support for element type ref attribute --- gowsdl.go | 12 ++++++++++++ types_tmpl.go | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gowsdl.go b/gowsdl.go index 858ace9..1f36121 100644 --- a/gowsdl.go +++ b/gowsdl.go @@ -235,6 +235,7 @@ func (g *GoWSDL) genTypes() ([]byte, error) { "replaceReservedWords": replaceReservedWords, "makePublic": makePublic, "comment": comment, + "removeNS": removeNS, } //TODO resolve element refs in place. @@ -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, ":") diff --git a/types_tmpl.go b/types_tmpl.go index 2147fa2..31acbea 100644 --- a/types_tmpl.go +++ b/types_tmpl.go @@ -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}}