diff --git a/openapi_python_client/templates/int_enum.py.jinja b/openapi_python_client/templates/int_enum.py.jinja index a508f1c8e..a20390daa 100644 --- a/openapi_python_client/templates/int_enum.py.jinja +++ b/openapi_python_client/templates/int_enum.py.jinja @@ -1,3 +1,4 @@ +from typing import Literal from enum import IntEnum class {{ enum.class_info.name }}(IntEnum): @@ -7,3 +8,10 @@ class {{ enum.class_info.name }}(IntEnum): def __str__(self) -> str: return str(self.value) + + +{{ enum.class_info.name }}Literal = Literal[ + {% for _, value in enum.values.items() %} + {{ value }}, + {% endfor %} +] diff --git a/openapi_python_client/templates/str_enum.py.jinja b/openapi_python_client/templates/str_enum.py.jinja index e0da5ed0f..b095d717c 100644 --- a/openapi_python_client/templates/str_enum.py.jinja +++ b/openapi_python_client/templates/str_enum.py.jinja @@ -1,3 +1,4 @@ +from typing import Literal from enum import Enum class {{ enum.class_info.name }}(str, Enum): @@ -7,3 +8,10 @@ class {{ enum.class_info.name }}(str, Enum): def __str__(self) -> str: return str(self.value) + + +{{ enum.class_info.name }}Literal = Literal[ + {% for _, value in enum.values|dictsort(true) %} + "{{ value }}", + {% endfor %} +]