Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support default namespace #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module github.com/hooklift/gowsdl

go 1.12
18 changes: 18 additions & 0 deletions gowsdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,22 @@ func (g *GoWSDL) resolveXSDExternals(schema *XSDSchema, loc *Location) error {
}

func (g *GoWSDL) genTypes() ([]byte, error) {

globalTargetNamespace := ""

setTargetNamespace := func(ns string) string {
globalTargetNamespace = ns
return ""
}

getQualifiedName := func(name string) string {
if globalTargetNamespace != "" {
return globalTargetNamespace + " " + name
} else {
return name
}
}

funcMap := template.FuncMap{
"toGoType": toGoType,
"stripns": stripns,
Expand All @@ -266,6 +282,8 @@ func (g *GoWSDL) genTypes() ([]byte, error) {
"goString": goString,
"findNameByType": g.findNameByType,
"removePointerFromType": removePointerFromType,
"setTargetNamespace": setTargetNamespace,
"getQualifiedName": getQualifiedName,
}

data := new(bytes.Buffer)
Expand Down
15 changes: 9 additions & 6 deletions types_tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@ var typesTmpl = `
{{if .SimpleType}}
{{if .Doc}} {{.Doc | comment}} {{end}}
{{if ne .SimpleType.List.ItemType ""}}
{{ .Name | makeFieldPublic}} []{{toGoType .SimpleType.List.ItemType}} ` + "`" + `xml:"{{.Name}},omitempty"` + "`" + `
{{ .Name | makeFieldPublic}} []{{toGoType .SimpleType.List.ItemType}} ` + "`" + `xml:"{{getQualifiedName .Name}},omitempty"` + "`" + `
{{else}}
{{ .Name | makeFieldPublic}} {{toGoType .SimpleType.Restriction.Base}} ` + "`" + `xml:"{{.Name}},omitempty"` + "`" + `
{{ .Name | makeFieldPublic}} {{toGoType .SimpleType.Restriction.Base}} ` + "`" + `xml:"{{getQualifiedName .Name}},omitempty"` + "`" + `
{{end}}
{{else}}
{{template "ComplexTypeInline" .}}
{{end}}
{{else}}
{{if .Doc}}{{.Doc | comment}} {{end}}
{{replaceReservedWords .Name | makeFieldPublic}} {{if eq .MaxOccurs "unbounded"}}[]{{end}}{{.Type | toGoType}} ` + "`" + `xml:"{{.Name}},omitempty"` + "`" + ` {{end}}
{{replaceReservedWords .Name | makeFieldPublic}} {{if eq .MaxOccurs "unbounded"}}[]{{end}}{{.Type | toGoType}} ` + "`" + `xml:"{{getQualifiedName .Name}},omitempty"` + "`" + ` {{end}}
{{end}}
{{end}}
{{end}}

{{range .Schemas}}
{{ $targetNamespace := .TargetNamespace }}
{{setTargetNamespace .TargetNamespace}}

{{range .SimpleType}}
{{template "SimpleType" .}}
Expand All @@ -108,7 +108,7 @@ var typesTmpl = `
{{/* ComplexTypeLocal */}}
{{with .ComplexType}}
type {{$name | replaceReservedWords | makePublic}} struct {
XMLName xml.Name ` + "`xml:\"{{$targetNamespace}} {{$name}}\"`" + `
XMLName xml.Name ` + "`xml:\"{{getQualifiedName $name}}\"`" + `
{{if ne .ComplexContent.Extension.Base ""}}
{{template "ComplexContent" .ComplexContent}}
{{else if ne .SimpleContent.Extension.Base ""}}
Expand All @@ -133,7 +133,7 @@ var typesTmpl = `
type {{$name}} struct {
{{$typ := findNameByType .Name}}
{{if ne $name $typ}}
XMLName xml.Name ` + "`xml:\"{{$targetNamespace}} {{$typ}}\"`" + `
XMLName xml.Name ` + "`xml:\"{{getQualifiedName $typ}}\"`" + `
{{end}}
{{if ne .ComplexContent.Extension.Base ""}}
{{template "ComplexContent" .ComplexContent}}
Expand All @@ -148,5 +148,8 @@ var typesTmpl = `
{{end}}
}
{{end}}

{{setTargetNamespace ""}}

{{end}}
`