Skip to content

Commit 29aff9a

Browse files
committed
regeneration and tests
1 parent 7bf223f commit 29aff9a

File tree

10 files changed

+218
-18
lines changed

10 files changed

+218
-18
lines changed

samples/client/petstore/python/petstore_api/model_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,11 +1559,16 @@ def get_valid_classes_phrase(input_classes):
15591559
def convert_js_args_to_python_args(fn):
15601560
from functools import wraps
15611561
@wraps(fn)
1562-
def wrapped_init(self, *args, **kwargs):
1562+
def wrapped_init(_self, *args, **kwargs):
1563+
"""
1564+
An attribute named `self` received from the api will conflicts with the reserved `self`
1565+
parameter of a class method. During generation, `self` attributes are mapped
1566+
to `_self` in models. Here, we name `_self` instead of `self` to avoid conflicts.
1567+
"""
15631568
spec_property_naming = kwargs.get('_spec_property_naming', False)
15641569
if spec_property_naming:
1565-
kwargs = change_keys_js_to_python(kwargs, self.__class__)
1566-
return fn(self, *args, **kwargs)
1570+
kwargs = change_keys_js_to_python(kwargs, _self.__class__)
1571+
return fn(_self, *args, **kwargs)
15671572
return wrapped_init
15681573

15691574

samples/openapi3/client/extensions/x-auth-id-alias/python/x_auth_id_alias/model_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,11 +1559,16 @@ def get_valid_classes_phrase(input_classes):
15591559
def convert_js_args_to_python_args(fn):
15601560
from functools import wraps
15611561
@wraps(fn)
1562-
def wrapped_init(self, *args, **kwargs):
1562+
def wrapped_init(_self, *args, **kwargs):
1563+
"""
1564+
An attribute named `self` received from the api will conflicts with the reserved `self`
1565+
parameter of a class method. During generation, `self` attributes are mapped
1566+
to `_self` in models. Here, we name `_self` instead of `self` to avoid conflicts.
1567+
"""
15631568
spec_property_naming = kwargs.get('_spec_property_naming', False)
15641569
if spec_property_naming:
1565-
kwargs = change_keys_js_to_python(kwargs, self.__class__)
1566-
return fn(self, *args, **kwargs)
1570+
kwargs = change_keys_js_to_python(kwargs, _self.__class__)
1571+
return fn(_self, *args, **kwargs)
15671572
return wrapped_init
15681573

15691574

samples/openapi3/client/features/dynamic-servers/python/dynamic_servers/model_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,11 +1559,16 @@ def get_valid_classes_phrase(input_classes):
15591559
def convert_js_args_to_python_args(fn):
15601560
from functools import wraps
15611561
@wraps(fn)
1562-
def wrapped_init(self, *args, **kwargs):
1562+
def wrapped_init(_self, *args, **kwargs):
1563+
"""
1564+
An attribute named `self` received from the api will conflicts with the reserved `self`
1565+
parameter of a class method. During generation, `self` attributes are mapped
1566+
to `_self` in models. Here, we name `_self` instead of `self` to avoid conflicts.
1567+
"""
15631568
spec_property_naming = kwargs.get('_spec_property_naming', False)
15641569
if spec_property_naming:
1565-
kwargs = change_keys_js_to_python(kwargs, self.__class__)
1566-
return fn(self, *args, **kwargs)
1570+
kwargs = change_keys_js_to_python(kwargs, _self.__class__)
1571+
return fn(_self, *args, **kwargs)
15671572
return wrapped_init
15681573

15691574

samples/openapi3/client/petstore/python/.openapi-generator/FILES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ docs/ShapeInterface.md
8282
docs/ShapeOrNull.md
8383
docs/SimpleQuadrilateral.md
8484
docs/SomeObject.md
85+
docs/SomeObjectWithSelfAttr.md
8586
docs/SpecialModelName.md
8687
docs/StoreApi.md
8788
docs/StringBooleanMap.md
@@ -184,6 +185,7 @@ petstore_api/model/shape_interface.py
184185
petstore_api/model/shape_or_null.py
185186
petstore_api/model/simple_quadrilateral.py
186187
petstore_api/model/some_object.py
188+
petstore_api/model/some_object_with_self_attr.py
187189
petstore_api/model/special_model_name.py
188190
petstore_api/model/string_boolean_map.py
189191
petstore_api/model/string_enum.py
@@ -204,4 +206,5 @@ setup.cfg
204206
setup.py
205207
test-requirements.txt
206208
test/__init__.py
209+
test/test_some_object_with_self_attr.py
207210
tox.ini

samples/openapi3/client/petstore/python/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Class | Method | HTTP request | Description
207207
- [ShapeOrNull](docs/ShapeOrNull.md)
208208
- [SimpleQuadrilateral](docs/SimpleQuadrilateral.md)
209209
- [SomeObject](docs/SomeObject.md)
210+
- [SomeObjectWithSelfAttr](docs/SomeObjectWithSelfAttr.md)
210211
- [SpecialModelName](docs/SpecialModelName.md)
211212
- [StringBooleanMap](docs/StringBooleanMap.md)
212213
- [StringEnum](docs/StringEnum.md)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SomeObjectWithSelfAttr
2+
3+
4+
## Properties
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**_self** | **str** | | [optional]
8+
9+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
10+
11+
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
"""
2+
OpenAPI Petstore
3+
4+
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ # noqa: E501
5+
6+
The version of the OpenAPI document: 1.0.0
7+
Generated by: https://openapi-generator.tech
8+
"""
9+
10+
11+
import re # noqa: F401
12+
import sys # noqa: F401
13+
14+
from petstore_api.model_utils import ( # noqa: F401
15+
ApiTypeError,
16+
ModelComposed,
17+
ModelNormal,
18+
ModelSimple,
19+
cached_property,
20+
change_keys_js_to_python,
21+
convert_js_args_to_python_args,
22+
date,
23+
datetime,
24+
file_type,
25+
none_type,
26+
validate_get_composed_info,
27+
)
28+
29+
30+
class SomeObjectWithSelfAttr(ModelNormal):
31+
"""NOTE: This class is auto generated by OpenAPI Generator.
32+
Ref: https://openapi-generator.tech
33+
34+
Do not edit the class manually.
35+
36+
Attributes:
37+
allowed_values (dict): The key is the tuple path to the attribute
38+
and the for var_name this is (var_name,). The value is a dict
39+
with a capitalized key describing the allowed value and an allowed
40+
value. These dicts store the allowed enum values.
41+
attribute_map (dict): The key is attribute name
42+
and the value is json key in definition.
43+
discriminator_value_class_map (dict): A dict to go from the discriminator
44+
variable value to the discriminator class name.
45+
validations (dict): The key is the tuple path to the attribute
46+
and the for var_name this is (var_name,). The value is a dict
47+
that stores validations for max_length, min_length, max_items,
48+
min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum,
49+
inclusive_minimum, and regex.
50+
additional_properties_type (tuple): A tuple of classes accepted
51+
as additional properties values.
52+
"""
53+
54+
allowed_values = {
55+
}
56+
57+
validations = {
58+
}
59+
60+
additional_properties_type = None
61+
62+
_nullable = False
63+
64+
@cached_property
65+
def openapi_types():
66+
"""
67+
This must be a method because a model may have properties that are
68+
of type self, this must run after the class is loaded
69+
70+
Returns
71+
openapi_types (dict): The key is attribute name
72+
and the value is attribute type.
73+
"""
74+
return {
75+
'_self': (str,), # noqa: E501
76+
}
77+
78+
@cached_property
79+
def discriminator():
80+
return None
81+
82+
83+
attribute_map = {
84+
'_self': 'self', # noqa: E501
85+
}
86+
87+
_composed_schemas = {}
88+
89+
required_properties = set([
90+
'_data_store',
91+
'_check_type',
92+
'_spec_property_naming',
93+
'_path_to_item',
94+
'_configuration',
95+
'_visited_composed_classes',
96+
])
97+
98+
@convert_js_args_to_python_args
99+
def __init__(self, *args, **kwargs): # noqa: E501
100+
"""SomeObjectWithSelfAttr - a model defined in OpenAPI
101+
102+
Keyword Args:
103+
_check_type (bool): if True, values for parameters in openapi_types
104+
will be type checked and a TypeError will be
105+
raised if the wrong type is input.
106+
Defaults to True
107+
_path_to_item (tuple/list): This is a list of keys or values to
108+
drill down to the model in received_data
109+
when deserializing a response
110+
_spec_property_naming (bool): True if the variable names in the input data
111+
are serialized names, as specified in the OpenAPI document.
112+
False if the variable names in the input data
113+
are pythonic names, e.g. snake case (default)
114+
_configuration (Configuration): the instance to use when
115+
deserializing a file_type parameter.
116+
If passed, type conversion is attempted
117+
If omitted no type conversion is done.
118+
_visited_composed_classes (tuple): This stores a tuple of
119+
classes that we have traveled through so that
120+
if we see that class again we will not use its
121+
discriminator again.
122+
When traveling through a discriminator, the
123+
composed schema that is
124+
is traveled through is added to this set.
125+
For example if Animal has a discriminator
126+
petType and we pass in "Dog", and the class Dog
127+
allOf includes Animal, we move through Animal
128+
once using the discriminator, and pick Dog.
129+
Then in Dog, we will make an instance of the
130+
Animal class but this time we won't travel
131+
through its discriminator because we passed in
132+
_visited_composed_classes = (Animal,)
133+
_self (str): [optional] # noqa: E501
134+
"""
135+
136+
_check_type = kwargs.pop('_check_type', True)
137+
_spec_property_naming = kwargs.pop('_spec_property_naming', False)
138+
_path_to_item = kwargs.pop('_path_to_item', ())
139+
_configuration = kwargs.pop('_configuration', None)
140+
_visited_composed_classes = kwargs.pop('_visited_composed_classes', ())
141+
142+
if args:
143+
raise ApiTypeError(
144+
"Invalid positional arguments=%s passed to %s. Remove those invalid positional arguments." % (
145+
args,
146+
self.__class__.__name__,
147+
),
148+
path_to_item=_path_to_item,
149+
valid_classes=(self.__class__,),
150+
)
151+
152+
self._data_store = {}
153+
self._check_type = _check_type
154+
self._spec_property_naming = _spec_property_naming
155+
self._path_to_item = _path_to_item
156+
self._configuration = _configuration
157+
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
158+
159+
for var_name, var_value in kwargs.items():
160+
if var_name not in self.attribute_map and \
161+
self._configuration is not None and \
162+
self._configuration.discard_unknown_keys and \
163+
self.additional_properties_type is None:
164+
# discard variable.
165+
continue
166+
setattr(self, var_name, var_value)

samples/openapi3/client/petstore/python/petstore_api/model_utils.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,11 +1559,16 @@ def get_valid_classes_phrase(input_classes):
15591559
def convert_js_args_to_python_args(fn):
15601560
from functools import wraps
15611561
@wraps(fn)
1562-
def wrapped_init(self, *args, **kwargs):
1562+
def wrapped_init(_self, *args, **kwargs):
1563+
"""
1564+
An attribute named `self` received from the api will conflicts with the reserved `self`
1565+
parameter of a class method. During generation, `self` attributes are mapped
1566+
to `_self` in models. Here, we name `_self` instead of `self` to avoid conflicts.
1567+
"""
15631568
spec_property_naming = kwargs.get('_spec_property_naming', False)
15641569
if spec_property_naming:
1565-
kwargs = change_keys_js_to_python(kwargs, self.__class__)
1566-
return fn(self, *args, **kwargs)
1570+
kwargs = change_keys_js_to_python(kwargs, _self.__class__)
1571+
return fn(_self, *args, **kwargs)
15671572
return wrapped_init
15681573

15691574

samples/openapi3/client/petstore/python/petstore_api/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
from petstore_api.model.shape_or_null import ShapeOrNull
8585
from petstore_api.model.simple_quadrilateral import SimpleQuadrilateral
8686
from petstore_api.model.some_object import SomeObject
87+
from petstore_api.model.some_object_with_self_attr import SomeObjectWithSelfAttr
8788
from petstore_api.model.special_model_name import SpecialModelName
8889
from petstore_api.model.string_boolean_map import StringBooleanMap
8990
from petstore_api.model.string_enum import StringEnum

samples/openapi3/client/petstore/python/tests_manual/test_object_with_self_attribute.py renamed to samples/openapi3/client/petstore/python/test/test_some_object_with_self_attr.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# coding: utf-8
2-
31
"""
42
OpenAPI Petstore
53
@@ -17,17 +15,17 @@
1715
from petstore_api.model.some_object_with_self_attr import SomeObjectWithSelfAttr
1816

1917

20-
class TestObjectWithSelfAttribute(unittest.TestCase):
21-
"""NumberWithValidations unit test stubs"""
18+
class TestSomeObjectWithSelfAttr(unittest.TestCase):
19+
"""SomeObjectWithSelfAttr unit test stubs"""
2220

2321
def setUp(self):
2422
pass
2523

2624
def tearDown(self):
2725
pass
2826

29-
def testObjectWithSelfAttribute(self):
30-
"""Test NumberWithValidations"""
27+
def testSomeObjectWithSelfAttr(self):
28+
"""Test SomeObjectWithSelfAttr"""
3129
kwargs = {"self": "this is a string"}
3230
model = SomeObjectWithSelfAttr(**kwargs)
3331
assert model._self == "this is a string"

0 commit comments

Comments
 (0)