Repository: tefra/xsdata (python)

Issue:
Keep the same "case" in the class names
At this moment it seems that xsData is transforming the casing of an element to something "pythonish" would it be possible to keep the "original" element casing as it matches the casing in the XML Schema and obviously the XML itself? 

Pull request description:
Fix OriginalCase for field name transformations
Resolves #498 

Patch:
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 363e70cb..bf84beb7 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -2,7 +2,7 @@ exclude: tests/fixtures
 
 repos:
   - repo: https://github.com/asottile/pyupgrade
-    rev: v2.18.1
+    rev: v2.18.3
     hooks:
       - id: pyupgrade
         args: [--py37-plus]
diff --git a/xsdata/formats/dataclass/models/elements.py b/xsdata/formats/dataclass/models/elements.py
index df8d0fa6..5afc0ade 100644
--- a/xsdata/formats/dataclass/models/elements.py
+++ b/xsdata/formats/dataclass/models/elements.py
@@ -67,7 +67,6 @@ class XmlVar(MetaMixin):
         "sequential",
         "list_element",
         "default",
-        "xml_type",
         "namespaces",
         "elements",
         "wildcards",
@@ -150,7 +149,6 @@ class XmlVar(MetaMixin):
         self.clazz = collections.first(tp for tp in types if is_dataclass(tp))
         self.is_clazz_union = self.clazz and len(types) > 1
         self.local_name = local_name(qname)
-        self.xml_type = xml_type
 
         self.is_text = False
         self.is_element = False
diff --git a/xsdata/models/config.py b/xsdata/models/config.py
index 182b35a2..83eda2ed 100644
--- a/xsdata/models/config.py
+++ b/xsdata/models/config.py
@@ -19,7 +19,6 @@ from xsdata.formats.dataclass.serializers.writers import XmlEventWriter
 from xsdata.models.mixins import array_element
 from xsdata.models.mixins import attribute
 from xsdata.models.mixins import element
-from xsdata.utils import constants
 from xsdata.utils import text
 
 
@@ -94,7 +93,7 @@ class NameCase(Enum):
 
 
 __name_case_func__: Dict[str, Callable] = {
-    "originalCase": constants.return_input,
+    "originalCase": text.original_case,
     "pascalCase": text.pascal_case,
     "camelCase": text.camel_case,
     "snakeCase": text.snake_case,
diff --git a/xsdata/utils/text.py b/xsdata/utils/text.py
index a221ae4c..164a2286 100644
--- a/xsdata/utils/text.py
+++ b/xsdata/utils/text.py
@@ -32,6 +32,11 @@ def capitalize(value: str, **kwargs: Any) -> str:
     return value[0].upper() + value[1:]
 
 
+def original_case(value: str, **kwargs: Any) -> str:
+    """Return the input string without any modifications."""
+    return value
+
+
 def pascal_case(value: str, **kwargs: Any) -> str:
     """Convert the given string to pascal case."""
     return "".join(map(str.title, split_words(value)))


Test patch:
diff --git a/tests/utils/test_text.py b/tests/utils/test_text.py
index 047d253d..a5b8d0e4 100644
--- a/tests/utils/test_text.py
+++ b/tests/utils/test_text.py
@@ -7,6 +7,7 @@ from xsdata.utils.text import kebab_case
 from xsdata.utils.text import mixed_case
 from xsdata.utils.text import mixed_pascal_case
 from xsdata.utils.text import mixed_snake_case
+from xsdata.utils.text import original_case
 from xsdata.utils.text import pascal_case
 from xsdata.utils.text import screaming_snake_case
 from xsdata.utils.text import snake_case
@@ -14,7 +15,19 @@ from xsdata.utils.text import split_words
 
 
 class TextTests(TestCase):
+    def test_original_case(self):
+        self.assertEqual("p00p", original_case("p00p", foobar=True))
+        self.assertEqual("p00p", original_case("p00p"))
+        self.assertEqual("USERName", original_case("USERName"))
+        self.assertEqual("UserNAME", original_case("UserNAME"))
+        self.assertEqual("USER_name", original_case("USER_name"))
+        self.assertEqual("USER-NAME", original_case("USER-NAME"))
+        self.assertEqual("User_Name", original_case("User_Name"))
+        self.assertEqual("user_name", original_case("user_name"))
+        self.assertEqual("SUserNAME", original_case("SUserNAME"))
+
     def test_snake_case(self):
+        self.assertEqual("p00p", snake_case("p00p", foobar=True))
         self.assertEqual("p00p", snake_case("p00p"))
         self.assertEqual("username", snake_case("USERName"))
         self.assertEqual("user_name", snake_case("UserNAME"))
@@ -25,6 +38,7 @@ class TextTests(TestCase):
         self.assertEqual("suser_name", snake_case("SUserNAME"))
 
     def test_screaming_snake_case(self):
+        self.assertEqual("P00P", screaming_snake_case("p00p", foobar=True))
         self.assertEqual("P00P", screaming_snake_case("p00p"))
         self.assertEqual("USERNAME", screaming_snake_case("USERName"))
         self.assertEqual("USER_NAME", screaming_snake_case("UserNAME"))
@@ -35,6 +49,7 @@ class TextTests(TestCase):
         self.assertEqual("SUSER_NAME", screaming_snake_case("SUserNAME"))
 
     def test_pascal_case(self):
+        self.assertEqual("P00P", pascal_case("p00p", foobar=True))
         self.assertEqual("P00P", pascal_case("p00p"))
         self.assertEqual("Username", pascal_case("USERName"))
         self.assertEqual("UserName", pascal_case("UserNAME"))
@@ -45,6 +60,7 @@ class TextTests(TestCase):
         self.assertEqual("SuserName", pascal_case("SUserNAME"))
 
     def test_camel_case(self):
+        self.assertEqual("p00P", camel_case("p00p", foobar=True))
         self.assertEqual("p00P", camel_case("p00p"))
         self.assertEqual("username", camel_case("USERName"))
         self.assertEqual("userName", camel_case("UserNAME"))
@@ -55,6 +71,7 @@ class TextTests(TestCase):
         self.assertEqual("suserName", camel_case("SUserNAME"))
 
     def test_mixed_case(self):
+        self.assertEqual("p00p", mixed_case("p00p", foobar=True))
         self.assertEqual("p00p", mixed_case("p00p"))
         self.assertEqual("USERName", mixed_case("USERName"))
         self.assertEqual("UserNAME", mixed_case("UserNAME"))
@@ -65,6 +82,7 @@ class TextTests(TestCase):
         self.assertEqual("SUserNAME", mixed_case("SUserNAME"))
 
     def test_mixed_pascal_case(self):
+        self.assertEqual("P00p", mixed_pascal_case("p00p", foobar=True))
         self.assertEqual("P00p", mixed_pascal_case("p00p"))
         self.assertEqual("USERName", mixed_pascal_case("USERName"))
         self.assertEqual("UserNAME", mixed_pascal_case("UserNAME"))
@@ -75,6 +93,7 @@ class TextTests(TestCase):
         self.assertEqual("SUserNAME", mixed_pascal_case("SUserNAME"))
 
     def test_mixed_snake_case(self):
+        self.assertEqual("p00p", mixed_snake_case("p00p", foobar=True))
         self.assertEqual("p00p", mixed_snake_case("p00p"))
         self.assertEqual("USERName", mixed_snake_case("USERName"))
         self.assertEqual("User_NAME", mixed_snake_case("UserNAME"))
@@ -85,6 +104,7 @@ class TextTests(TestCase):
         self.assertEqual("SUser_NAME", mixed_snake_case("SUserNAME"))
 
     def test_kebab_case(self):
+        self.assertEqual("p00p", kebab_case("p00p", foobar=True))
         self.assertEqual("p00p", kebab_case("p00p"))
         self.assertEqual("USERName", kebab_case("USERName"))
         self.assertEqual("User-NAME", kebab_case("UserNAME"))