lumeohq / xsd-parser-rs

A xsd/wsdl => rust code generator written in rust
Apache License 2.0
100 stars 39 forks source link

Anonymous types clash #40

Closed DmitrySamoylov closed 4 years ago

DmitrySamoylov commented 4 years ago

Consider this schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://example.com"
           targetNamespace="http://example.com"
           elementFormDefault="qualified">

    <xs:complexType name="FooType">
        <xs:sequence>
            <xs:element name="Extension">
                <xs:complexType/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="BarType">
        <xs:sequence>
            <xs:element name="Extension">
                <xs:complexType/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>

    <xs:element name="Foo" type="tns:FooType"/>
</xs:schema>

Currently Extension type is generated twice. What if we put it under a separate module:

pub mod foo_type {
    use super::*;

    #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
    #[yaserde(prefix = "tns", namespace = "tns: http://example.com")]
    pub struct Extension {}
}

#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "tns", namespace = "tns: http://example.com")]
pub struct FooType {
    #[yaserde(prefix = "tns", rename = "Min")]
    pub extension: foo_type::Extension,
}

pub mod bar_type {
    use super::*;

    #[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
    #[yaserde(prefix = "tns", namespace = "tns: http://example.com")]
    pub struct Extension {}
}

#[derive(Default, PartialEq, Debug, YaSerialize, YaDeserialize)]
#[yaserde(prefix = "tns", namespace = "tns: http://example.com")]
pub struct BarType {
    #[yaserde(prefix = "tns", rename = "Min")]
    pub extension: bar_type::Extension,
}
DmitrySamoylov commented 4 years ago

Test case (note that it is in a separate branch)

DmitrySamoylov commented 4 years ago

Another case that looks related