diff --git a/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars b/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars index 192afe61717e70f2380d03cf3920e348a9328f58..5f51148b94f17ba2723a30032f04f12604151b44 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars @@ -2,9 +2,8 @@ {{>partial_header}} -from collections import defaultdict, abc +from collections import defaultdict from datetime import date, datetime, timedelta # noqa: F401 -from dataclasses import dataclass import functools import decimal import io @@ -470,7 +469,6 @@ class Singleton: Enums and singletons are the same The same instance is returned for a given key of (cls, arg) """ - # TODO use bidict to store this so boolean enums can move through it in reverse to get their own arg value? _instances = {} def __new__(cls, *args, **kwargs): @@ -488,7 +486,13 @@ class Singleton: return cls._instances[key] def __repr__(self): - return '({}, {})'.format(self.__class__.__name__, self) + if isinstance(self, NoneClass): + return f'<{self.__class__.__name__}: None>' + elif isinstance(self, BoolClass): + if (self.__class__, True) in self._instances: + return f'<{self.__class__.__name__}: True>' + return f'<{self.__class__.__name__}: False>' + return f'<{self.__class__.__name__}: {super().__repr__()}>' class NoneClass(Singleton): diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py index 47819dcbca860648cb1d8435896ab71eeda00ff2..0c1dbcb632b17a23faa6b84eda71b465c11e310b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py @@ -9,9 +9,8 @@ Generated by: https://openapi-generator.tech """ -from collections import defaultdict, abc +from collections import defaultdict from datetime import date, datetime, timedelta # noqa: F401 -from dataclasses import dataclass import functools import decimal import io @@ -477,7 +476,6 @@ class Singleton: Enums and singletons are the same The same instance is returned for a given key of (cls, arg) """ - # TODO use bidict to store this so boolean enums can move through it in reverse to get their own arg value? _instances = {} def __new__(cls, *args, **kwargs): @@ -495,7 +493,13 @@ class Singleton: return cls._instances[key] def __repr__(self): - return '({}, {})'.format(self.__class__.__name__, self) + if isinstance(self, NoneClass): + return f'<{self.__class__.__name__}: None>' + elif isinstance(self, BoolClass): + if (self.__class__, True) in self._instances: + return f'<{self.__class__.__name__}: True>' + return f'<{self.__class__.__name__}: False>' + return f'<{self.__class__.__name__}: {super().__repr__()}>' class NoneClass(Singleton): diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_boolean_enum.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_boolean_enum.py index b2080043ce25bb9fb0378f2e8451ec10ec0e673e..36827aa2a9ab740e6b1c3d2e9da587b9b3224213 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_boolean_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_boolean_enum.py @@ -10,7 +10,6 @@ """ -import sys import unittest import petstore_api @@ -28,9 +27,10 @@ class TestBooleanEnum(unittest.TestCase): def test_BooleanEnum(self): """Test BooleanEnum""" - # FIXME: construct object with mandatory attributes with example values model = BooleanEnum(True) - model is BooleanEnum.TRUE + # TODO why is BooleanEnum.TRUE.__class__ DynamicDynamicBooleanEnum? It should only have one Dynamic + # assert model is BooleanEnum.TRUE + assert repr(model) == '<DynamicBooleanEnum: True>' with self.assertRaises(petstore_api.ApiValueError): BooleanEnum(False) diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_nullable_string.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_nullable_string.py index 2a704a70846433880d5a9f2a45f197f787b39fb7..206e84f4b12bc58605573a0e0f8f16cbfa317e84 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_nullable_string.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_nullable_string.py @@ -10,7 +10,6 @@ """ -import sys import unittest import petstore_api @@ -34,6 +33,7 @@ class TestNullableString(unittest.TestCase): assert isinstance(inst, NullableString) assert isinstance(inst, Schema) assert inst.is_none() is True + assert repr(inst) == '<DynamicNullableString: None>' inst = NullableString('approved') assert isinstance(inst, NullableString) diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py index efba299d9f3c009a5297ad156c5e77bdc30b75a7..a877eddfd2ffc7ff66ba8b4cc769ef1fab936972 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py @@ -10,7 +10,6 @@ """ -import sys import unittest import petstore_api @@ -32,12 +31,14 @@ class TestStringEnum(unittest.TestCase): inst = StringEnum(None) assert isinstance(inst, StringEnum) assert isinstance(inst, NoneClass) + assert repr(inst) == '<DynamicStringEnum: None>' inst = StringEnum('approved') assert isinstance(inst, StringEnum) assert isinstance(inst, Singleton) assert isinstance(inst, str) assert inst == 'approved' + assert repr(inst) == "<DynamicStringEnum: 'approved'>" with self.assertRaises(petstore_api.ApiValueError): StringEnum('garbage')