Skip to content

Commit

Permalink
Adds support for generating code for <attributes/> and <simpleContent/>
Browse files Browse the repository at this point in the history
  • Loading branch information
c4milo committed Jan 17, 2014
1 parent 0553ad2 commit 5101fef
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <xs:attribute/> elements
* Resolve XSD element references
* Support for generating namespaces
* Make code generation agnostic so generating code to other programming languages is feasible through plugins
Expand Down
40 changes: 27 additions & 13 deletions generator/types_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
15 changes: 11 additions & 4 deletions generator/xsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down

0 comments on commit 5101fef

Please sign in to comment.