lumeohq / xsd-parser-rs

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

Support for nested sequence fields? #108

Open fusillicode opened 4 years ago

fusillicode commented 4 years ago

Hi sorry for the bother.

I'm facing the following error while trying to generate Rust's structs for the following xsd input.txt (I've changed to extension to .txt to be able to upload the file)

thread 'main' panicked at 'internal error: entered unreachable code:
Error: Element { tag_name: {http://www.w3.org/2001/XMLSchema}sequence, attributes: [Attribute { name: minOccurs, value: "0" }, Attribute { name: maxOccurs, value: "11" }], namespaces: [Namespace { name: Some("xs"), uri: "http://www.w3.org/2001/XMLSchema" }] }
Struct(Struct { name: "Foo", comment: None, fields: RefCell { value: [StructField { name: "Bazs", type_name: "BazsType", comment: None, subtypes: [Struct(Struct { name: "BazsType", comment: None, fields: RefCell { value: [StructField { name: "initialsBaz", type_name: "initialsBazType", comment: None, subtypes: [Enum(Enum { name: "initialsBazType", cases: [EnumCase { name: "Fizz01", comment: None, value: "Fizz01", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz02", comment: None, value: "Fizz02", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz03", comment: None, value: "Fizz03", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz04", comment: None, value: "Fizz04", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz05", comment: None, value: "Fizz05", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz06", comment: None, value: "Fizz06", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz07", comment: None, value: "Fizz07", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz08", comment: None, value: "Fizz08", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz09", comment: None, value: "Fizz09", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz10", comment: None, value: "Fizz10", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz11", comment: None, value: "Fizz11", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz12", comment: None, value: "Fizz12", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz13", comment: None, value: "Fizz13", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz14", comment: None, value: "Fizz14", type_name: None, type_modifiers: [], source: Restriction }, EnumCase { name: "Fizz15", comment: None, value: "Fizz15", type_name: None, type_modifiers: [], source: Restriction }], comment: None, type_name: "xs:string", subtypes: [], source: Restriction })], source: Element, type_modifiers: [None] }] }, subtypes: [] })], source: Element, type_modifiers: [None] }] }, subtypes: [] })', xsd-parser/src/parser/sequence.rs:38:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

By looking at the code it seems that the problem may lie in the presence of nested sequence fields in the xsd input file.

I tried to look inside both the code base and the test suite but I didn't find anything useful to endorse my guess 😞

Obviously do not hesitate to ask for any kind of additional info I may have missed to specify.

fusillicode commented 4 years ago

P.S: I managed to reproduce the problem with a test and I've also tried to implement a fix but I think that it is not quite correct. Here's the draft PR: https://github.com/lumeohq/xsd-parser-rs/pull/109