Skip to content

Commit

Permalink
Fix alias modular default enum member (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi authored Oct 31, 2022
1 parent ddee5d9 commit 8183a29
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 1 addition & 3 deletions datamodel_code_generator/model/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions tests/data/jsonschema/modular_default_enum_member/foo.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"properties": {
"loggerLevel": {
"$ref": "bar.json#/definitions/logLevels"
},
"AnotherLoggerLevel": {
"$ref": "nested_bar/bar.json#/definitions/logLevels"
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

0 comments on commit 8183a29

Please sign in to comment.