diff --git a/datamodel_code_generator/model/enum.py b/datamodel_code_generator/model/enum.py index 8b76c0352..a1fac06df 100644 --- a/datamodel_code_generator/model/enum.py +++ b/datamodel_code_generator/model/enum.py @@ -94,6 +94,4 @@ def __init__(self, enum: Enum, field: DataModelFieldBase) -> None: self.alias: Optional[str] = None def __repr__(self) -> str: - if self.alias: - return self.alias - return f'{self.enum.name}.{self.field.name}' + return f'{self.alias or self.enum.name}.{self.field.name}' diff --git a/tests/data/expected/main/main_jsonschema_modular_default_enum_member/foo.py b/tests/data/expected/main/main_jsonschema_modular_default_enum_member/foo.py index b947269ab..056dda003 100644 --- a/tests/data/expected/main/main_jsonschema_modular_default_enum_member/foo.py +++ b/tests/data/expected/main/main_jsonschema_modular_default_enum_member/foo.py @@ -9,7 +9,9 @@ from pydantic import BaseModel from . import bar +from .nested_bar import bar as bar_1 class Foo(BaseModel): - loggerLevel: Optional[bar.LogLevels] = bar.LogLevels + loggerLevel: Optional[bar.LogLevels] = bar.LogLevels.INFO + AnotherLoggerLevel: Optional[bar_1.LogLevels] = bar_1.LogLevels.ERROR diff --git a/tests/data/jsonschema/modular_default_enum_member/foo.json b/tests/data/jsonschema/modular_default_enum_member/foo.json index ead46196d..a6e2a335a 100644 --- a/tests/data/jsonschema/modular_default_enum_member/foo.json +++ b/tests/data/jsonschema/modular_default_enum_member/foo.json @@ -6,6 +6,9 @@ "properties": { "loggerLevel": { "$ref": "bar.json#/definitions/logLevels" + }, + "AnotherLoggerLevel": { + "$ref": "nested_bar/bar.json#/definitions/logLevels" } } } \ No newline at end of file diff --git a/tests/data/jsonschema/modular_default_enum_member/nested_bar/bar.json b/tests/data/jsonschema/modular_default_enum_member/nested_bar/bar.json new file mode 100644 index 000000000..bf9956e81 --- /dev/null +++ b/tests/data/jsonschema/modular_default_enum_member/nested_bar/bar.json @@ -0,0 +1,14 @@ +{ + "$id": "nested_bar/bar.json", + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "NestedBar", + "type": "object", + "definitions": { + "logLevels": { + "description": "Supported logging levels Nested Model", + "type": "string", + "enum": ["DEBUG", "INFO", "ERROR"], + "default": "ERROR" + } + } +} \ No newline at end of file