media-io / xml-schema

Generate rust code (structures and enum) from XSD
MIT License
53 stars 29 forks source link

Avoid collision between elements and types #11

Closed dodomorandi closed 1 year ago

dodomorandi commented 4 years ago

Take the following XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test.test/">
  <xs:element name="hello" type="hello"/>
  <xs:complexType name="hello">
    <xs:all>
      <xs:element name="world">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="test1" minOccurs="0" type="xs:string"/>
            <xs:element name="test2" minOccurs="0" type="xs:int"/>
            <xs:element name="test3" minOccurs="0" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:all>
  </xs:complexType>
</xs:schema>

hello is both an element and a type, and AFAIK this is valid XSD. Unfortunately xml-schema-derive tries to create Hello two times in the same module, causing the proc_macro to panic.

Maybe the simplest thing would be to put all types in a pub mod types to avoid collisions, but this would also be a breaking change. What do you think?