media-io / xml-schema

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

fix: vec and option complex types #38

Closed borgoat closed 9 months ago

borgoat commented 9 months ago

Hello! I had an issue trying to use this crate to build the DMARC RUA schema (I put in a test for it).

Compilation failed with error:

error[E0412]: cannot find type `Vec` in module `xml_schema_types`
 --> xml_schema/tests/dmarc_rua.rs:7:21
  |
7 |     #[derive(Debug, XmlSchema)]
  |                     ^^^^^^^^^ not found in `xml_schema_types`
  |
  = help: consider importing this struct:
          std::vec::Vec
  = note: this error originates in the derive macro `XmlSchema` (in Nightly builds, run with -Z macro-backtrace for more info)

The error can be tracked to this line in the generated struct:^1

// [...]
pub struct Feedback
    {
        #[yaserde(rename = "report_metadata", prefix = "dmarc")] pub
        report_metadata : xml_schema_types :: ReportMetadataType,
        #[yaserde(rename = "policy_published", prefix = "dmarc")] pub
        policy_published : xml_schema_types :: PolicyPublishedType,
        #[yaserde(rename = "record", prefix = "dmarc")] pub record_list :
        xml_schema_types :: Vec < RecordType >,  // should be Vec<xml_schema_types::RecordType>
    }

The test is still incomplete because I have issues with some types (it looks like it fails to generate structs for <xs:all> elements, but I'd rather take a look at it in a separate PR

MarcAntoine-Arnaud commented 9 months ago

Hi @borgoat , I have reformat and check parsing of the XML in the test.

I have merged on main branch. Thank you for your contribution.

Just in case, please rebase for the next pull request, I have configured the github actions to perform checks and improve code quality.