Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python-experimental] Rename from_server variable to json_variable_naming #6390

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
41e97e6
Mustache template should use invokerPackage tag to generate import
sebastien-rosset May 13, 2020
1760f6a
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
3ae466e
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
b628667
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 13, 2020
4dc915c
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 14, 2020
7a207f6
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 16, 2020
776fba6
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 18, 2020
3fac434
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 19, 2020
a96c46b
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 20, 2020
1351fd0
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 21, 2020
77133c5
Add unit test showing how to construct objects from a JSON dict
sebastien-rosset May 22, 2020
721b8ff
rename from_server to json_variable_naming
sebastien-rosset May 22, 2020
21c3994
rename from_server to json_variable_naming
sebastien-rosset May 22, 2020
8112ebb
fix code so it can execute in python 2.x
sebastien-rosset May 22, 2020
ba65735
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 22, 2020
6018ee4
rename variable
sebastien-rosset May 22, 2020
b35d43c
fix typo
sebastien-rosset May 22, 2020
3218b2d
fix typo
sebastien-rosset May 22, 2020
9a0b89e
Merge branch 'master' of https://github.com/OpenAPITools/openapi-gene…
sebastien-rosset May 22, 2020
42a4113
Merge branch 'master' of github.com:CiscoM31/openapi-generator into p…
sebastien-rosset May 22, 2020
bc6358d
fix deprecation warning
sebastien-rosset May 22, 2020
1fcbc89
fix deprecation warning
sebastien-rosset May 22, 2020
c611d0b
fix deprecation warning
sebastien-rosset May 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
required_properties = set([
'_data_store',
'_check_type',
'_from_server',
'_spec_property_naming',
'_path_to_item',
'_configuration',
'_visited_composed_classes',
Expand All @@ -15,7 +15,7 @@
constant_args = {
'_check_type': _check_type,
'_path_to_item': _path_to_item,
'_from_server': _from_server,
'_spec_property_naming': _spec_property_naming,
'_configuration': _configuration,
'_visited_composed_classes': self._visited_composed_classes,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
required_properties = set([
'_data_store',
'_check_type',
'_from_server',
'_spec_property_naming',
'_path_to_item',
'_configuration',
'_visited_composed_classes',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@convert_js_args_to_python_args
def __init__(self{{#requiredVars}}{{^defaultValue}}, {{name}}{{/defaultValue}}{{/requiredVars}}{{#requiredVars}}{{#defaultValue}}, {{name}}={{{defaultValue}}}{{/defaultValue}}{{/requiredVars}}, _check_type=True, _from_server=False, _path_to_item=(), _configuration=None, _visited_composed_classes=(), **kwargs): # noqa: E501
def __init__(self{{#requiredVars}}{{^defaultValue}}, {{name}}{{/defaultValue}}{{/requiredVars}}{{#requiredVars}}{{#defaultValue}}, {{name}}={{{defaultValue}}}{{/defaultValue}}{{/requiredVars}}, _check_type=True, _spec_property_naming=False, _path_to_item=(), _configuration=None, _visited_composed_classes=(), **kwargs): # noqa: E501
"""{{classname}} - a model defined in OpenAPI

{{#requiredVars}}
Expand All @@ -26,8 +26,10 @@
_path_to_item (tuple/list): This is a list of keys or values to
drill down to the model in received_data
when deserializing a response
_from_server (bool): True if the data is from the server
False if the data is from the client (default)
_spec_property_naming (bool): True if the variable names in the input data
are serialized names, as specified in the OpenAPI document.
False if the variable names in the input data
are pythonic names, e.g. snake case (default)
_configuration (Configuration): the instance to use when
deserializing a file_type parameter.
If passed, type conversion is attempted
Expand All @@ -54,7 +56,7 @@

self._data_store = {}
self._check_type = _check_type
self._from_server = _from_server
self._spec_property_naming = _spec_property_naming
self._path_to_item = _path_to_item
self._configuration = _configuration
self._visited_composed_classes = _visited_composed_classes + (self.__class__,)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

if self._check_type:
value = validate_and_convert_types(
value, required_types_mixed, path_to_item, self._from_server,
value, required_types_mixed, path_to_item, self._spec_property_naming,
self._check_type, configuration=self._configuration)
if (name,) in self.allowed_values:
check_allowed_values(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,17 @@ def order_response_types(required_types):
return sorted_types


def remove_uncoercible(required_types_classes, current_item, from_server,
def remove_uncoercible(required_types_classes, current_item, spec_property_naming,
must_convert=True):
"""Only keeps the type conversions that are possible

Args:
required_types_classes (tuple): tuple of classes that are required
these should be ordered by COERCION_INDEX_BY_TYPE
from_server (bool): a boolean of whether the data is from the server
if false, the data is from the client
spec_property_naming (bool): True if the variable names in the input
data are serialized names as specified in the OpenAPI document.
False if the variables names in the input data are python
variable names in PEP-8 snake case.
current_item (any): the current item (input data) to be converted

Keyword Args:
Expand Down Expand Up @@ -602,7 +604,7 @@ def remove_uncoercible(required_types_classes, current_item, from_server,
continue

class_pair = (current_type_simple, required_type_class_simplified)
if must_convert and class_pair in COERCIBLE_TYPE_PAIRS[from_server]:
if must_convert and class_pair in COERCIBLE_TYPE_PAIRS[spec_property_naming]:
results_classes.append(required_type_class)
elif class_pair in UPCONVERSION_TYPE_PAIRS:
results_classes.append(required_type_class)
Expand Down Expand Up @@ -786,7 +788,7 @@ def get_discriminator_class(model_class,


def deserialize_model(model_data, model_class, path_to_item, check_type,
configuration, from_server):
configuration, spec_property_naming):
"""Deserializes model_data to model instance.

Args:
Expand All @@ -796,8 +798,10 @@ def deserialize_model(model_data, model_class, path_to_item, check_type,
check_type (bool): whether to check the data tupe for the values in
the model
configuration (Configuration): the instance to use to convert files
from_server (bool): True if the data is from the server
False if the data is from the client
spec_property_naming (bool): True if the variable names in the input
data are serialized names as specified in the OpenAPI document.
False if the variables names in the input data are python
variable names in PEP-8 snake case.

Returns:
model instance
Expand All @@ -811,7 +815,7 @@ def deserialize_model(model_data, model_class, path_to_item, check_type,
kw_args = dict(_check_type=check_type,
_path_to_item=path_to_item,
_configuration=configuration,
_from_server=from_server)
_spec_property_naming=spec_property_naming)

if issubclass(model_class, ModelSimple):
instance = model_class(value=model_data, **kw_args)
Expand Down Expand Up @@ -862,16 +866,18 @@ def deserialize_file(response_data, configuration, content_disposition=None):


def attempt_convert_item(input_value, valid_classes, path_to_item,
configuration, from_server, key_type=False,
configuration, spec_property_naming, key_type=False,
must_convert=False, check_type=True):
"""
Args:
input_value (any): the data to convert
valid_classes (any): the classes that are valid
path_to_item (list): the path to the item to convert
configuration (Configuration): the instance to use to convert files
from_server (bool): True if data is from the server, False is data is
from the client
spec_property_naming (bool): True if the variable names in the input
data are serialized names as specified in the OpenAPI document.
False if the variables names in the input data are python
variable names in PEP-8 snake case.
key_type (bool): if True we need to convert a key type (not supported)
must_convert (bool): if True we must convert
check_type (bool): if True we check the type or the returned data in
Expand All @@ -887,7 +893,7 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
"""
valid_classes_ordered = order_response_types(valid_classes)
valid_classes_coercible = remove_uncoercible(
valid_classes_ordered, input_value, from_server)
valid_classes_ordered, input_value, spec_property_naming)
if not valid_classes_coercible or key_type:
# we do not handle keytype errors, json will take care
# of this for us
Expand All @@ -899,7 +905,7 @@ def attempt_convert_item(input_value, valid_classes, path_to_item,
if issubclass(valid_class, OpenApiModel):
return deserialize_model(input_value, valid_class,
path_to_item, check_type,
configuration, from_server)
configuration, spec_property_naming)
elif valid_class == file_type:
return deserialize_file(input_value, configuration)
return deserialize_primitive(input_value, valid_class,
Expand Down Expand Up @@ -971,7 +977,7 @@ def is_valid_type(input_class_simple, valid_classes):


def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
from_server, _check_type, configuration=None):
spec_property_naming, _check_type, configuration=None):
"""Raises a TypeError is there is a problem, otherwise returns value

Args:
Expand All @@ -982,8 +988,10 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
path_to_item: (list) the path to the data being validated
this stores a list of keys or indices to get to the data being
validated
from_server (bool): True if data is from the server
False if data is from the client
spec_property_naming (bool): True if the variable names in the input
data are serialized names as specified in the OpenAPI document.
False if the variables names in the input data are python
variable names in PEP-8 snake case.
_check_type: (boolean) if true, type will be checked and conversion
will be attempted.
configuration: (Configuration): the configuration class to use
Expand Down Expand Up @@ -1011,7 +1019,7 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
valid_classes,
path_to_item,
configuration,
from_server,
spec_property_naming,
key_type=False,
must_convert=True
)
Expand All @@ -1024,14 +1032,14 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
if len(valid_classes) > 1 and configuration:
# there are valid classes which are not the current class
valid_classes_coercible = remove_uncoercible(
valid_classes, input_value, from_server, must_convert=False)
valid_classes, input_value, spec_property_naming, must_convert=False)
if valid_classes_coercible:
converted_instance = attempt_convert_item(
input_value,
valid_classes_coercible,
path_to_item,
configuration,
from_server,
spec_property_naming,
key_type=False,
must_convert=False
)
Expand All @@ -1058,7 +1066,7 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
inner_value,
inner_required_types,
inner_path,
from_server,
spec_property_naming,
_check_type,
configuration=configuration
)
Expand All @@ -1076,7 +1084,7 @@ def validate_and_convert_types(input_value, required_types_mixed, path_to_item,
inner_val,
inner_required_types,
inner_path,
from_server,
spec_property_naming,
_check_type,
configuration=configuration
)
Expand Down Expand Up @@ -1182,8 +1190,8 @@ def convert_js_args_to_python_args(fn):
from functools import wraps
@wraps(fn)
def wrapped_init(self, *args, **kwargs):
from_server = kwargs.get('_from_server', False)
if from_server:
spec_property_naming = kwargs.get('_spec_property_naming', False)
if spec_property_naming:
kwargs = change_keys_js_to_python(kwargs, self.__class__)
return fn(self, *args, **kwargs)
return wrapped_init
Expand Down
Loading