xuri / xgen

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

Add Support for xsd:choice plurality #39

Closed alexandre-normand closed 2 years ago

alexandre-normand commented 2 years ago

PR Details

This adds support for xsd:choice plurality. All elements contained in a xsd:choice now get to be plural if either the element or the containing choice are plural.

Fixes #38.

Description

This adds handling of xsd:choice. It supports choices being enclosed within other choices in order to properly set the plurality of elements. All cases are relatively simple since singular elements get upgraded to plural as soon as one of its containing choice elements is declared as plural or the element itself is plural.

Related Issue

Motivation and Context

I have an xsd that uses choices to basically state that there are multiple occurrences where each occurrence can be of any one type enclosed in that choice. Because xgen doesn't generate any validation code, the only information required to be propagated to the generated code is the correct plurality.

How Has This Been Tested

Added coverage in the base64.xsd, updated the base64.xml example and made sure all tests are passing. Furthermore, I ran xgen on my own real-world use-case and made sure that the generated code would marshal/unmarshal the real-world XML correctly.

Types of changes

Checklist

xuri commented 2 years ago

LGTM, thank your very much.

xuri commented 2 years ago

Hi @alexandre-normand, I've accepted this PR, but this change will cause the xsd:group will be skipped, please try testing with https://github.com/xuri/xsd.

alexandre-normand commented 2 years ago

Hi @alexandre-normand, I've accepted this PR, but this change will cause the xsd:group will be skipped, please try testing with https://github.com/xuri/xsd.

Ah! Sorry about that. I see wsdl.xsd being one of the simpler examples of this and I'm troubleshooting to figure out how I broke this. I'll report back as soon as I figure it out.

alexandre-normand commented 2 years ago

Hi @alexandre-normand, I've accepted this PR, but this change will cause the xsd:group will be skipped, please try testing with https://github.com/xuri/xsd.

Ah! Sorry about that. I see wsdl.xsd being one of the simpler examples of this and I'm troubleshooting to figure out how I broke this. I'll report back as soon as I figure it out.

I think I figured it out. I'll have a PR to fix the regression as well as the PR in https://github.com/xuri/xsd to update the expected outputs with the recent changes.

alexandre-normand commented 2 years ago

Here's the fix: https://github.com/xuri/xgen/pull/40 And the updates to the xsd expected outputs: https://github.com/xuri/xsd/pull/4

Sorry again for the regression I introduced.