Skip to content

Commit fbdd3c3

Browse files
authored
[python-experimental] Fixes enum is comparison (#12176)
* Fixes enum is comparison * Reverts file
1 parent 35d6fd4 commit fbdd3c3

32 files changed

+88
-89
lines changed

modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ def NONE(cls):
1111
@classmethod
1212
@property
1313
def {{name}}(cls):
14-
return cls._enum_by_value[{{{value}}}]({{{value}}})
14+
return cls({{{value}}})
1515
{{/each}}
1616
{{/with}}

modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,7 @@ class Schema:
13891389
# Use case: value is None, True, False, or an enum value
13901390
value = arg
13911391
for key in path[1:]:
1392+
# if path is bigger than one, get the value that mfg_cls validated
13921393
value = value[key]
13931394
if hasattr(mfg_cls, '_enum_by_value'):
13941395
mfg_cls = mfg_cls._enum_by_value[value]

samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ class _items(
8484
@classmethod
8585
@property
8686
def GREATER_THAN(cls):
87-
return cls._enum_by_value[">"](">")
87+
return cls(">")
8888

8989
@classmethod
9090
@property
9191
def DOLLAR(cls):
92-
return cls._enum_by_value["$"]("$")
92+
return cls("$")
9393

9494

9595
class EnumQueryStringSchema(
@@ -106,17 +106,17 @@ class EnumQueryStringSchema(
106106
@classmethod
107107
@property
108108
def _ABC(cls):
109-
return cls._enum_by_value["_abc"]("_abc")
109+
return cls("_abc")
110110

111111
@classmethod
112112
@property
113113
def EFG(cls):
114-
return cls._enum_by_value["-efg"]("-efg")
114+
return cls("-efg")
115115

116116
@classmethod
117117
@property
118118
def XYZ(cls):
119-
return cls._enum_by_value["(xyz)"]("(xyz)")
119+
return cls("(xyz)")
120120

121121

122122
class EnumQueryIntegerSchema(
@@ -132,12 +132,12 @@ class EnumQueryIntegerSchema(
132132
@classmethod
133133
@property
134134
def POSITIVE_1(cls):
135-
return cls._enum_by_value[1](1)
135+
return cls(1)
136136

137137
@classmethod
138138
@property
139139
def NEGATIVE_2(cls):
140-
return cls._enum_by_value[-2](-2)
140+
return cls(-2)
141141

142142

143143
class EnumQueryDoubleSchema(
@@ -153,12 +153,12 @@ class EnumQueryDoubleSchema(
153153
@classmethod
154154
@property
155155
def POSITIVE_1_PT_1(cls):
156-
return cls._enum_by_value[1.1](1.1)
156+
return cls(1.1)
157157

158158
@classmethod
159159
@property
160160
def NEGATIVE_1_PT_2(cls):
161-
return cls._enum_by_value[-1.2](-1.2)
161+
return cls(-1.2)
162162
RequestRequiredQueryParams = typing.TypedDict(
163163
'RequestRequiredQueryParams',
164164
{
@@ -225,12 +225,12 @@ class _items(
225225
@classmethod
226226
@property
227227
def GREATER_THAN(cls):
228-
return cls._enum_by_value[">"](">")
228+
return cls(">")
229229

230230
@classmethod
231231
@property
232232
def DOLLAR(cls):
233-
return cls._enum_by_value["$"]("$")
233+
return cls("$")
234234

235235

236236
class EnumHeaderStringSchema(
@@ -247,17 +247,17 @@ class EnumHeaderStringSchema(
247247
@classmethod
248248
@property
249249
def _ABC(cls):
250-
return cls._enum_by_value["_abc"]("_abc")
250+
return cls("_abc")
251251

252252
@classmethod
253253
@property
254254
def EFG(cls):
255-
return cls._enum_by_value["-efg"]("-efg")
255+
return cls("-efg")
256256

257257
@classmethod
258258
@property
259259
def XYZ(cls):
260-
return cls._enum_by_value["(xyz)"]("(xyz)")
260+
return cls("(xyz)")
261261
RequestRequiredHeaderParams = typing.TypedDict(
262262
'RequestRequiredHeaderParams',
263263
{
@@ -313,12 +313,12 @@ class _items(
313313
@classmethod
314314
@property
315315
def GREATER_THAN(cls):
316-
return cls._enum_by_value[">"](">")
316+
return cls(">")
317317

318318
@classmethod
319319
@property
320320
def DOLLAR(cls):
321-
return cls._enum_by_value["$"]("$")
321+
return cls("$")
322322

323323

324324
class enum_form_string(
@@ -335,17 +335,17 @@ class enum_form_string(
335335
@classmethod
336336
@property
337337
def _ABC(cls):
338-
return cls._enum_by_value["_abc"]("_abc")
338+
return cls("_abc")
339339

340340
@classmethod
341341
@property
342342
def EFG(cls):
343-
return cls._enum_by_value["-efg"]("-efg")
343+
return cls("-efg")
344344

345345
@classmethod
346346
@property
347347
def XYZ(cls):
348-
return cls._enum_by_value["(xyz)"]("(xyz)")
348+
return cls("(xyz)")
349349

350350

351351
def __new__(

samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ class _items(
8787
@classmethod
8888
@property
8989
def AVAILABLE(cls):
90-
return cls._enum_by_value["available"]("available")
90+
return cls("available")
9191

9292
@classmethod
9393
@property
9494
def PENDING(cls):
95-
return cls._enum_by_value["pending"]("pending")
95+
return cls("pending")
9696

9797
@classmethod
9898
@property
9999
def SOLD(cls):
100-
return cls._enum_by_value["sold"]("sold")
100+
return cls("sold")
101101
RequestRequiredQueryParams = typing.TypedDict(
102102
'RequestRequiredQueryParams',
103103
{

samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class className(
9090
@classmethod
9191
@property
9292
def BASQUEPIG(cls):
93-
return cls._enum_by_value["BasquePig"]("BasquePig")
93+
return cls("BasquePig")
9494

9595

9696
def __new__(

samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ class BooleanEnum(
8282
@classmethod
8383
@property
8484
def TRUE(cls):
85-
return cls._enum_by_value[True](True)
85+
return cls(True)

samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral_all_of.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class quadrilateralType(
8787
@classmethod
8888
@property
8989
def COMPLEXQUADRILATERAL(cls):
90-
return cls._enum_by_value["ComplexQuadrilateral"]("ComplexQuadrilateral")
90+
return cls("ComplexQuadrilateral")
9191

9292

9393
def __new__(

samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ class Currency(
8383
@classmethod
8484
@property
8585
def EUR(cls):
86-
return cls._enum_by_value["eur"]("eur")
86+
return cls("eur")
8787

8888
@classmethod
8989
@property
9090
def USD(cls):
91-
return cls._enum_by_value["usd"]("usd")
91+
return cls("usd")

samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class className(
9090
@classmethod
9191
@property
9292
def DANISHPIG(cls):
93-
return cls._enum_by_value["DanishPig"]("DanishPig")
93+
return cls("DanishPig")
9494

9595

9696
def __new__(

samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ class just_symbol(
8888
@classmethod
8989
@property
9090
def GREATER_THAN_EQUALS(cls):
91-
return cls._enum_by_value[">="](">=")
91+
return cls(">=")
9292

9393
@classmethod
9494
@property
9595
def DOLLAR(cls):
96-
return cls._enum_by_value["$"]("$")
96+
return cls("$")
9797

9898

9999
class array_enum(
@@ -114,12 +114,12 @@ class _items(
114114
@classmethod
115115
@property
116116
def FISH(cls):
117-
return cls._enum_by_value["fish"]("fish")
117+
return cls("fish")
118118

119119
@classmethod
120120
@property
121121
def CRAB(cls):
122-
return cls._enum_by_value["crab"]("crab")
122+
return cls("crab")
123123

124124

125125
def __new__(

0 commit comments

Comments
 (0)