-
Notifications
You must be signed in to change notification settings - Fork 19
Support SimpleTypes defined as a union of enums as enums #795
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -179,6 +179,12 @@ public void testUnion() throws IOException { | |
| compareExpectedAndGenerated(expectedRootFolder, "default/union.proto", generatedRootFolder, "default/default.proto"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUnionOfEnums() throws IOException { | ||
| generateProtobufNoOptions("basic/union-of-enums.xsd"); | ||
| compareExpectedAndGenerated(expectedRootFolder, "default/union-of-enums.proto", generatedRootFolder, "default/default.proto"); | ||
| } | ||
|
Comment on lines
+182
to
+186
|
||
|
|
||
| // @Test | ||
| public void testValidationRules() throws IOException { | ||
| generateProtobufNoOptions("basic/validationrules.xsd"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // default.proto at 0:0 | ||
| syntax = "proto3"; | ||
| package default; | ||
|
|
||
| enum Enum1 { | ||
| // Default | ||
| ENUM1_UNSPECIFIED = 0; | ||
| ENUM1_E_1_VAL_1 = 1; | ||
| ENUM1_E_1_VAL_2 = 2; | ||
| } | ||
|
|
||
| enum Enum2 { | ||
| // Default | ||
| ENUM2_UNSPECIFIED = 0; | ||
| ENUM2_E_2_VAL_1 = 1; | ||
| ENUM2_E_2_VAL_2 = 2; | ||
| } | ||
|
|
||
| enum UnionEnumeration { | ||
| // Default | ||
| UNION_ENUMERATION_UNSPECIFIED = 0; | ||
| UNION_ENUMERATION_E_1_VAL_1 = 1; | ||
| UNION_ENUMERATION_E_1_VAL_2 = 2; | ||
| UNION_ENUMERATION_E_2_VAL_1 = 3; | ||
| UNION_ENUMERATION_E_2_VAL_2 = 4; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0"> | ||
|
|
||
| <xsd:simpleType name="UnionEnumeration"> | ||
| <xsd:union memberTypes="Enum1 Enum2"/> | ||
| </xsd:simpleType> | ||
|
|
||
| <xsd:simpleType name="Enum1"> | ||
| <xsd:restriction base="xsd:string"> | ||
| <xsd:enumeration value="e1val1"/> | ||
| <xsd:enumeration value="e1val2"/> | ||
| </xsd:restriction> | ||
| </xsd:simpleType> | ||
|
|
||
| <xsd:simpleType name="Enum2"> | ||
| <xsd:restriction base="xsd:string"> | ||
| <xsd:enumeration value="e2val1"/> | ||
| <xsd:enumeration value="e2val2"/> | ||
| </xsd:restriction> | ||
| </xsd:simpleType> | ||
|
|
||
| </xsd:schema> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
createEnumFromUnionalways adds the generated enum at file scope. If a union-of-enums occurs as a local/anonymous simpleType (e.g., inline on an element), this will create a global enum with a generated name rather than nesting it under the enclosing message (unlikecreateEnum(...)which supportsenclosingType). If local union-of-enums should be supported, consider threading through the enclosing message (or otherwise aligning scoping rules) to avoid polluting the global namespace and to keep naming consistent.