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

xsdgen: Duplicate field names #23

Closed
droyo opened this issue Aug 6, 2017 · 1 comment
Closed

xsdgen: Duplicate field names #23

droyo opened this issue Aug 6, 2017 · 1 comment
Labels

Comments

@droyo
Copy link
Owner

droyo commented Aug 6, 2017

xsdgen does not ensure struct fields for complex types are named uniquely, so generated code for a type with an attribute and element of the same name will not compile. Using a simple xsd like this:

<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.org/">
  <complexType name="myType2">
    <sequence>
      <element name="title" type="string"/>
      <attribute name="title" type="string"/>
    </sequence>
  </complexType>
</schema>

Generates this:

package ws

type MyType2 struct {
	Title string `xml:"title,attr"`
	Title string `xml:"http://example.org/ title"`
}

Which is not valid code. For the attribute/element case in the example, we can append "Attr" to the field name for the attribute. I can't think of other type declarations that would cause this problem, but it's something to be mindful of if we add more support for unions. The relevant portion of the XSD spec is here, I think.

@droyo
Copy link
Owner Author

droyo commented Oct 20, 2017

Fixed with d363344

@droyo droyo closed this as completed Oct 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant