From c9e569c52e2392f484a584c91bb02fd705e23714 Mon Sep 17 00:00:00 2001 From: Packy Gallagher Date: Fri, 4 Dec 2020 15:59:49 -0800 Subject: [PATCH 1/2] Implement __str__ for enum props to fix conversion to query string --- openapi_python_client/templates/int_enum.pyi | 3 +++ openapi_python_client/templates/str_enum.pyi | 3 +++ 2 files changed, 6 insertions(+) diff --git a/openapi_python_client/templates/int_enum.pyi b/openapi_python_client/templates/int_enum.pyi index 7b8904e65..18d6066ae 100644 --- a/openapi_python_client/templates/int_enum.pyi +++ b/openapi_python_client/templates/int_enum.pyi @@ -4,3 +4,6 @@ class {{ enum.reference.class_name }}(IntEnum): {% for key, value in enum.values.items() %} {{ key }} = {{ value }} {% endfor %} + + def __str__(self) -> str: + return str(self.value) diff --git a/openapi_python_client/templates/str_enum.pyi b/openapi_python_client/templates/str_enum.pyi index 4c7f97f89..74dcd1de2 100644 --- a/openapi_python_client/templates/str_enum.pyi +++ b/openapi_python_client/templates/str_enum.pyi @@ -4,3 +4,6 @@ class {{ enum.reference.class_name }}(str, Enum): {% for key, value in enum.values.items() %} {{ key }} = "{{ value }}" {% endfor %} + + def __str__(self) -> str: + return str(self.value) From 73eed97ebacaaa10040ed5cc3171d3cc3c292886 Mon Sep 17 00:00:00 2001 From: Packy Gallagher Date: Fri, 4 Dec 2020 16:03:58 -0800 Subject: [PATCH 2/2] Update golden record --- .../golden-record-custom/custom_e2e/models/an_enum.py | 3 +++ .../golden-record-custom/custom_e2e/models/an_int_enum.py | 3 +++ .../golden-record-custom/custom_e2e/models/different_enum.py | 3 +++ .../golden-record/my_test_api_client/models/an_enum.py | 3 +++ .../golden-record/my_test_api_client/models/an_int_enum.py | 3 +++ .../golden-record/my_test_api_client/models/different_enum.py | 3 +++ 6 files changed, 18 insertions(+) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/an_enum.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/an_enum.py index 9616ca82e..c266d0763 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/an_enum.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/an_enum.py @@ -4,3 +4,6 @@ class AnEnum(str, Enum): FIRST_VALUE = "FIRST_VALUE" SECOND_VALUE = "SECOND_VALUE" + + def __str__(self) -> str: + return str(self.value) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/an_int_enum.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/an_int_enum.py index 6048add0f..d7d7a713d 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/an_int_enum.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/an_int_enum.py @@ -5,3 +5,6 @@ class AnIntEnum(IntEnum): VALUE_NEGATIVE_1 = -1 VALUE_1 = 1 VALUE_2 = 2 + + def __str__(self) -> str: + return str(self.value) diff --git a/end_to_end_tests/golden-record-custom/custom_e2e/models/different_enum.py b/end_to_end_tests/golden-record-custom/custom_e2e/models/different_enum.py index 00357ab7a..6c167f25c 100644 --- a/end_to_end_tests/golden-record-custom/custom_e2e/models/different_enum.py +++ b/end_to_end_tests/golden-record-custom/custom_e2e/models/different_enum.py @@ -4,3 +4,6 @@ class DifferentEnum(str, Enum): DIFFERENT = "DIFFERENT" OTHER = "OTHER" + + def __str__(self) -> str: + return str(self.value) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_enum.py b/end_to_end_tests/golden-record/my_test_api_client/models/an_enum.py index 9616ca82e..c266d0763 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_enum.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/an_enum.py @@ -4,3 +4,6 @@ class AnEnum(str, Enum): FIRST_VALUE = "FIRST_VALUE" SECOND_VALUE = "SECOND_VALUE" + + def __str__(self) -> str: + return str(self.value) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/an_int_enum.py b/end_to_end_tests/golden-record/my_test_api_client/models/an_int_enum.py index 6048add0f..d7d7a713d 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/an_int_enum.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/an_int_enum.py @@ -5,3 +5,6 @@ class AnIntEnum(IntEnum): VALUE_NEGATIVE_1 = -1 VALUE_1 = 1 VALUE_2 = 2 + + def __str__(self) -> str: + return str(self.value) diff --git a/end_to_end_tests/golden-record/my_test_api_client/models/different_enum.py b/end_to_end_tests/golden-record/my_test_api_client/models/different_enum.py index 00357ab7a..6c167f25c 100644 --- a/end_to_end_tests/golden-record/my_test_api_client/models/different_enum.py +++ b/end_to_end_tests/golden-record/my_test_api_client/models/different_enum.py @@ -4,3 +4,6 @@ class DifferentEnum(str, Enum): DIFFERENT = "DIFFERENT" OTHER = "OTHER" + + def __str__(self) -> str: + return str(self.value)