Repository: koxudaxi/datamodel-code-generator

Issue:
capitalize-enum-member not working with use-subclass-enum  and snake-case-field when typed enum
              the problem is still there for 0.30.1 when using `--use-subclass-enum  --capitalize-enum-member  --snake-case-field` 
the fields are not capitalized when both subclass and snake case are used.

_Originally posted by @ant31 in https://github.com/koxudaxi/datamodel-code-generator/issues/2389#issuecomment-2842568539_
            


Discussion:
```yaml
openapi: 3.0.3
info:
  version: X.Y.Z
  title: example schema
servers:
  - url: "https://acme.org"
paths: {}
components:
  schemas:
    EnumSystems:
      type: string
      enum:
        - linux
        - osx
        - windows
 ```
with `--output-model-type "pydantic_v2.BaseModel" --disable-timestamp --capitalise-enum-members --snake-case-field --use-subclass-enum` produces:
```python
Generated output:
# generated by datamodel-codegen:
#   filename:  myschema.yaml

from __future__ import annotations

from enum import Enum

from pydantic import Field


class EnumSystems(str, Enum):
    linux = 'linux'
    osx = 'osx'
    windows = 'windows'
```

but it should produce:
```python
Generated output:
# generated by datamodel-codegen:
#   filename:  myschema.yaml

from __future__ import annotations

from enum import Enum


class EnumSystems(str, Enum):
    LINUX = 'linux'
    OSX = 'osx'
    WINDOWS = 'windows'
```



Patch:
diff --git a/src/datamodel_code_generator/parser/base.py b/src/datamodel_code_generator/parser/base.py
index 413e56981..cd32c1517 100644
--- a/src/datamodel_code_generator/parser/base.py
+++ b/src/datamodel_code_generator/parser/base.py
@@ -1135,7 +1135,7 @@ def __change_field_name(
         if self.data_model_type != pydantic_model_v2.BaseModel:
             return
         for model in models:
-            if model.base_class == "Enum":
+            if "Enum" in model.base_class:
                 continue
 
             for field in model.fields:


Test patch:
diff --git a/tests/test_main_kr.py b/tests/test_main_kr.py
index 197f3c015..a5a42749b 100644
--- a/tests/test_main_kr.py
+++ b/tests/test_main_kr.py
@@ -362,3 +362,62 @@ class EnumSystems(Enum):
     assert output_file_read_text == expected_output, (
         f"\nExpected  output:\n{expected_output}\n\nGenerated output:\n{output_file_read_text}"
     )
+
+
+def test_capitalise_enum_members_and_use_subclass_enum(tmp_path: Path) -> None:
+    """Combination of capitalise-enum-members and use-subclass-enum not working since v0.28.5
+
+    From https://github.com/koxudaxi/datamodel-code-generator/issues/2395
+    """
+    input_data = """
+openapi: 3.0.3
+info:
+  version: X.Y.Z
+  title: example schema
+servers:
+  - url: "https://acme.org"
+paths: {}
+components:
+  schemas:
+    EnumSystems:
+      type: string
+      enum:
+        - linux
+        - osx
+        - windows
+"""
+    input_file = tmp_path / "myschema.yaml"
+    input_file.write_text(input_data, encoding="utf_8")
+
+    expected_output = """# generated by datamodel-codegen:
+#   filename:  myschema.yaml
+
+from __future__ import annotations
+
+from enum import Enum
+
+
+class EnumSystems(str, Enum):
+    LINUX = 'linux'
+    OSX = 'osx'
+    WINDOWS = 'windows'
+"""
+
+    output_file: Path = tmp_path / "output.py"
+    return_code: Exit = main([
+        "--output-model-type",
+        "pydantic_v2.BaseModel",
+        "--disable-timestamp",
+        "--capitalise-enum-members",
+        "--snake-case-field",
+        "--use-subclass-enum",
+        "--input",
+        str(input_file),
+        "--output",
+        str(output_file),
+    ])
+    assert return_code == Exit.OK
+    output_file_read_text = output_file.read_text(encoding="utf_8")
+    assert output_file_read_text == expected_output, (
+        f"\nExpected  output:\n{expected_output}\n\nGenerated output:\n{output_file_read_text}"
+    )