From fbdd3c3e220ea064a041ce653dc98c3991ee0180 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Tue, 19 Apr 2022 21:28:42 -0700 Subject: [PATCH] [python-experimental] Fixes enum is comparison (#12176) * Fixes enum is comparison * Reverts file --- .../model_templates/enums.handlebars | 2 +- .../python-experimental/schemas.handlebars | 1 + .../api/fake_api_endpoints/enum_parameters.py | 38 +++++++++---------- .../pet_api_endpoints/find_pets_by_status.py | 6 +-- .../petstore_api/model/basque_pig.py | 2 +- .../petstore_api/model/boolean_enum.py | 2 +- .../model/complex_quadrilateral_all_of.py | 2 +- .../petstore_api/model/currency.py | 4 +- .../petstore_api/model/danish_pig.py | 2 +- .../petstore_api/model/enum_arrays.py | 8 ++-- .../petstore_api/model/enum_class.py | 6 +-- .../petstore_api/model/enum_test.py | 20 +++++----- .../model/equilateral_triangle_all_of.py | 2 +- .../petstore_api/model/integer_enum.py | 6 +-- .../petstore_api/model/integer_enum_big.py | 6 +-- .../model/integer_enum_one_value.py | 2 +- .../model/integer_enum_with_default_value.py | 6 +-- .../model/isosceles_triangle_all_of.py | 2 +- .../petstore_api/model/map_test.py | 4 +- .../petstore_api/model/order.py | 6 +-- .../petstore_api/model/pet.py | 6 +-- .../model/quadrilateral_interface.py | 2 +- .../model/scalene_triangle_all_of.py | 2 +- .../model/simple_quadrilateral_all_of.py | 2 +- .../petstore_api/model/string_enum.py | 14 +++---- .../model/string_enum_with_default_value.py | 6 +-- .../petstore_api/model/triangle_interface.py | 2 +- .../petstore_api/model/whale.py | 2 +- .../petstore_api/model/zebra.py | 8 ++-- .../petstore_api/schemas.py | 1 + .../tests_manual/test_boolean_enum.py | 3 +- .../tests_manual/test_combine_schemas.py | 2 +- 32 files changed, 88 insertions(+), 89 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars index 5cbc68dc173..923fac7f6f5 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars @@ -11,6 +11,6 @@ def NONE(cls): @classmethod @property def {{name}}(cls): - return cls._enum_by_value[{{{value}}}]({{{value}}}) + return cls({{{value}}}) {{/each}} {{/with}} \ No newline at end of file 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 5f51148b94f..ecfaae2e66c 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars @@ -1389,6 +1389,7 @@ class Schema: # Use case: value is None, True, False, or an enum value value = arg for key in path[1:]: + # if path is bigger than one, get the value that mfg_cls validated value = value[key] if hasattr(mfg_cls, '_enum_by_value'): mfg_cls = mfg_cls._enum_by_value[value] diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py index 191524e61ee..289f5210680 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py @@ -84,12 +84,12 @@ class EnumQueryStringArraySchema( @classmethod @property def GREATER_THAN(cls): - return cls._enum_by_value[">"](">") + return cls(">") @classmethod @property def DOLLAR(cls): - return cls._enum_by_value["$"]("$") + return cls("$") class EnumQueryStringSchema( @@ -106,17 +106,17 @@ class EnumQueryStringSchema( @classmethod @property def _ABC(cls): - return cls._enum_by_value["_abc"]("_abc") + return cls("_abc") @classmethod @property def EFG(cls): - return cls._enum_by_value["-efg"]("-efg") + return cls("-efg") @classmethod @property def XYZ(cls): - return cls._enum_by_value["(xyz)"]("(xyz)") + return cls("(xyz)") class EnumQueryIntegerSchema( @@ -132,12 +132,12 @@ class EnumQueryIntegerSchema( @classmethod @property def POSITIVE_1(cls): - return cls._enum_by_value[1](1) + return cls(1) @classmethod @property def NEGATIVE_2(cls): - return cls._enum_by_value[-2](-2) + return cls(-2) class EnumQueryDoubleSchema( @@ -153,12 +153,12 @@ class EnumQueryDoubleSchema( @classmethod @property def POSITIVE_1_PT_1(cls): - return cls._enum_by_value[1.1](1.1) + return cls(1.1) @classmethod @property def NEGATIVE_1_PT_2(cls): - return cls._enum_by_value[-1.2](-1.2) + return cls(-1.2) RequestRequiredQueryParams = typing.TypedDict( 'RequestRequiredQueryParams', { @@ -225,12 +225,12 @@ class EnumHeaderStringArraySchema( @classmethod @property def GREATER_THAN(cls): - return cls._enum_by_value[">"](">") + return cls(">") @classmethod @property def DOLLAR(cls): - return cls._enum_by_value["$"]("$") + return cls("$") class EnumHeaderStringSchema( @@ -247,17 +247,17 @@ class EnumHeaderStringSchema( @classmethod @property def _ABC(cls): - return cls._enum_by_value["_abc"]("_abc") + return cls("_abc") @classmethod @property def EFG(cls): - return cls._enum_by_value["-efg"]("-efg") + return cls("-efg") @classmethod @property def XYZ(cls): - return cls._enum_by_value["(xyz)"]("(xyz)") + return cls("(xyz)") RequestRequiredHeaderParams = typing.TypedDict( 'RequestRequiredHeaderParams', { @@ -313,12 +313,12 @@ class SchemaForRequestBodyApplicationXWwwFormUrlencoded( @classmethod @property def GREATER_THAN(cls): - return cls._enum_by_value[">"](">") + return cls(">") @classmethod @property def DOLLAR(cls): - return cls._enum_by_value["$"]("$") + return cls("$") class enum_form_string( @@ -335,17 +335,17 @@ class SchemaForRequestBodyApplicationXWwwFormUrlencoded( @classmethod @property def _ABC(cls): - return cls._enum_by_value["_abc"]("_abc") + return cls("_abc") @classmethod @property def EFG(cls): - return cls._enum_by_value["-efg"]("-efg") + return cls("-efg") @classmethod @property def XYZ(cls): - return cls._enum_by_value["(xyz)"]("(xyz)") + return cls("(xyz)") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py index b49694637fd..42fe59410ba 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py @@ -87,17 +87,17 @@ class StatusSchema( @classmethod @property def AVAILABLE(cls): - return cls._enum_by_value["available"]("available") + return cls("available") @classmethod @property def PENDING(cls): - return cls._enum_by_value["pending"]("pending") + return cls("pending") @classmethod @property def SOLD(cls): - return cls._enum_by_value["sold"]("sold") + return cls("sold") RequestRequiredQueryParams = typing.TypedDict( 'RequestRequiredQueryParams', { diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py index e738e1cf139..c61420c182d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py @@ -90,7 +90,7 @@ class BasquePig( @classmethod @property def BASQUEPIG(cls): - return cls._enum_by_value["BasquePig"]("BasquePig") + return cls("BasquePig") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py index a03629682ba..228d6f5b0b7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py @@ -82,4 +82,4 @@ class BooleanEnum( @classmethod @property def TRUE(cls): - return cls._enum_by_value[True](True) + return cls(True) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral_all_of.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral_all_of.py index 769118b31c8..1442efce783 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral_all_of.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral_all_of.py @@ -87,7 +87,7 @@ class ComplexQuadrilateralAllOf( @classmethod @property def COMPLEXQUADRILATERAL(cls): - return cls._enum_by_value["ComplexQuadrilateral"]("ComplexQuadrilateral") + return cls("ComplexQuadrilateral") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py index a71536bb8ec..2b0afd27365 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py @@ -83,9 +83,9 @@ class Currency( @classmethod @property def EUR(cls): - return cls._enum_by_value["eur"]("eur") + return cls("eur") @classmethod @property def USD(cls): - return cls._enum_by_value["usd"]("usd") + return cls("usd") diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py index 58da6f981c5..0c900458d90 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py @@ -90,7 +90,7 @@ class DanishPig( @classmethod @property def DANISHPIG(cls): - return cls._enum_by_value["DanishPig"]("DanishPig") + return cls("DanishPig") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py index 37c1c364549..be3c9560958 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py @@ -88,12 +88,12 @@ class EnumArrays( @classmethod @property def GREATER_THAN_EQUALS(cls): - return cls._enum_by_value[">="](">=") + return cls(">=") @classmethod @property def DOLLAR(cls): - return cls._enum_by_value["$"]("$") + return cls("$") class array_enum( @@ -114,12 +114,12 @@ class EnumArrays( @classmethod @property def FISH(cls): - return cls._enum_by_value["fish"]("fish") + return cls("fish") @classmethod @property def CRAB(cls): - return cls._enum_by_value["crab"]("crab") + return cls("crab") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_class.py index a89d939ad10..5062446c15a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_class.py @@ -84,14 +84,14 @@ class EnumClass( @classmethod @property def _ABC(cls): - return cls._enum_by_value["_abc"]("_abc") + return cls("_abc") @classmethod @property def EFG(cls): - return cls._enum_by_value["-efg"]("-efg") + return cls("-efg") @classmethod @property def XYZ(cls): - return cls._enum_by_value["(xyz)"]("(xyz)") + return cls("(xyz)") diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_test.py index ade595b3d89..a294d590bb8 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_test.py @@ -92,17 +92,17 @@ class EnumTest( @classmethod @property def UPPER(cls): - return cls._enum_by_value["UPPER"]("UPPER") + return cls("UPPER") @classmethod @property def LOWER(cls): - return cls._enum_by_value["lower"]("lower") + return cls("lower") @classmethod @property def EMPTY(cls): - return cls._enum_by_value[""]("") + return cls("") class enum_string_required( @@ -119,17 +119,17 @@ class EnumTest( @classmethod @property def UPPER(cls): - return cls._enum_by_value["UPPER"]("UPPER") + return cls("UPPER") @classmethod @property def LOWER(cls): - return cls._enum_by_value["lower"]("lower") + return cls("lower") @classmethod @property def EMPTY(cls): - return cls._enum_by_value[""]("") + return cls("") class enum_integer( @@ -145,12 +145,12 @@ class EnumTest( @classmethod @property def POSITIVE_1(cls): - return cls._enum_by_value[1](1) + return cls(1) @classmethod @property def NEGATIVE_1(cls): - return cls._enum_by_value[-1](-1) + return cls(-1) class enum_number( @@ -166,12 +166,12 @@ class EnumTest( @classmethod @property def POSITIVE_1_PT_1(cls): - return cls._enum_by_value[1.1](1.1) + return cls(1.1) @classmethod @property def NEGATIVE_1_PT_2(cls): - return cls._enum_by_value[-1.2](-1.2) + return cls(-1.2) @classmethod @property diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/equilateral_triangle_all_of.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/equilateral_triangle_all_of.py index 8a3b9de0a34..080dcc90d27 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/equilateral_triangle_all_of.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/equilateral_triangle_all_of.py @@ -87,7 +87,7 @@ class EquilateralTriangleAllOf( @classmethod @property def EQUILATERALTRIANGLE(cls): - return cls._enum_by_value["EquilateralTriangle"]("EquilateralTriangle") + return cls("EquilateralTriangle") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum.py index 4d6f4e87f24..b55bb1bb1dd 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum.py @@ -84,14 +84,14 @@ class IntegerEnum( @classmethod @property def POSITIVE_0(cls): - return cls._enum_by_value[0](0) + return cls(0) @classmethod @property def POSITIVE_1(cls): - return cls._enum_by_value[1](1) + return cls(1) @classmethod @property def POSITIVE_2(cls): - return cls._enum_by_value[2](2) + return cls(2) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_big.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_big.py index 4fc07b1e6b4..f7c5f87db59 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_big.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_big.py @@ -84,14 +84,14 @@ class IntegerEnumBig( @classmethod @property def POSITIVE_10(cls): - return cls._enum_by_value[10](10) + return cls(10) @classmethod @property def POSITIVE_11(cls): - return cls._enum_by_value[11](11) + return cls(11) @classmethod @property def POSITIVE_12(cls): - return cls._enum_by_value[12](12) + return cls(12) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_one_value.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_one_value.py index 7127bb9d910..d0b73258d09 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_one_value.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_one_value.py @@ -82,4 +82,4 @@ class IntegerEnumOneValue( @classmethod @property def POSITIVE_0(cls): - return cls._enum_by_value[0](0) + return cls(0) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_with_default_value.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_with_default_value.py index 16ea7b03fff..b79bee62ba7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_with_default_value.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_with_default_value.py @@ -84,14 +84,14 @@ class IntegerEnumWithDefaultValue( @classmethod @property def POSITIVE_0(cls): - return cls._enum_by_value[0](0) + return cls(0) @classmethod @property def POSITIVE_1(cls): - return cls._enum_by_value[1](1) + return cls(1) @classmethod @property def POSITIVE_2(cls): - return cls._enum_by_value[2](2) + return cls(2) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/isosceles_triangle_all_of.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/isosceles_triangle_all_of.py index 861cc308ce4..b166abba12b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/isosceles_triangle_all_of.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/isosceles_triangle_all_of.py @@ -87,7 +87,7 @@ class IsoscelesTriangleAllOf( @classmethod @property def ISOSCELESTRIANGLE(cls): - return cls._enum_by_value["IsoscelesTriangle"]("IsoscelesTriangle") + return cls("IsoscelesTriangle") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/map_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/map_test.py index a3db41640ce..180be2c1449 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/map_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/map_test.py @@ -132,12 +132,12 @@ class MapTest( @classmethod @property def UPPER(cls): - return cls._enum_by_value["UPPER"]("UPPER") + return cls("UPPER") @classmethod @property def LOWER(cls): - return cls._enum_by_value["lower"]("lower") + return cls("lower") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/order.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/order.py index 0d368c4b56b..dbf535def29 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/order.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/order.py @@ -93,17 +93,17 @@ class Order( @classmethod @property def PLACED(cls): - return cls._enum_by_value["placed"]("placed") + return cls("placed") @classmethod @property def APPROVED(cls): - return cls._enum_by_value["approved"]("approved") + return cls("approved") @classmethod @property def DELIVERED(cls): - return cls._enum_by_value["delivered"]("delivered") + return cls("delivered") complete = BoolSchema diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pet.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pet.py index 79e65c32623..14f783ee2fd 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pet.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pet.py @@ -118,17 +118,17 @@ class Pet( @classmethod @property def AVAILABLE(cls): - return cls._enum_by_value["available"]("available") + return cls("available") @classmethod @property def PENDING(cls): - return cls._enum_by_value["pending"]("pending") + return cls("pending") @classmethod @property def SOLD(cls): - return cls._enum_by_value["sold"]("sold") + return cls("sold") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral_interface.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral_interface.py index 08e6532be72..9560bc5a548 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral_interface.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral_interface.py @@ -91,7 +91,7 @@ class QuadrilateralInterface( @classmethod @property def QUADRILATERAL(cls): - return cls._enum_by_value["Quadrilateral"]("Quadrilateral") + return cls("Quadrilateral") quadrilateralType = StrSchema def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/scalene_triangle_all_of.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/scalene_triangle_all_of.py index e4712af077e..257d28bb7c6 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/scalene_triangle_all_of.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/scalene_triangle_all_of.py @@ -87,7 +87,7 @@ class ScaleneTriangleAllOf( @classmethod @property def SCALENETRIANGLE(cls): - return cls._enum_by_value["ScaleneTriangle"]("ScaleneTriangle") + return cls("ScaleneTriangle") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/simple_quadrilateral_all_of.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/simple_quadrilateral_all_of.py index 67c0b0d286f..ae5179cb5b1 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/simple_quadrilateral_all_of.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/simple_quadrilateral_all_of.py @@ -87,7 +87,7 @@ class SimpleQuadrilateralAllOf( @classmethod @property def SIMPLEQUADRILATERAL(cls): - return cls._enum_by_value["SimpleQuadrilateral"]("SimpleQuadrilateral") + return cls("SimpleQuadrilateral") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum.py index bc2264a11c4..800ee5a3baf 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum.py @@ -98,35 +98,33 @@ lines''': "MULTIPLE_LINES", @classmethod @property def PLACED(cls): - return cls._enum_by_value["placed"]("placed") + return cls("placed") @classmethod @property def APPROVED(cls): - return cls._enum_by_value["approved"]("approved") + return cls("approved") @classmethod @property def DELIVERED(cls): - return cls._enum_by_value["delivered"]("delivered") + return cls("delivered") @classmethod @property def SINGLE_QUOTED(cls): - return cls._enum_by_value["single quoted"]("single quoted") + return cls("single quoted") @classmethod @property def MULTIPLE_LINES(cls): - return cls._enum_by_value['''multiple -lines''']('''multiple + return cls('''multiple lines''') @classmethod @property def DOUBLE_QUOTE_WITH_NEWLINE(cls): - return cls._enum_by_value['''double quote - with newline''']('''double quote + return cls('''double quote with newline''') def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum_with_default_value.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum_with_default_value.py index e7960720659..91bfd93fad4 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum_with_default_value.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum_with_default_value.py @@ -84,14 +84,14 @@ class StringEnumWithDefaultValue( @classmethod @property def PLACED(cls): - return cls._enum_by_value["placed"]("placed") + return cls("placed") @classmethod @property def APPROVED(cls): - return cls._enum_by_value["approved"]("approved") + return cls("approved") @classmethod @property def DELIVERED(cls): - return cls._enum_by_value["delivered"]("delivered") + return cls("delivered") diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle_interface.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle_interface.py index 7a75467c51d..7949415fe15 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle_interface.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle_interface.py @@ -91,7 +91,7 @@ class TriangleInterface( @classmethod @property def TRIANGLE(cls): - return cls._enum_by_value["Triangle"]("Triangle") + return cls("Triangle") triangleType = StrSchema def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/whale.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/whale.py index d51b9d3e1ea..1e126220ef9 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/whale.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/whale.py @@ -92,7 +92,7 @@ class Whale( @classmethod @property def WHALE(cls): - return cls._enum_by_value["whale"]("whale") + return cls("whale") def __new__( diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/zebra.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/zebra.py index 99ba4d3ce81..0d6ad534ca6 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/zebra.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/zebra.py @@ -92,17 +92,17 @@ class Zebra( @classmethod @property def PLAINS(cls): - return cls._enum_by_value["plains"]("plains") + return cls("plains") @classmethod @property def MOUNTAIN(cls): - return cls._enum_by_value["mountain"]("mountain") + return cls("mountain") @classmethod @property def GREVYS(cls): - return cls._enum_by_value["grevys"]("grevys") + return cls("grevys") class className( @@ -117,7 +117,7 @@ class Zebra( @classmethod @property def ZEBRA(cls): - return cls._enum_by_value["zebra"]("zebra") + return cls("zebra") def __new__( 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 0c1dbcb632b..96887c212fd 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py @@ -1396,6 +1396,7 @@ class Schema: # Use case: value is None, True, False, or an enum value value = arg for key in path[1:]: + # if path is bigger than one, get the value that mfg_cls validated value = value[key] if hasattr(mfg_cls, '_enum_by_value'): mfg_cls = mfg_cls._enum_by_value[value] 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 36827aa2a9a..a8c835b1e4a 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 @@ -28,8 +28,7 @@ class TestBooleanEnum(unittest.TestCase): def test_BooleanEnum(self): """Test BooleanEnum""" model = BooleanEnum(True) - # TODO why is BooleanEnum.TRUE.__class__ DynamicDynamicBooleanEnum? It should only have one Dynamic - # assert model is BooleanEnum.TRUE + 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_combine_schemas.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_combine_schemas.py index c6d353f66c9..c6571ded220 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_combine_schemas.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_combine_schemas.py @@ -96,7 +96,7 @@ class TestCombineNonObjectSchemas(unittest.TestCase): # accessing invalid enum throws an exception invalid_enums = ['POSITIVE_1', 'POSITIVE_2'] for invalid_enum in invalid_enums: - with self.assertRaises(KeyError): + with self.assertRaises(petstore_api.ApiValueError): getattr(IntegerOneEnum, invalid_enum)