Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for optional element #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

djnalluri
Copy link

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#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.

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

geoko86 and others added 3 commits October 14, 2024 12:30
Signed-off-by: Dheeraj Nalluri <[email protected]>
Signed-off-by: Dheeraj Nalluri <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants