xuri / xgen

XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
BSD 3-Clause "New" or "Revised" License
305 stars 69 forks source link

xs:choise looses some of the chooses. #42

Open zadeck opened 2 years ago

zadeck commented 2 years ago

Description Under certain conditions, some of the choices in an xs:choice do not get generated. In the enclosed example, there is on a6 field in the generated go code. This bug is subtle!!! If you remove the input for the "d" attribute from the source file, it will generate all 6 of the a elements.

Steps to reproduce the issue:

  1. Run xgen with the go output option on the test case.
  2. save the output
  3. Remove the code for the d attribute from the test case and rerun. here is the input to use

    <?xml version="1.0" encoding="UTF-8"?>

============= Describe the results you received: // Code generated by xgen. DO NOT EDIT.

package test1

import ( "encoding/xml" )

// E ... type E struct { XMLName xml.Name xml:"e" DAttr string xml:"d,attr" A1 []A1 xml:"a1" A2 []A2 xml:"a2" A3 []A3 xml:"a3" A4 []A4 xml:"a4" A5 []*A5 xml:"a5" E string xml:"e" }

// A1 ... type A1 struct { XMLName xml.Name xml:"a1" NAttr string xml:"n,attr" }

// A2 ... type A2 struct { XMLName xml.Name xml:"a2" NAttr string xml:"n,attr" }

// A3 ... type A3 struct { XMLName xml.Name xml:"a3" NAttr string xml:"n,attr" }

// A4 ... type A4 struct { XMLName xml.Name xml:"a4" NAttr string xml:"n,attr" }

// A5 ... type A5 struct { XMLName xml.Name xml:"a5" NAttr string xml:"n,attr" }

// A6 ... type A6 struct { XMLName xml.Name xml:"a6" NAttr string xml:"n,attr" }

Describe the results you expected: // Code generated by xgen. DO NOT EDIT.

package test1

import ( "encoding/xml" )

// E ... type E struct { XMLName xml.Name xml:"e" DAttr string xml:"d,attr" A1 []A1 xml:"a1" A2 []A2 xml:"a2" A3 []A3 xml:"a3" A4 []A4 xml:"a4" A5 []A5 xml:"a5" A6 []A6 xml:"a6" E string xml:"e" }

// A1 ... type A1 struct { XMLName xml.Name xml:"a1" NAttr string xml:"n,attr" }

// A2 ... type A2 struct { XMLName xml.Name xml:"a2" NAttr string xml:"n,attr" }

// A3 ... type A3 struct { XMLName xml.Name xml:"a3" NAttr string xml:"n,attr" }

// A4 ... type A4 struct { XMLName xml.Name xml:"a4" NAttr string xml:"n,attr" }

// A5 ... type A5 struct { XMLName xml.Name xml:"a5" NAttr string xml:"n,attr" }

// A6 ... type A6 struct { XMLName xml.Name xml:"a6" NAttr string xml:"n,attr" }

Output of go version: xgen version: 0.1.0

(paste your output here)

xgen version or commit ID:

(paste here)

Environment details (OS, physical, etc.): ubuntu 20.04 x86-64

zadeck commented 2 years ago

please change choise to choice. Sorry.