Adds support for optional elements where minOccurs=0.
Description
At present, elements have an Optional field that is never set during XSD parsing. This PR sets the field and adds support for it to the Go generator. The Rust generator already has it implemented.
Credit goes to geoko86 for the fix. I cherry-picked the commit from this PR: geoko86/xgen#1
Related Issue
47
Motivation and Context
XSD provides a way to express a tag that can be omitted without breaking the spec. That freedom does not make it into the generated code as it tends to always include tags whether or not they have been initialized.
How Has This Been Tested
I tested this code on a Linux system using the existing test cases in this repository. The TopLevel element includes an optional element with minOccurs="0" maxOccurs="1". The test's expected values however don't respect the minOccurs. The tests broke after making this change and worked again after changing the Go and Rust expected results to use their respective representations for optional elements.
I have also tested the Go code generated from a proprietary schema and verified that, after serializing the generated models, empty tags are no longer included.
PR Details
Adds support for optional elements where
minOccurs=0
.Description
At present, elements have an
Optional
field that is never set during XSD parsing. This PR sets the field and adds support for it to the Go generator. The Rust generator already has it implemented.Credit goes to geoko86 for the fix. I cherry-picked the commit from this PR: geoko86/xgen#1
Related Issue
47
Motivation and Context
XSD provides a way to express a tag that can be omitted without breaking the spec. That freedom does not make it into the generated code as it tends to always include tags whether or not they have been initialized.
How Has This Been Tested
I tested this code on a Linux system using the existing test cases in this repository. The
TopLevel
element includes an optional element withminOccurs="0" maxOccurs="1"
. The test's expected values however don't respect theminOccurs
. The tests broke after making this change and worked again after changing the Go and Rust expected results to use their respective representations for optional elements.I have also tested the Go code generated from a proprietary schema and verified that, after serializing the generated models, empty tags are no longer included.
Types of changes
Checklist