Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Nett committed Aug 23, 2024
1 parent a193ea3 commit e932368
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion pkg/xsd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,22 @@ func (sch *Schema) encodingXmlImportNeeded() bool {
return len(sch.Elements) != 0 || len(sch.ComplexTypes) != 0
}

func deduplicateElementsLossfree(elements []Element) []Element {
seen := make(map[string]int, len(elements))
for j, element := range elements {
dupeCount, dupe := seen[element.GoName()]
if !dupe {
seen[element.GoName()] = 1
continue
}
elements[j].nameOverride = fmt.Sprintf("%s-%d", element.GoName(), dupeCount)
seen[element.GoName()]++
}
return elements
}

func (sch *Schema) ExportableElements() []Element {
return append(sch.Elements, sch.inlinedElements...)
return deduplicateElementsLossfree(append(sch.Elements, sch.inlinedElements...))
}

func (sch *Schema) ExportableComplexTypes() []ComplexType {
Expand Down
2 changes: 1 addition & 1 deletion tests/xsd-examples/valid/issue129.xsd.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type List struct {
}

// Element
type List struct {
type List1 struct {
XMLName xml.Name `xml:"List"`

Ddd []int `xml:",any"`
Expand Down

0 comments on commit e932368

Please sign in to comment.