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 192afe61717e..5f51148b94f1 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 47819dcbca86..0c1dbcb632b1 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 @@ def __new__(cls, *args, **kwargs): 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 b2080043ce25..36827aa2a9ab 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 @@ def tearDown(self): 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) == '' 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 2a704a708464..206e84f4b12b 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 @@ def testNullableString(self): assert isinstance(inst, NullableString) assert isinstance(inst, Schema) assert inst.is_none() is True + assert repr(inst) == '' 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 efba299d9f3c..a877eddfd2ff 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 @@ def testStringEnum(self): inst = StringEnum(None) assert isinstance(inst, StringEnum) assert isinstance(inst, NoneClass) + assert repr(inst) == '' inst = StringEnum('approved') assert isinstance(inst, StringEnum) assert isinstance(inst, Singleton) assert isinstance(inst, str) assert inst == 'approved' + assert repr(inst) == "" with self.assertRaises(petstore_api.ApiValueError): StringEnum('garbage')