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

Extra underscores when XSD elements use upper underscore #667

Open
wardev opened this issue Nov 20, 2024 · 0 comments
Open

Extra underscores when XSD elements use upper underscore #667

wardev opened this issue Nov 20, 2024 · 0 comments

Comments

@wardev
Copy link

wardev commented Nov 20, 2024

With 1.97 I have a <xsd:element name="COMMENT" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/> that gets turned into repeated string c_o_m_m_e_n_t, but I would expect repeated string comment.

Looks like the current code assumes element names are in camel case. Here is a patch to use getCaseFormatName(...) to figure out which case convention is used. I changed \w+ to \w* so that names like abc3 are treated as camel case.

diff --git a/schema2proto-lib/src/main/java/no/entur/schema2proto/generateproto/ProtoSerializer.java b/schema2proto-lib/src/main/java/no/entur/schema2proto/generateproto/ProtoSerializer.java
index 2b5cc93..1272253 100644
--- a/schema2proto-lib/src/main/java/no/entur/schema2proto/generateproto/ProtoSerializer.java
+++ b/schema2proto-lib/src/main/java/no/entur/schema2proto/generateproto/ProtoSerializer.java
@@ -565,13 +565,13 @@ public class ProtoSerializer {
                        }
                } else {
                        if (Character.isLowerCase(s.charAt(0))) {
-                               if (s.matches("([a-z]+[A-Z0-9]+\\w+)+")) {
+                               if (s.matches("([a-z]+[A-Z0-9]+\\w*)+")) {
                                        return CaseFormat.LOWER_CAMEL;
                                } else if (s.matches("[a-z]+")) {
                                        return CaseFormat.LOWER_UNDERSCORE;
                                }
                        } else {
-                               if (s.matches("([A-Z]+[a-z0-9]+\\w+)+")) {
+                               if (s.matches("([A-Z]+[a-z0-9]+\\w*)+")) {
                                        return CaseFormat.UPPER_CAMEL;
                                } else if (s.matches("[A-Z]+")) {
                                        return CaseFormat.UPPER_UNDERSCORE;
@@ -1158,7 +1158,7 @@ public class ProtoSerializer {
 
                        String strippedFieldName = StringUtils.removeEnd(StringUtils.removeStart(fieldName, UNDERSCORE), UNDERSCORE);
 
-                       String newFieldName = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, strippedFieldName);
+                       String newFieldName = getCaseFormatName(strippedFieldName).to(CaseFormat.LOWER_UNDERSCORE, strippedFieldName);
 
                        // Remove all dashes
                        newFieldName = StringUtils.remove(newFieldName, DASH);
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

No branches or pull requests

1 participant