xuri / xgen

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

Types declared at the end of the XSD are not substituted into the generated code #44

Open themaxi opened 2 years ago

themaxi commented 2 years ago

Description Types declared at the end of the XSD are not substituted into the generated code.

XSD file: XSD.txt

Generated file: Gotype.txt

Describe the results you received:

type CField struct {
    Uid            *String36  `xml:"Uid"`
    Name           *String500 `xml:"Name"`
    YStart         int        `xml:"YStart"`
    YEnd           int        `xml:"YEnd"`
    IdCFieldType   int        `xml:"IdCFieldType"`
    IdCFieldStatus int        `xml:"IdCFieldStatus"`
    MaxCount       int        `xml:"MaxCount"`
    NAgree         int        `xml:"NAgree"`
    CDir           int        `xml:"CDir"`
    DateE          string     `xml:"DateE"`
    FormLst        *FormLst   `xml:"FormLst"`
    LevelLst       *LevelLst  `xml:"LevelLst"`
}

Describe the results you expected:

type CField struct {
    Uid            string    `xml:"Uid"`
    Name           string    `xml:"Name"`
    YStart         int       `xml:"YStart"`
    YEnd           int       `xml:"YEnd"`
    IdCFieldType   int       `xml:"IdCFieldType"`
    IdCFieldStatus int       `xml:"IdCFieldStatus"`
    MaxCount       int       `xml:"MaxCount"`
    NAgree         int       `xml:"NAgree"`
    CDir           int       `xml:"CDir"`
    DateE          string    `xml:"DateE"`
    FormLst        *FormLst  `xml:"FormLst"`
    LevelLst       *LevelLst `xml:"LevelLst"`
}

I have made a quick and dirty fix which works for my schemas: https://github.com/themaxi/xgen/commit/2691c989537ab8662a81457d801b5f82d48fb6d5 Generated file: GotypeFix.txt

But I think a more correct and more thoughtful solution should be implemented.

Output of go version:

go version go1.17.6 linux/amd64

xgen version or commit ID:

github.com/xuri/xgen v0.0.0-20220120053031-4e87e56e80f1

Environment details (OS, physical, etc.): Ubuntu 20.04