-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add Support for XSD Extensions #36
Add Support for XSD Extensions #36
Conversation
@xuri : I did a few more things here that I've kept as separate commits because I could see the argument for spinning those off into their own PRs. Let me go through those things:
Let me know if you'd like me to create a separate PR for those testing improvements (at least, they seem like improvements to me?) before I move on to the rest of this PR. Otherwise, back to the main goal of this PR, I'd like some guidance on the missing changes to the C generator. I've done C a long time ago but I don't think I've ever done XML marshaling/unmarshaling in C so I'm a bit lost as to how those generated C structs can be used. Is there a common XML library that can marshal structs into XML? I'm just wondering where to look to find out how the generated C code would end up being used by developers using xgen to generate C. I looked at libxml2 as it came up as a popular one but didn't seem to find how it would use structs for parsing/encoding. Thanks! |
Thanks for your PR, I was motivated by generated C code which can be used for some custom parser based on libxml2, or others ASN.1 module. I'll accept this change, could you squash the commits and refine the commit message, you can copy the description of the PR to the squashed commit in this case. |
Adds support for two cases of xsd extensions: - Extending a built-in type - Extending a complex type The supported languages for the extension support are Java, Typescript, Rust and Go. C is not yet supported. Details on each implentation: * Go: The generated code uses struct embedding. the base64 example has been modified to include both supported extension cases and the tests were modified to show the new expected output. * Rust: Children types extending a parent type declare a field of that parent type with serde(flatten). * Java: Uses classic inheritance. * TypeScript: Similar as the Java version, it uses inheritance. To make development easier, parser tests were updated to assert on the content of the expected output rather than just the length. This made it easier to view the differences and I actually started with what the desired expected output should be before the implementation. In order to make the tests stable, the generation was updated to sort members and make that unstable part of the generation now be stable. Fixes issue xuri#7. Signed-off-by: Alex Normand <alexandre.normand@gmail.com>
a89f282
to
5fd092f
Compare
Thanks for the review, @xuri ! I squashed all commits and included the summary of each language's implementation in that commit. I also submitted a PR on the xsd repo to update the tests. The generated code should be stable now. The members were previously unsorted but I applied a sort so we could have stable tests asserting on the content. |
Cool, thank you for carrying this across the finish line! |
PR Details
This builds on the work from @BatmanAoD in #18 (thanks again for doing all that work!) but also considers the case where an extension is used to extend another type. I was motivated by having this very case in one of the XSD I'm working with but I also wanted to support the case described in issue #7.
Description
I can't say this PR is complete because I'm not sure how to implement the feature in the C version. Are there any references/links on typical libs that C programmers would use to generate XML from their structs? I've implemented the feature in the other languages (Typescript, Java, Rust and Go) with my main interest/expertise being in the Go one but I could use guidance to complete the work on the C variant.
Some details regarding the case of extending a complex type:
To make development easier, I updated the parser tests to assert on the content of the expected output rather than just the length. This made it easier to view the differences and I actually started with what the desired expected output should be before the implementation.
Related Issue
This fixes issue #7 although it covers the other common case for extensions (extending other complex types).
Motivation and Context
Currently, XSD extensions aren't supported. I'm not sure how generally commonly used they are but I have one use case with the Microsoft ShowPlan XSD that uses extensions heavily to define elements and attributes in base types that are then extended in children types.
How Has This Been Tested
Added to the
base64.xsd
example to showcase the simple cases and ran through a more complex real-world example where I used the generated go structs and then parsed some real XML for that matching xsd.Types of changes
Checklist