Skip to content

Commit 9f93f9a

Browse files
committed
Add literals alongside enums
1 parent 30665ea commit 9f93f9a

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

openapi_python_client/templates/int_enum.py.jinja

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Literal
12
from enum import IntEnum
23

34
class {{ enum.class_info.name }}(IntEnum):
@@ -7,3 +8,10 @@ class {{ enum.class_info.name }}(IntEnum):
78

89
def __str__(self) -> str:
910
return str(self.value)
11+
12+
13+
{{ enum.class_info.name }}Literal = Literal[
14+
{% for _, value in enum.values.items() %}
15+
{{ value }},
16+
{% endfor %}
17+
]

openapi_python_client/templates/str_enum.py.jinja

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from typing import Literal
12
from enum import Enum
23

34
class {{ enum.class_info.name }}(str, Enum):
@@ -7,3 +8,10 @@ class {{ enum.class_info.name }}(str, Enum):
78

89
def __str__(self) -> str:
910
return str(self.value)
11+
12+
13+
{{ enum.class_info.name }}Literal = Literal[
14+
{% for _, value in enum.values|dictsort(true) %}
15+
"{{ value }}",
16+
{% endfor %}
17+
]

0 commit comments

Comments
 (0)