diff --git a/gowsdl.go b/gowsdl.go index 6c2ff29..5564fdb 100644 --- a/gowsdl.go +++ b/gowsdl.go @@ -119,9 +119,39 @@ func (g *GoWSDL) Start() (map[string][]byte, error) { return nil, err } + resolveCollisions := map[string]string{} + + // resolve complex type name collision + { + seen := map[string]int{} + for _, schema := range g.wsdl.Types.Schemas { + for _, complexType := range schema.ComplexTypes { + seen[complexType.Name] += 1 + } + } + for k, v := range seen { + if v < 2 { + delete(seen, k) + } + } + for i := range g.wsdl.Types.Schemas { + schema := g.wsdl.Types.Schemas[i] + for j := range schema.ComplexTypes { + complexType := schema.ComplexTypes[j] + if num := seen[complexType.Name]; num > 0 { + org := complexType.Name + update := fmt.Sprintf("%s%d", org, num) + resolveCollisions[fmt.Sprintf("%s/%s", schema.TargetNamespace, org)] = update + complexType.Name = update + seen[org] -= 1 + } + } + } + } + // Process WSDL nodes for _, schema := range g.wsdl.Types.Schemas { - newTraverser(schema, g.wsdl.Types.Schemas).traverse() + newTraverser(schema, g.wsdl.Types.Schemas, resolveCollisions).traverse() } var wg sync.WaitGroup diff --git a/traverser.go b/traverser.go index 207e019..97b2105 100644 --- a/traverser.go +++ b/traverser.go @@ -2,18 +2,21 @@ package gowsdl import ( "encoding/xml" + "fmt" "strings" ) type traverser struct { - c *XSDSchema - all []*XSDSchema + c *XSDSchema + all []*XSDSchema + resolveCollisions map[string]string } -func newTraverser(c *XSDSchema, all []*XSDSchema) *traverser { +func newTraverser(c *XSDSchema, all []*XSDSchema, resolveCollisions map[string]string) *traverser { return &traverser{ - c: c, - all: all, + c: c, + all: all, + resolveCollisions: resolveCollisions, } } @@ -42,6 +45,12 @@ func (t *traverser) traverseElement(elm *XSDElement) { if elm.SimpleType != nil { t.traverseSimpleType(elm.SimpleType) } + { + ref := t.qname(elm.Type) + if updated, ok := t.resolveCollisions[fmt.Sprintf("%s/%s", ref.Space, ref.Local)]; ok { + elm.Type = updated + } + } } func (t *traverser) traverseSimpleType(st *XSDSimpleType) {