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

Compilation errors and missing attributes for complex types #17

Open
advolkov opened this issue Aug 5, 2021 · 1 comment
Open

Compilation errors and missing attributes for complex types #17

advolkov opened this issue Aug 5, 2021 · 1 comment

Comments

@advolkov
Copy link

advolkov commented Aug 5, 2021

During some testing on the lib we've faced 2 problems:

Schema example:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:complexType name="ComplexElement">
        <xs:sequence>
            <xs:element name="Element" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>Some annotation</xs:documentation>
                </xs:annotation>
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="info" type="xs:string" minOccurs="0"/>
                    </xs:sequence>
                    <xs:attribute name="attrib" type="xs:string"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

The first problem is compilation errors for the above schema:

error: proc-macro derive panicked
  --> src/main.rs:11:17
   |
11 | #[derive(Debug, XmlSchema)]
   |                 ^^^^^^^^^
   |
   = help: message: not implemented
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `Element: YaDeserialize` is not satisfied
   --> src/main.rs:11:17
    |
11  | #[derive(Debug, XmlSchema)]
    |                 ^^^^^^^^^ the trait `YaDeserialize` is not implemented for `Element`
    | 
    |
101 |   fn deserialize<R: Read>(reader: &mut de::Deserializer<R>) -> Result<Self, String>;
    |                     ---- required by this bound in `deserialize`
    |
    = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)

Another problem seems it ignores attributes for complex types. For the schema above if I set store_generated_code, I see the following output:

#[derive(Clone, Debug, Default, PartialEq, YaDeserialize, YaSerialize)] 
pub struct ComplexElement
{ 
  #[yaserde(rename = "Element")] 
  pub element : Option < Element >, 
}
#[doc = "Some annotation"]
#[derive(Clone, Debug, Default, PartialEq, YaDeserialize, YaSerialize)] 
pub struct Element
{ 
  #[yaserde(rename = "info")] 
  pub infos : Option < Vec < String > >, 
}

There is no attribute attrib in Element.

Also, I've found this problem in the existing test (https://github.com/media-io/xml-schema/blob/master/xml_schema/tests/complex_type.rs): attribute scope is missing.

@RcusStackwalker
Copy link

The first problem with "proc-macro derive panicked" is actually a panic inside YaDeserialize for Option<Vec<..>>.
It was reported before for this package #4
Similar issue reported there media-io/yaserde#49 .
The fix imo would be for yaserde to provide more information in unimplemented! macro call

Root cause for this problem is incorrect handling of maxOccurs element attribute. It's not actually handled at all, even for missing maxOccurs it' still 1. #13 - this ticket's author suggested a solution.

Correct implementation should generate
pub info : Option < String >
in this case.

As for the second problem, it's connected to the first one: this package handles nested compleType's differently than top-level

    <xs:complexType name="ElementType">
        <xs:annotation>
            <xs:documentation>Some annotation</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="info" type="xs:string" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute name="attrib" type="xs:string"/>
    </xs:complexType>
    <xs:complexType name="ComplexElement">
        <xs:sequence>
            <xs:element name="Element" minOccurs="0" type="ElementType"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Will produce

#[doc = "Some annotation"]
#[derive(Clone, Debug, Default, PartialEq, YaDeserialize, YaSerialize)] pub
struct ElementType
{
    #[yaserde(rename = "info")] pub info : Option < String >,
    #[yaserde(attribute)] pub attrib : Option < String >,
} #[derive(Clone, Debug, Default, PartialEq, YaDeserialize, YaSerialize)] pub
struct ComplexElement
{ #[yaserde(rename = "Element")] pub element : Option < ElementType >, }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants