From 5101fef2fd8ee34f408388f46b35edae96e2be5a Mon Sep 17 00:00:00 2001 From: Camilo Aguilar Date: Fri, 17 Jan 2014 11:33:10 -0500 Subject: [PATCH] Adds support for generating code for and --- README.md | 1 - generator/types_tmpl.go | 40 +++++++++++++++++++++++++++------------- generator/xsd.go | 15 +++++++++++---- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index fd74936..9cda844 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,6 @@ Help Options: ### TODO * If WSDL file is local, resolve external XML schemas locally too instead of failing due to not having a URL to download them from. -* Support elements * Resolve XSD element references * Support for generating namespaces * Make code generation agnostic so generating code to other programming languages is feasible through plugins diff --git a/generator/types_tmpl.go b/generator/types_tmpl.go index 15d4399..a2d8e38 100644 --- a/generator/types_tmpl.go +++ b/generator/types_tmpl.go @@ -12,36 +12,50 @@ var typesTmpl = ` ) {{end}} +{{define "ComplexContent"}} + {{$baseType := toGoType .Extension.Base}} + {{ if $baseType }} + {{$baseType}} + {{end}} + + {{template "Elements" .Extension.Sequence.Elements}} + {{template "Attributes" .Extension.Attributes}} +{{end}} + +{{define "Attributes"}} + {{range .}} + {{ .Name | makePublic}} {{toGoType .Type}}{{end}} +{{end}} + +{{define "SimpleContent"}} + Value {{toGoType .Extension.Base}}{{template "Attributes" .Extension.Attributes}} +{{end}} + {{define "ComplexTypeGlobal"}} {{$name := replaceReservedWords .Name}} type {{$name}} struct { {{if ne .ComplexContent.Extension.Base ""}} - {{$baseType := .ComplexContent.Extension.Base}} - {{ if $baseType }} - *{{stripns $baseType}} - {{end}} - - {{template "Elements" .ComplexContent.Extension.Sequence.Elements}} + {{template "ComplexContent" .ComplexContent}} + {{else if ne .SimpleContent.Extension.Base ""}} + {{template "SimpleContent" .SimpleContent}} {{ else }} {{template "Elements" .Sequence.Elements}} + {{template "Attributes" .Attributes}} {{end}} } {{end}} {{define "ComplexTypeLocal"}} {{$name := replaceReservedWords .Name}} - {{with .ComplexType}} type {{$name}} struct { {{if ne .ComplexContent.Extension.Base ""}} - {{$baseType := .ComplexContent.Extension.Base}} - {{ if $baseType }} - *{{stripns $baseType}} - {{end}} - - {{template "Elements" .ComplexContent.Extension.Sequence.Elements}} + {{template "ComplexContent" .ComplexContent}} + {{else if ne .SimpleContent.Extension.Base ""}} + {{template "SimpleContent" .SimpleContent}} {{ else }} {{template "Elements" .Sequence.Elements}} + {{template "Attributes" .Attributes}} {{end}} } {{end}} diff --git a/generator/xsd.go b/generator/xsd.go index e312c58..2aaa821 100644 --- a/generator/xsd.go +++ b/generator/xsd.go @@ -51,10 +51,11 @@ type XsdComplexType struct { All []XsdElement `xml:"all>element"` ComplexContent XsdComplexContent `xml:"http://www.w3.org/2001/XMLSchema complexContent"` SimpleContent XsdSimpleContent `xml:"http://www.w3.org/2001/XMLSchema simpleContent"` + Attributes []*XsdAttribute `xml:"http://www.w3.org/2001/XMLSchema attribute"` } type XsdGroup struct { - Name string `xml:"name, attr"` + Name string `xml:"name,attr"` Ref string `xml:"ref,attr"` Sequence XsdSequence `xml:"http://www.w3.org/2001/XMLSchema sequence"` Choice []XsdElement `xml:"http://www.w3.org/2001/XMLSchema choice"` @@ -72,9 +73,15 @@ type XsdSimpleContent struct { } type XsdExtension struct { - XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema extension"` - Base string `xml:"base,attr"` - Sequence XsdSequence `xml:"http://www.w3.org/2001/XMLSchema sequence"` + XMLName xml.Name `xml:"http://www.w3.org/2001/XMLSchema extension"` + Base string `xml:"base,attr"` + Attributes []*XsdAttribute `xml:"http://www.w3.org/2001/XMLSchema attribute"` + Sequence XsdSequence `xml:"http://www.w3.org/2001/XMLSchema sequence"` +} + +type XsdAttribute struct { + Name string `xml:"name,attr"` + Type string `xml:"type,attr"` } type XsdSimpleType struct {