Fixes double serialization bug in python-experimental (#12561)

* Partial template update, simplifies ref6570 serialization

* Updated serialization

* Typo fixes

* Fixes test_query_style_form_serialization

* Fixes test_cookie_style_form_serialization

* FIxes test_style_simple_in_path_serialization

* Fixes test_style_simple_in_header_serialization

* Fixes many parameter tests

* Deletes duplicate method

* Fixes TestParameter.test_path_params_no_style

* Fixes test_style_pipe_delimited_serialization

* Fixes test_header_params_no_style

* Fixes test_style_space_delimited_serialization

* Fixes test_query_style_form_serialization

* Fixes test_cookie_style_form_serialization

* Fixes test_query_params_no_style

* Fixes test_cookie_params_no_style

* Fixes test_delete_endpoint_without_request_body

* Fixes all tests

* Reverts version file

* Adds test_get_user_by_name to test path param url encoding

* Adds test_body_with_query_params

* Samples regenerated
This commit is contained in:
Justin Black 2022-06-13 07:45:15 -07:00 committed by GitHub
parent 3190084134
commit a00ae4631d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
66 changed files with 1374 additions and 1077 deletions

View File

@ -49,9 +49,12 @@ class RequestField(RequestFieldBase):
class JSONEncoder(json.JSONEncoder): class JSONEncoder(json.JSONEncoder):
def default(self, obj): def default(self, obj):
if isinstance(obj, (str, int, float)): if isinstance(obj, str):
# instances based on primitive classes return str(obj)
return obj elif isinstance(obj, float):
return float(obj)
elif isinstance(obj, int):
return int(obj)
elif isinstance(obj, Decimal): elif isinstance(obj, Decimal):
if obj.as_tuple().exponent >= 0: if obj.as_tuple().exponent >= 0:
return int(obj) return int(obj)
@ -84,180 +87,175 @@ class ParameterStyle(enum.Enum):
DEEP_OBJECT = 'deepObject' DEEP_OBJECT = 'deepObject'
class PrefixSeparatorIterator:
# A class to store prefixes and separators for rfc6570 expansions
def __init__(self, prefix: str, separator: str):
self.prefix = prefix
self.separator = separator
self.first = True
if separator in {'.', '|', '%20'}:
item_separator = separator
else:
item_separator = ','
self.item_separator = item_separator
def __iter__(self):
return self
def __next__(self):
if self.first:
self.first = False
return self.prefix
return self.separator
class ParameterSerializerBase: class ParameterSerializerBase:
@staticmethod @classmethod
def __serialize_number( def get_default_explode(cls, style: ParameterStyle) -> bool:
in_data: typing.Union[int, float], name: str, prefix='' return False
) -> typing.Tuple[typing.Tuple[str, str]]:
return tuple([(name, prefix + str(in_data))])
@staticmethod @staticmethod
def __serialize_str( def __ref6570_item_value(in_data: typing.Any, percent_encode: bool):
in_data: str, name: str, prefix='' """
) -> typing.Tuple[typing.Tuple[str, str]]: Get representation if str/float/int/None/items in list/ values in dict
return tuple([(name, prefix + quote(in_data))]) None is returned if an item is undefined, use cases are value=
- None
@staticmethod - []
def __serialize_bool(in_data: bool, name: str, prefix='') -> typing.Tuple[typing.Tuple[str, str]]: - {}
if in_data: - [None, None None]
return tuple([(name, prefix + 'true')]) - {'a': None, 'b': None}
return tuple([(name, prefix + 'false')]) """
if type(in_data) in {str, float, int}:
@staticmethod if percent_encode:
def __urlencode(in_data: typing.Any) -> str: return quote(str(in_data))
return quote(str(in_data)) return str(in_data)
elif isinstance(in_data, none_type):
def __serialize_list( # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
self,
in_data: typing.List[typing.Any],
style: ParameterStyle,
name: str,
explode: bool,
empty_val: typing.Union[typing.Tuple[str, str], typing.Tuple] = tuple(),
prefix: str = '',
separator: str = ',',
) -> typing.Tuple[typing.Union[typing.Tuple[str, str], typing.Tuple], ...]:
if not in_data:
return empty_val
if explode and style in {
ParameterStyle.FORM,
ParameterStyle.MATRIX,
ParameterStyle.SPACE_DELIMITED,
ParameterStyle.PIPE_DELIMITED
}:
if style is ParameterStyle.FORM:
return tuple((name, prefix + self.__urlencode(val)) for val in in_data)
else:
joined_vals = prefix + separator.join(name + '=' + self.__urlencode(val) for val in in_data)
else:
joined_vals = prefix + separator.join(map(self.__urlencode, in_data))
return tuple([(name, joined_vals)])
def __form_item_representation(self, in_data: typing.Any) -> typing.Optional[str]:
if isinstance(in_data, none_type):
return None return None
elif isinstance(in_data, list): elif isinstance(in_data, list) and not in_data:
if not in_data: # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
return None return None
raise ApiValueError('Unable to generate a form representation of {}'.format(in_data)) elif isinstance(in_data, dict) and not in_data:
elif isinstance(in_data, dict): # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
if not in_data: return None
return None raise ApiValueError('Unable to generate a ref6570 item representation of {}'.format(in_data))
raise ApiValueError('Unable to generate a form representation of {}'.format(in_data))
elif isinstance(in_data, (bool, bytes)):
raise ApiValueError('Unable to generate a form representation of {}'.format(in_data))
# str, float, int
return self.__urlencode(in_data)
def __serialize_dict( @staticmethod
self, def to_dict(name: str, value: str):
in_data: typing.Dict[str, typing.Any], return {name: value}
style: ParameterStyle,
name: str, @classmethod
def ref6570_expansion(
cls,
variable_name: str,
in_data: typing.Any,
explode: bool, explode: bool,
empty_val: typing.Union[typing.Tuple[str, str], typing.Tuple] = tuple(), percent_encode: bool,
prefix: str = '', prefix_separator_iterator: PrefixSeparatorIterator
separator: str = ',', ) -> str:
) -> typing.Tuple[typing.Tuple[str, str]]: """
if not in_data: Separator is for separate variables like dict with explode true, not for array item separation
return empty_val """
if all(val is None for val in in_data.values()): named_parameter_expansion = prefix_separator_iterator.separator in {'&', ';'}
return empty_val var_name_piece = variable_name if named_parameter_expansion else ''
if type(in_data) in {str, float, int}:
form_items = {} item_value = cls.__ref6570_item_value(in_data, percent_encode)
if style is ParameterStyle.FORM: if item_value is None:
for key, val in in_data.items(): return next(prefix_separator_iterator) + var_name_piece
new_val = self.__form_item_representation(val) elif item_value == '' and prefix_separator_iterator.separator == ';':
if new_val is None: return next(prefix_separator_iterator) + var_name_piece
continue value_pair_equals = '=' if named_parameter_expansion else ''
form_items[key] = new_val return next(prefix_separator_iterator) + var_name_piece + value_pair_equals + item_value
elif isinstance(in_data, none_type):
if explode: # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
if style is ParameterStyle.FORM: return ""
return tuple((key, prefix + val) for key, val in form_items.items())
elif style in {
ParameterStyle.SIMPLE,
ParameterStyle.LABEL,
ParameterStyle.MATRIX,
ParameterStyle.SPACE_DELIMITED,
ParameterStyle.PIPE_DELIMITED
}:
joined_vals = prefix + separator.join(key + '=' + self.__urlencode(val) for key, val in in_data.items())
else:
raise ApiValueError(f'Invalid style {style} for dict serialization with explode=True')
elif style is ParameterStyle.FORM:
joined_vals = prefix + separator.join(key + separator + val for key, val in form_items.items())
else:
joined_vals = prefix + separator.join(
key + separator + self.__urlencode(val) for key, val in in_data.items())
return tuple([(name, joined_vals)])
def _serialize_x(
self,
in_data: typing.Union[None, int, float, str, bool, dict, list],
style: ParameterStyle,
name: str,
explode: bool,
empty_val: typing.Union[typing.Tuple[str, str], typing.Tuple] = (),
prefix: str = '',
separator: str = ',',
) -> typing.Tuple[typing.Tuple[str, str], ...]:
if isinstance(in_data, none_type):
return empty_val
elif isinstance(in_data, bool):
# must be before int check
return self.__serialize_bool(in_data, name=name, prefix=prefix)
elif isinstance(in_data, (int, float)):
return self.__serialize_number(in_data, name=name, prefix=prefix)
elif isinstance(in_data, str):
return self.__serialize_str(in_data, name=name, prefix=prefix)
elif isinstance(in_data, list): elif isinstance(in_data, list):
return self.__serialize_list( item_values = [cls.__ref6570_item_value(v, percent_encode) for v in in_data]
in_data, item_values = [v for v in item_values if v is not None]
style=style, if not item_values:
name=name, # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
explode=explode, return ""
empty_val=empty_val, value_pair_equals = '=' if named_parameter_expansion else ''
prefix=prefix, if not explode:
separator=separator return (
next(prefix_separator_iterator) +
var_name_piece +
value_pair_equals +
prefix_separator_iterator.item_separator.join(item_values)
)
# exploded
return next(prefix_separator_iterator) + next(prefix_separator_iterator).join(
[var_name_piece + value_pair_equals + val for val in item_values]
) )
elif isinstance(in_data, dict): elif isinstance(in_data, dict):
return self.__serialize_dict( in_data_transformed = {key: cls.__ref6570_item_value(val, percent_encode) for key, val in in_data.items()}
in_data, in_data_transformed = {key: val for key, val in in_data_transformed.items() if val is not None}
style=style, if not in_data_transformed:
name=name, # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
explode=explode, return ""
empty_val=empty_val, value_pair_equals = '=' if named_parameter_expansion else ''
prefix=prefix, if not explode:
separator=separator return (
next(prefix_separator_iterator) +
var_name_piece + value_pair_equals +
prefix_separator_iterator.item_separator.join(
prefix_separator_iterator.item_separator.join(
item_pair
) for item_pair in in_data_transformed.items()
)
)
# exploded
return next(prefix_separator_iterator) + next(prefix_separator_iterator).join(
[key + '=' + val for key, val in in_data_transformed.items()]
) )
# bool, bytes, etc
raise ApiValueError('Unable to generate a ref6570 representation of {}'.format(in_data))
class StyleFormSerializer(ParameterSerializerBase): class StyleFormSerializer(ParameterSerializerBase):
@classmethod
def get_default_explode(cls, style: ParameterStyle) -> bool:
if style is ParameterStyle.FORM:
return True
return super().get_default_explode(style)
def _serialize_form( def serialize_form(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list], in_data: typing.Union[None, int, float, str, bool, dict, list],
name: str, name: str,
explode: bool, explode: bool,
) -> typing.Tuple[typing.Tuple[str, str], ...]: percent_encode: bool,
return self._serialize_x(in_data, style=ParameterStyle.FORM, name=name, explode=explode) prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator] = None
) -> str:
if prefix_separator_iterator is None:
prefix_separator_iterator = PrefixSeparatorIterator('?', '&')
return self.ref6570_expansion(
variable_name=name,
in_data=in_data,
explode=explode,
percent_encode=percent_encode,
prefix_separator_iterator=prefix_separator_iterator
)
class StyleSimpleSerializer(ParameterSerializerBase): class StyleSimpleSerializer(ParameterSerializerBase):
def _serialize_simple_tuple( def serialize_simple(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list], in_data: typing.Union[None, int, float, str, bool, dict, list],
name: str, name: str,
explode: bool, explode: bool,
in_type: ParameterInType, percent_encode: bool
) -> typing.Tuple[typing.Tuple[str, str], ...]: ) -> str:
if in_type is ParameterInType.HEADER: prefix_separator_iterator = PrefixSeparatorIterator('', ',')
empty_val = () return self.ref6570_expansion(
else: variable_name=name,
empty_val = ((name, ''),) in_data=in_data,
return self._serialize_x(in_data, style=ParameterStyle.SIMPLE, name=name, explode=explode, empty_val=empty_val) explode=explode,
percent_encode=percent_encode,
prefix_separator_iterator=prefix_separator_iterator
)
@dataclass @dataclass
@ -345,8 +343,8 @@ class ParameterBase:
def _serialize_json( def _serialize_json(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list]
) -> typing.Tuple[typing.Tuple[str, str]]: ) -> str:
return tuple([(self.name, json.dumps(in_data))]) return json.dumps(in_data)
class PathParameter(ParameterBase, StyleSimpleSerializer): class PathParameter(ParameterBase, StyleSimpleSerializer):
@ -372,56 +370,45 @@ class PathParameter(ParameterBase, StyleSimpleSerializer):
content=content content=content
) )
def __serialize_label( def _serialize_label(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list]
) -> typing.Dict[str, str]: ) -> typing.Dict[str, str]:
empty_val = ((self.name, ''),) prefix_separator_iterator = PrefixSeparatorIterator('.', '.')
prefix = '.' value = self.ref6570_expansion(
separator = '.' variable_name=self.name,
return self._remove_empty_and_cast( in_data=in_data,
self._serialize_x( explode=self.explode,
in_data, percent_encode=True,
style=ParameterStyle.LABEL, prefix_separator_iterator=prefix_separator_iterator
name=self.name,
explode=self.explode,
empty_val=empty_val,
prefix=prefix,
separator=separator
)
) )
return self.to_dict(self.name, value)
def __serialize_matrix( def _serialize_matrix(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list]
) -> typing.Dict[str, str]: ) -> typing.Dict[str, str]:
separator = ',' prefix_separator_iterator = PrefixSeparatorIterator(';', ';')
if in_data == '': value = self.ref6570_expansion(
prefix = ';' + self.name variable_name=self.name,
elif isinstance(in_data, (dict, list)) and self.explode: in_data=in_data,
prefix = ';' explode=self.explode,
separator = ';' percent_encode=True,
else: prefix_separator_iterator=prefix_separator_iterator
prefix = ';' + self.name + '='
empty_val = ((self.name, ''),)
return self._remove_empty_and_cast(
self._serialize_x(
in_data,
style=ParameterStyle.MATRIX,
name=self.name,
explode=self.explode,
prefix=prefix,
empty_val=empty_val,
separator=separator
)
) )
return self.to_dict(self.name, value)
def _serialize_simple( def _serialize_simple(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list], in_data: typing.Union[None, int, float, str, bool, dict, list],
) -> typing.Dict[str, str]: ) -> typing.Dict[str, str]:
tuple_data = self._serialize_simple_tuple(in_data, self.name, self.explode, self.in_type) value = self.serialize_simple(
return self._remove_empty_and_cast(tuple_data) in_data=in_data,
name=self.name,
explode=self.explode,
percent_encode=True
)
return self.to_dict(self.name, value)
def serialize( def serialize(
self, self,
@ -444,16 +431,16 @@ class PathParameter(ParameterBase, StyleSimpleSerializer):
if self.style is ParameterStyle.SIMPLE: if self.style is ParameterStyle.SIMPLE:
return self._serialize_simple(cast_in_data) return self._serialize_simple(cast_in_data)
elif self.style is ParameterStyle.LABEL: elif self.style is ParameterStyle.LABEL:
return self.__serialize_label(cast_in_data) return self._serialize_label(cast_in_data)
elif self.style is ParameterStyle.MATRIX: elif self.style is ParameterStyle.MATRIX:
return self.__serialize_matrix(cast_in_data) return self._serialize_matrix(cast_in_data)
# self.content will be length one # self.content will be length one
for content_type, schema in self.content.items(): for content_type, schema in self.content.items():
cast_in_data = schema(in_data) cast_in_data = schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
if content_type == self._json_content_type: if content_type == self._json_content_type:
tuple_data = self._serialize_json(cast_in_data) value = self._serialize_json(cast_in_data)
return self._remove_empty_and_cast(tuple_data) return self.to_dict(self.name, value)
raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type)) raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type))
@ -464,17 +451,20 @@ class QueryParameter(ParameterBase, StyleFormSerializer):
name: str, name: str,
required: bool = False, required: bool = False,
style: typing.Optional[ParameterStyle] = None, style: typing.Optional[ParameterStyle] = None,
explode: bool = False, explode: typing.Optional[bool] = None,
allow_reserved: typing.Optional[bool] = None, allow_reserved: typing.Optional[bool] = None,
schema: typing.Optional[typing.Type[Schema]] = None, schema: typing.Optional[typing.Type[Schema]] = None,
content: typing.Optional[typing.Dict[str, typing.Type[Schema]]] = None content: typing.Optional[typing.Dict[str, typing.Type[Schema]]] = None
): ):
used_style = ParameterStyle.FORM if style is None and content is None and schema else style
used_explode = self.get_default_explode(used_style) if explode is None else explode
super().__init__( super().__init__(
name, name,
in_type=ParameterInType.QUERY, in_type=ParameterInType.QUERY,
required=required, required=required,
style=style, style=used_style,
explode=explode, explode=used_explode,
allow_reserved=allow_reserved, allow_reserved=allow_reserved,
schema=schema, schema=schema,
content=content content=content
@ -482,39 +472,68 @@ class QueryParameter(ParameterBase, StyleFormSerializer):
def __serialize_space_delimited( def __serialize_space_delimited(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list],
) -> typing.Tuple[typing.Tuple[str, str], ...]: prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator]
separator = '%20' ) -> typing.Dict[str, str]:
empty_val = () if prefix_separator_iterator is None:
return self._serialize_x( prefix_separator_iterator = self.get_prefix_separator_iterator()
in_data, value = self.ref6570_expansion(
style=ParameterStyle.SPACE_DELIMITED, variable_name=self.name,
name=self.name, in_data=in_data,
explode=self.explode, explode=self.explode,
separator=separator, percent_encode=True,
empty_val=empty_val prefix_separator_iterator=prefix_separator_iterator
) )
return self.to_dict(self.name, value)
def __serialize_pipe_delimited( def __serialize_pipe_delimited(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list],
) -> typing.Tuple[typing.Tuple[str, str], ...]: prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator]
separator = '|' ) -> typing.Dict[str, str]:
empty_val = () if prefix_separator_iterator is None:
return self._serialize_x( prefix_separator_iterator = self.get_prefix_separator_iterator()
value = self.ref6570_expansion(
variable_name=self.name,
in_data=in_data,
explode=self.explode,
percent_encode=True,
prefix_separator_iterator=prefix_separator_iterator
)
return self.to_dict(self.name, value)
def __serialize_form(
self,
in_data: typing.Union[None, int, float, str, bool, dict, list],
prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator]
) -> typing.Dict[str, str]:
if prefix_separator_iterator is None:
prefix_separator_iterator = self.get_prefix_separator_iterator()
value = self.serialize_form(
in_data, in_data,
style=ParameterStyle.PIPE_DELIMITED,
name=self.name, name=self.name,
explode=self.explode, explode=self.explode,
separator=separator, percent_encode=True,
empty_val=empty_val prefix_separator_iterator=prefix_separator_iterator
) )
return self.to_dict(self.name, value)
def get_prefix_separator_iterator(self) -> typing.Optional[PrefixSeparatorIterator]:
if not self.schema:
return None
if self.style is ParameterStyle.FORM:
return PrefixSeparatorIterator('?', '&')
elif self.style is ParameterStyle.SPACE_DELIMITED:
return PrefixSeparatorIterator('', '%20')
elif self.style is ParameterStyle.PIPE_DELIMITED:
return PrefixSeparatorIterator('', '|')
def serialize( def serialize(
self, self,
in_data: typing.Union[ in_data: typing.Union[
Schema, Decimal, int, float, str, date, datetime, None, bool, list, tuple, dict, frozendict] Schema, Decimal, int, float, str, date, datetime, None, bool, list, tuple, dict, frozendict],
) -> typing.Tuple[typing.Tuple[str, str]]: prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator] = None
) -> typing.Dict[str, str]:
if self.schema: if self.schema:
cast_in_data = self.schema(in_data) cast_in_data = self.schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
@ -534,17 +553,18 @@ class QueryParameter(ParameterBase, StyleFormSerializer):
if self.style: if self.style:
# TODO update query ones to omit setting values when [] {} or None is input # TODO update query ones to omit setting values when [] {} or None is input
if self.style is ParameterStyle.FORM: if self.style is ParameterStyle.FORM:
return self._serialize_form(cast_in_data, explode=self.explode, name=self.name) return self.__serialize_form(cast_in_data, prefix_separator_iterator)
elif self.style is ParameterStyle.SPACE_DELIMITED: elif self.style is ParameterStyle.SPACE_DELIMITED:
return self.__serialize_space_delimited(cast_in_data) return self.__serialize_space_delimited(cast_in_data, prefix_separator_iterator)
elif self.style is ParameterStyle.PIPE_DELIMITED: elif self.style is ParameterStyle.PIPE_DELIMITED:
return self.__serialize_pipe_delimited(cast_in_data) return self.__serialize_pipe_delimited(cast_in_data, prefix_separator_iterator)
# self.content will be length one # self.content will be length one
for content_type, schema in self.content.items(): for content_type, schema in self.content.items():
cast_in_data = schema(in_data) cast_in_data = schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
if content_type == self._json_content_type: if content_type == self._json_content_type:
return self._serialize_json(cast_in_data) value = self._serialize_json(cast_in_data)
return self.to_dict(self.name, value)
raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type)) raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type))
@ -555,17 +575,20 @@ class CookieParameter(ParameterBase, StyleFormSerializer):
name: str, name: str,
required: bool = False, required: bool = False,
style: typing.Optional[ParameterStyle] = None, style: typing.Optional[ParameterStyle] = None,
explode: bool = False, explode: typing.Optional[bool] = None,
allow_reserved: typing.Optional[bool] = None, allow_reserved: typing.Optional[bool] = None,
schema: typing.Optional[typing.Type[Schema]] = None, schema: typing.Optional[typing.Type[Schema]] = None,
content: typing.Optional[typing.Dict[str, typing.Type[Schema]]] = None content: typing.Optional[typing.Dict[str, typing.Type[Schema]]] = None
): ):
used_style = ParameterStyle.FORM if style is None and content is None and schema else style
used_explode = self.get_default_explode(used_style) if explode is None else explode
super().__init__( super().__init__(
name, name,
in_type=ParameterInType.COOKIE, in_type=ParameterInType.COOKIE,
required=required, required=required,
style=style, style=used_style,
explode=explode, explode=used_explode,
allow_reserved=allow_reserved, allow_reserved=allow_reserved,
schema=schema, schema=schema,
content=content content=content
@ -575,7 +598,7 @@ class CookieParameter(ParameterBase, StyleFormSerializer):
self, self,
in_data: typing.Union[ in_data: typing.Union[
Schema, Decimal, int, float, str, date, datetime, None, bool, list, tuple, dict, frozendict] Schema, Decimal, int, float, str, date, datetime, None, bool, list, tuple, dict, frozendict]
) -> typing.Tuple[typing.Tuple[str, str]]: ) -> typing.Dict[str, str]:
if self.schema: if self.schema:
cast_in_data = self.schema(in_data) cast_in_data = self.schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
@ -584,13 +607,25 @@ class CookieParameter(ParameterBase, StyleFormSerializer):
returns fields: tuple returns fields: tuple
""" """
if self.style: if self.style:
return self._serialize_form(cast_in_data, explode=self.explode, name=self.name) """
TODO add escaping of comma, space, equals
or turn encoding on
"""
value = self.serialize_form(
cast_in_data,
explode=self.explode,
name=self.name,
percent_encode=False,
prefix_separator_iterator=PrefixSeparatorIterator('', '&')
)
return self.to_dict(self.name, value)
# self.content will be length one # self.content will be length one
for content_type, schema in self.content.items(): for content_type, schema in self.content.items():
cast_in_data = schema(in_data) cast_in_data = schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
if content_type == self._json_content_type: if content_type == self._json_content_type:
return self._serialize_json(cast_in_data) value = self._serialize_json(cast_in_data)
return self.to_dict(self.name, value)
raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type)) raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type))
@ -628,9 +663,8 @@ class HeaderParameter(ParameterBase, StyleSimpleSerializer):
def _serialize_simple( def _serialize_simple(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list], in_data: typing.Union[None, int, float, str, bool, dict, list],
) -> HTTPHeaderDict[str, str]: ) -> str:
tuple_data = self._serialize_simple_tuple(in_data, self.name, self.explode, self.in_type) return self.serialize_simple(in_data, self.name, self.explode, False)
return self.__to_headers(tuple_data)
def serialize( def serialize(
self, self,
@ -646,14 +680,15 @@ class HeaderParameter(ParameterBase, StyleSimpleSerializer):
returns headers: dict returns headers: dict
""" """
if self.style: if self.style:
return self._serialize_simple(cast_in_data) value = self._serialize_simple(cast_in_data)
return self.__to_headers(((self.name, value),))
# self.content will be length one # self.content will be length one
for content_type, schema in self.content.items(): for content_type, schema in self.content.items():
cast_in_data = schema(in_data) cast_in_data = schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
if content_type == self._json_content_type: if content_type == self._json_content_type:
tuple_data = self._serialize_json(cast_in_data) value = self._serialize_json(cast_in_data)
return self.__to_headers(tuple_data) return self.__to_headers(((self.name, value),))
raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type)) raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type))
@ -934,8 +969,6 @@ class ApiClient:
self, self,
resource_path: str, resource_path: str,
method: str, method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None, headers: typing.Optional[HTTPHeaderDict] = None,
body: typing.Optional[typing.Union[str, bytes]] = None, body: typing.Optional[typing.Union[str, bytes]] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None, fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
@ -951,17 +984,8 @@ class ApiClient:
if self.cookie: if self.cookie:
headers['Cookie'] = self.cookie headers['Cookie'] = self.cookie
# path parameters
if path_params:
for k, v in path_params.items():
# specified safe chars, encode everything
resource_path = resource_path.replace(
'{%s}' % k,
quote(str(v), safe=self.configuration.safe_chars_for_path_param)
)
# auth setting # auth setting
self.update_params_for_auth(headers, query_params, self.update_params_for_auth(headers,
auth_settings, resource_path, method, body) auth_settings, resource_path, method, body)
# request url # request url
@ -975,7 +999,6 @@ class ApiClient:
response = {{#if asyncio}}await {{/if}}{{#if tornado}}yield {{/if}}self.request( response = {{#if asyncio}}await {{/if}}{{#if tornado}}yield {{/if}}self.request(
method, method,
url, url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
body=body, body=body,
@ -988,8 +1011,6 @@ class ApiClient:
self, self,
resource_path: str, resource_path: str,
method: str, method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None, headers: typing.Optional[HTTPHeaderDict] = None,
body: typing.Optional[typing.Union[str, bytes]] = None, body: typing.Optional[typing.Union[str, bytes]] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None, fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
@ -1005,8 +1026,6 @@ class ApiClient:
:param resource_path: Path to method endpoint. :param resource_path: Path to method endpoint.
:param method: Method to call. :param method: Method to call.
:param path_params: Path parameters in the url.
:param query_params: Query parameters in the url.
:param headers: Header parameters to be :param headers: Header parameters to be
placed in the request header. placed in the request header.
:param body: Request body. :param body: Request body.
@ -1039,8 +1058,6 @@ class ApiClient:
return self.__call_api( return self.__call_api(
resource_path, resource_path,
method, method,
path_params,
query_params,
headers, headers,
body, body,
fields, fields,
@ -1055,8 +1072,6 @@ class ApiClient:
( (
resource_path, resource_path,
method, method,
path_params,
query_params,
headers, headers,
body, body,
json, json,
@ -1072,7 +1087,6 @@ class ApiClient:
self, self,
method: str, method: str,
url: str, url: str,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None, headers: typing.Optional[HTTPHeaderDict] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None, fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
body: typing.Optional[typing.Union[str, bytes]] = None, body: typing.Optional[typing.Union[str, bytes]] = None,
@ -1082,19 +1096,16 @@ class ApiClient:
"""Makes the HTTP request using RESTClient.""" """Makes the HTTP request using RESTClient."""
if method == "GET": if method == "GET":
return self.rest_client.GET(url, return self.rest_client.GET(url,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
headers=headers) headers=headers)
elif method == "HEAD": elif method == "HEAD":
return self.rest_client.HEAD(url, return self.rest_client.HEAD(url,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
headers=headers) headers=headers)
elif method == "OPTIONS": elif method == "OPTIONS":
return self.rest_client.OPTIONS(url, return self.rest_client.OPTIONS(url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
stream=stream, stream=stream,
@ -1102,7 +1113,6 @@ class ApiClient:
body=body) body=body)
elif method == "POST": elif method == "POST":
return self.rest_client.POST(url, return self.rest_client.POST(url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
stream=stream, stream=stream,
@ -1110,7 +1120,6 @@ class ApiClient:
body=body) body=body)
elif method == "PUT": elif method == "PUT":
return self.rest_client.PUT(url, return self.rest_client.PUT(url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
stream=stream, stream=stream,
@ -1118,7 +1127,6 @@ class ApiClient:
body=body) body=body)
elif method == "PATCH": elif method == "PATCH":
return self.rest_client.PATCH(url, return self.rest_client.PATCH(url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
stream=stream, stream=stream,
@ -1126,7 +1134,6 @@ class ApiClient:
body=body) body=body)
elif method == "DELETE": elif method == "DELETE":
return self.rest_client.DELETE(url, return self.rest_client.DELETE(url,
query_params=query_params,
headers=headers, headers=headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
@ -1137,12 +1144,11 @@ class ApiClient:
" `POST`, `PATCH`, `PUT` or `DELETE`." " `POST`, `PATCH`, `PUT` or `DELETE`."
) )
def update_params_for_auth(self, headers, querys, auth_settings, def update_params_for_auth(self, headers, auth_settings,
resource_path, method, body): resource_path, method, body):
"""Updates header and query params based on authentication setting. """Updates header and query params based on authentication setting.
:param headers: Header parameters dict to be updated. :param headers: Header parameters dict to be updated.
:param querys: Query parameters tuple list to be updated.
:param auth_settings: Authentication setting identifiers list. :param auth_settings: Authentication setting identifiers list.
:param resource_path: A string representation of the HTTP request resource path. :param resource_path: A string representation of the HTTP request resource path.
:param method: A string representation of the HTTP request method. :param method: A string representation of the HTTP request method.
@ -1165,13 +1171,18 @@ class ApiClient:
# The HTTP signature scheme requires multiple HTTP headers # The HTTP signature scheme requires multiple HTTP headers
# that are calculated dynamically. # that are calculated dynamically.
signing_info = self.configuration.signing_info signing_info = self.configuration.signing_info
querys = tuple()
auth_headers = signing_info.get_http_signature_headers( auth_headers = signing_info.get_http_signature_headers(
resource_path, method, headers, body, querys) resource_path, method, headers, body, querys)
for key, value in auth_headers.items(): for key, value in auth_headers.items():
headers.add(key, value) headers.add(key, value)
{{/if}} {{/if}}
elif auth_setting['in'] == 'query': elif auth_setting['in'] == 'query':
querys.append((auth_setting['key'], auth_setting['value'])) """ TODO implement auth in query
need to pass in prefix_separator_iterator
and need to output resource_path with query params added
"""
raise ApiValueError("Auth in query not yet implemented")
else: else:
raise ApiValueError( raise ApiValueError(
'Authentication token must be in `query` or `header`' 'Authentication token must be in `query` or `header`'
@ -1374,15 +1385,16 @@ class RequestBody(StyleFormSerializer, JSONDetector):
def __serialize_application_x_www_form_data( def __serialize_application_x_www_form_data(
self, in_data: typing.Any self, in_data: typing.Any
) -> typing.Dict[str, tuple[tuple[str, str], ...]]: ) -> SerializedRequestBody:
"""
POST submission of form data in body
"""
if not isinstance(in_data, frozendict): if not isinstance(in_data, frozendict):
raise ValueError( raise ValueError(
f'Unable to serialize {in_data} to application/x-www-form-urlencoded because it is not a dict of data') f'Unable to serialize {in_data} to application/x-www-form-urlencoded because it is not a dict of data')
cast_in_data = self.__json_encoder.default(in_data) cast_in_data = self.__json_encoder.default(in_data)
fields = self._serialize_form(cast_in_data, explode=True, name='') value = self.serialize_form(cast_in_data, name='', explode=True, percent_encode=False)
if not fields: return dict(body=value)
return {}
return {'fields': fields}
def serialize( def serialize(
self, in_data: typing.Any, content_type: str self, in_data: typing.Any, content_type: str

View File

@ -436,6 +436,7 @@ class {{operationIdCamelCase}}(api_client.Api):
{{#if cookieParams}} {{#if cookieParams}}
self._verify_typed_dict_inputs(RequestCookieParams, cookie_params) self._verify_typed_dict_inputs(RequestCookieParams, cookie_params)
{{/if}} {{/if}}
used_path = _path
{{#if pathParams}} {{#if pathParams}}
_path_params = {} _path_params = {}
@ -449,10 +450,13 @@ class {{operationIdCamelCase}}(api_client.Api):
continue continue
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
{{/if}} {{/if}}
{{#if queryParams}} {{#if queryParams}}
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
{{#each queryParams}} {{#each queryParams}}
request_query_{{paramName}}, request_query_{{paramName}},
@ -461,8 +465,11 @@ class {{operationIdCamelCase}}(api_client.Api):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
{{/if}} {{/if}}
{{#or headerParams bodyParam produces}} {{#or headerParams bodyParam produces}}
@ -509,14 +516,8 @@ class {{operationIdCamelCase}}(api_client.Api):
{{/if}} {{/if}}
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
{{#if pathParams}}
path_params=_path_params,
{{/if}}
{{#if queryParams}}
query_params=tuple(_query_params),
{{/if}}
{{#or headerParams bodyParam produces}} {{#or headerParams bodyParam produces}}
headers=_headers, headers=_headers,
{{/or}} {{/or}}

View File

@ -83,7 +83,6 @@ class RESTClientObject(object):
self, self,
method: str, method: str,
url: str, url: str,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None, headers: typing.Optional[HTTPHeaderDict] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, typing.Any], ...]] = None, fields: typing.Optional[typing.Tuple[typing.Tuple[str, typing.Any], ...]] = None,
body: typing.Optional[typing.Union[str, bytes]] = None, body: typing.Optional[typing.Union[str, bytes]] = None,
@ -94,7 +93,6 @@ class RESTClientObject(object):
:param method: http request method :param method: http request method
:param url: http request url :param url: http request url
:param query_params: query parameters in the url
:param headers: http request headers :param headers: http request headers
:param body: request body, for other types :param body: request body, for other types
:param fields: request parameters for :param fields: request parameters for
@ -130,13 +128,10 @@ class RESTClientObject(object):
try: try:
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
if query_params:
url += '?' + urlencode(query_params)
if 'Content-Type' not in headers and body is None: if 'Content-Type' not in headers and body is None:
r = self.pool_manager.request( r = self.pool_manager.request(
method, method,
url, url,
fields=query_params,
preload_content=not stream, preload_content=not stream,
timeout=timeout, timeout=timeout,
headers=headers headers=headers
@ -181,7 +176,6 @@ class RESTClientObject(object):
# For `GET`, `HEAD` # For `GET`, `HEAD`
else: else:
r = self.pool_manager.request(method, url, r = self.pool_manager.request(method, url,
fields=query_params,
preload_content=not stream, preload_content=not stream,
timeout=timeout, timeout=timeout,
headers=headers) headers=headers)
@ -195,63 +189,58 @@ class RESTClientObject(object):
return r return r
def GET(self, url, headers=None, query_params=None, stream=False, def GET(self, url, headers=None, stream=False,
timeout=None, fields=None) -> urllib3.HTTPResponse: timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("GET", url, return self.request("GET", url,
headers=headers, headers=headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
query_params=query_params, fields=fields) fields=fields)
def HEAD(self, url, headers=None, query_params=None, stream=False, def HEAD(self, url, headers=None, stream=False,
timeout=None, fields=None) -> urllib3.HTTPResponse: timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("HEAD", url, return self.request("HEAD", url,
headers=headers, headers=headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
query_params=query_params, fields=fields) fields=fields)
def OPTIONS(self, url, headers=None, query_params=None, def OPTIONS(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("OPTIONS", url, return self.request("OPTIONS", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)
def DELETE(self, url, headers=None, query_params=None, body=None, def DELETE(self, url, headers=None, body=None,
stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("DELETE", url, return self.request("DELETE", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)
def POST(self, url, headers=None, query_params=None, def POST(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("POST", url, return self.request("POST", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)
def PUT(self, url, headers=None, query_params=None, def PUT(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("PUT", url, return self.request("PUT", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)
def PATCH(self, url, headers=None, query_params=None, def PATCH(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("PATCH", url, return self.request("PATCH", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)

View File

@ -126,6 +126,7 @@ class Call123TestSpecialTags(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -145,7 +146,7 @@ class Call123TestSpecialTags(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -137,6 +137,7 @@ class FooGet(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -145,7 +146,7 @@ class FooGet(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
stream=stream, stream=stream,

View File

@ -125,6 +125,7 @@ class AdditionalPropertiesWithArrayOfEnums(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -142,7 +143,7 @@ class AdditionalPropertiesWithArrayOfEnums(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -124,6 +124,7 @@ class ArrayModel(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -141,7 +142,7 @@ class ArrayModel(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -125,6 +125,7 @@ class ArrayOfEnums(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -142,7 +143,7 @@ class ArrayOfEnums(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -114,6 +114,7 @@ class BodyWithFileSchema(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -130,7 +131,7 @@ class BodyWithFileSchema(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -143,16 +143,20 @@ class BodyWithQueryParams(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_query, request_query_query,
): ):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -169,9 +173,8 @@ class BodyWithQueryParams(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,
body=_body, body=_body,

View File

@ -122,6 +122,7 @@ class Boolean(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -139,7 +140,7 @@ class Boolean(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -145,8 +145,9 @@ class CaseSensitiveParams(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_some_var, request_query_some_var,
request_query_some_var2, request_query_some_var2,
@ -155,14 +156,16 @@ class CaseSensitiveParams(api_client.Api):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
) )

View File

@ -126,6 +126,7 @@ class ClientModel(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -145,7 +146,7 @@ class ClientModel(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -124,6 +124,7 @@ class ComposedOneOfDifferentTypes(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -141,7 +142,7 @@ class ComposedOneOfDifferentTypes(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -141,6 +141,7 @@ class DeleteCoffee(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -151,12 +152,14 @@ class DeleteCoffee(api_client.Api):
continue continue
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
) )

View File

@ -257,6 +257,7 @@ class EndpointParameters(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -271,7 +272,7 @@ class EndpointParameters(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -427,8 +427,9 @@ class EnumParameters(api_client.Api):
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
self._verify_typed_dict_inputs(RequestHeaderParams, header_params) self._verify_typed_dict_inputs(RequestHeaderParams, header_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_enum_query_string_array, request_query_enum_query_string_array,
request_query_enum_query_string, request_query_enum_query_string,
@ -438,8 +439,11 @@ class EnumParameters(api_client.Api):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
for parameter in ( for parameter in (
@ -463,9 +467,8 @@ class EnumParameters(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,
body=_body, body=_body,

View File

@ -113,6 +113,7 @@ class FakeHealthGet(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -121,7 +122,7 @@ class FakeHealthGet(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
stream=stream, stream=stream,

View File

@ -191,8 +191,9 @@ class GroupParameters(api_client.Api):
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
self._verify_typed_dict_inputs(RequestHeaderParams, header_params) self._verify_typed_dict_inputs(RequestHeaderParams, header_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_required_string_group, request_query_required_string_group,
request_query_required_int64_group, request_query_required_int64_group,
@ -202,8 +203,11 @@ class GroupParameters(api_client.Api):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
for parameter in ( for parameter in (
@ -218,9 +222,8 @@ class GroupParameters(api_client.Api):
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
headers=_headers, headers=_headers,
auth_settings=_auth, auth_settings=_auth,
stream=stream, stream=stream,

View File

@ -132,6 +132,7 @@ class InlineAdditionalProperties(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -148,7 +149,7 @@ class InlineAdditionalProperties(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -524,8 +524,9 @@ class InlineComposition(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_composition_at_root, request_query_composition_at_root,
request_query_composition_in_property, request_query_composition_in_property,
@ -533,8 +534,11 @@ class InlineComposition(api_client.Api):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -552,9 +556,8 @@ class InlineComposition(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,
body=_body, body=_body,

View File

@ -134,6 +134,7 @@ class JsonFormData(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -148,7 +149,7 @@ class JsonFormData(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -123,6 +123,7 @@ class JsonWithCharset(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -140,7 +141,7 @@ class JsonWithCharset(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -125,6 +125,7 @@ class Mammal(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -144,7 +145,7 @@ class Mammal(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -124,6 +124,7 @@ class NumberWithValidations(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -141,7 +142,7 @@ class NumberWithValidations(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -148,22 +148,25 @@ class ObjectInQuery(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_map_bean, request_query_map_bean,
): ):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
) )

View File

@ -124,6 +124,7 @@ class ObjectModelWithRefProps(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -141,7 +142,7 @@ class ObjectModelWithRefProps(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -351,6 +351,7 @@ class ParameterCollisions(api_client.Api):
self._verify_typed_dict_inputs(RequestHeaderParams, header_params) self._verify_typed_dict_inputs(RequestHeaderParams, header_params)
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
self._verify_typed_dict_inputs(RequestCookieParams, cookie_params) self._verify_typed_dict_inputs(RequestCookieParams, cookie_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -366,7 +367,10 @@ class ParameterCollisions(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
_query_params = [] for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query__1, request_query__1,
request_query_a_b, request_query_a_b,
@ -377,8 +381,11 @@ class ParameterCollisions(api_client.Api):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
for parameter in ( for parameter in (
@ -407,10 +414,8 @@ class ParameterCollisions(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
query_params=tuple(_query_params),
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,
body=_body, body=_body,

View File

@ -196,8 +196,9 @@ class QueryParameterCollectionFormat(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_pipe, request_query_pipe,
request_query_ioutil, request_query_ioutil,
@ -209,14 +210,16 @@ class QueryParameterCollectionFormat(api_client.Api):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
) )

View File

@ -129,22 +129,25 @@ class RefObjectInQuery(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_map_bean, request_query_map_bean,
): ):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
) )

View File

@ -112,6 +112,7 @@ class ResponseWithoutSchema(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -120,7 +121,7 @@ class ResponseWithoutSchema(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
stream=stream, stream=stream,

View File

@ -122,6 +122,7 @@ class String(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -139,7 +140,7 @@ class String(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -124,6 +124,7 @@ class StringEnum(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -141,7 +142,7 @@ class StringEnum(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -124,6 +124,7 @@ class UploadDownloadFile(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -143,7 +144,7 @@ class UploadDownloadFile(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -149,6 +149,7 @@ class UploadFile(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -166,7 +167,7 @@ class UploadFile(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -151,6 +151,7 @@ class UploadFiles(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -168,7 +169,7 @@ class UploadFiles(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -129,6 +129,7 @@ class Classname(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -148,7 +149,7 @@ class Classname(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -146,6 +146,7 @@ class AddPet(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -164,7 +165,7 @@ class AddPet(api_client.Api):
host = self.get_host('add_pet', _servers, host_index) host = self.get_host('add_pet', _servers, host_index)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -157,6 +157,7 @@ class DeletePet(api_client.Api):
""" """
self._verify_typed_dict_inputs(RequestHeaderParams, header_params) self._verify_typed_dict_inputs(RequestHeaderParams, header_params)
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -168,6 +169,9 @@ class DeletePet(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
for parameter in ( for parameter in (
request_header_api_key, request_header_api_key,
@ -180,9 +184,8 @@ class DeletePet(api_client.Api):
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
headers=_headers, headers=_headers,
auth_settings=_auth, auth_settings=_auth,
stream=stream, stream=stream,

View File

@ -212,16 +212,20 @@ class FindPetsByStatus(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_status, request_query_status,
): ):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -230,9 +234,8 @@ class FindPetsByStatus(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
headers=_headers, headers=_headers,
auth_settings=_auth, auth_settings=_auth,
stream=stream, stream=stream,

View File

@ -186,16 +186,20 @@ class FindPetsByTags(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_tags, request_query_tags,
): ):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -204,9 +208,8 @@ class FindPetsByTags(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
headers=_headers, headers=_headers,
auth_settings=_auth, auth_settings=_auth,
stream=stream, stream=stream,

View File

@ -175,6 +175,7 @@ class GetPetById(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -186,6 +187,9 @@ class GetPetById(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
if accept_content_types: if accept_content_types:
@ -193,9 +197,8 @@ class GetPetById(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
headers=_headers, headers=_headers,
auth_settings=_auth, auth_settings=_auth,
stream=stream, stream=stream,

View File

@ -158,6 +158,7 @@ class UpdatePet(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -176,7 +177,7 @@ class UpdatePet(api_client.Api):
host = self.get_host('update_pet', _servers, host_index) host = self.get_host('update_pet', _servers, host_index)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -166,6 +166,7 @@ class UpdatePetWithForm(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -177,6 +178,9 @@ class UpdatePetWithForm(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -190,9 +194,8 @@ class UpdatePetWithForm(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,
body=_body, body=_body,

View File

@ -180,6 +180,7 @@ class UploadFileWithRequiredFile(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -191,6 +192,9 @@ class UploadFileWithRequiredFile(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
if accept_content_types: if accept_content_types:
@ -207,9 +211,8 @@ class UploadFileWithRequiredFile(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,
body=_body, body=_body,

View File

@ -178,6 +178,7 @@ class UploadImage(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -189,6 +190,9 @@ class UploadImage(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
if accept_content_types: if accept_content_types:
@ -205,9 +209,8 @@ class UploadImage(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,
body=_body, body=_body,

View File

@ -139,6 +139,7 @@ class DeleteOrder(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -149,12 +150,14 @@ class DeleteOrder(api_client.Api):
continue continue
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
) )

View File

@ -133,6 +133,7 @@ class GetInventory(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -141,7 +142,7 @@ class GetInventory(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
auth_settings=_auth, auth_settings=_auth,

View File

@ -181,6 +181,7 @@ class GetOrderById(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -192,6 +193,9 @@ class GetOrderById(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
if accept_content_types: if accept_content_types:
@ -199,9 +203,8 @@ class GetOrderById(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
headers=_headers, headers=_headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,

View File

@ -144,6 +144,7 @@ class PlaceOrder(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -163,7 +164,7 @@ class PlaceOrder(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -115,6 +115,7 @@ class CreateUser(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -131,7 +132,7 @@ class CreateUser(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -124,6 +124,7 @@ class CreateUsersWithArrayInput(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -140,7 +141,7 @@ class CreateUsersWithArrayInput(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -124,6 +124,7 @@ class CreateUsersWithListInput(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -140,7 +141,7 @@ class CreateUsersWithListInput(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,

View File

@ -139,6 +139,7 @@ class DeleteUser(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -149,12 +150,14 @@ class DeleteUser(api_client.Api):
continue continue
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
) )

View File

@ -172,6 +172,7 @@ class GetUserByName(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -183,6 +184,9 @@ class GetUserByName(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
if accept_content_types: if accept_content_types:
@ -190,9 +194,8 @@ class GetUserByName(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
headers=_headers, headers=_headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,

View File

@ -190,8 +190,9 @@ class LoginUser(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestQueryParams, query_params) self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path
_query_params = [] prefix_separator_iterator = None
for parameter in ( for parameter in (
request_query_username, request_query_username,
request_query_password, request_query_password,
@ -199,8 +200,11 @@ class LoginUser(api_client.Api):
parameter_data = query_params.get(parameter.name, unset) parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset: if parameter_data is unset:
continue continue
serialized_data = parameter.serialize(parameter_data) if prefix_separator_iterator is None:
_query_params.extend(serialized_data) prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -209,9 +213,8 @@ class LoginUser(api_client.Api):
_headers.add('Accept', accept_content_type) _headers.add('Accept', accept_content_type)
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
query_params=tuple(_query_params),
headers=_headers, headers=_headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,

View File

@ -99,10 +99,11 @@ class LogoutUser(api_client.Api):
api_response.body and api_response.headers will not be deserialized into schema api_response.body and api_response.headers will not be deserialized into schema
class instances class instances
""" """
used_path = _path
# TODO add cookie handling # TODO add cookie handling
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,

View File

@ -155,6 +155,7 @@ class UpdateUser(api_client.Api):
class instances class instances
""" """
self._verify_typed_dict_inputs(RequestPathParams, path_params) self._verify_typed_dict_inputs(RequestPathParams, path_params)
used_path = _path
_path_params = {} _path_params = {}
for parameter in ( for parameter in (
@ -166,6 +167,9 @@ class UpdateUser(api_client.Api):
serialized_data = parameter.serialize(parameter_data) serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data) _path_params.update(serialized_data)
for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
_headers = HTTPHeaderDict() _headers = HTTPHeaderDict()
# TODO add cookie handling # TODO add cookie handling
@ -181,9 +185,8 @@ class UpdateUser(api_client.Api):
elif 'body' in serialized_data: elif 'body' in serialized_data:
_body = serialized_data['body'] _body = serialized_data['body']
response = self.api_client.call_api( response = self.api_client.call_api(
resource_path=_path, resource_path=used_path,
method=_method, method=_method,
path_params=_path_params,
headers=_headers, headers=_headers,
fields=_fields, fields=_fields,
body=_body, body=_body,

View File

@ -53,9 +53,12 @@ class RequestField(RequestFieldBase):
class JSONEncoder(json.JSONEncoder): class JSONEncoder(json.JSONEncoder):
def default(self, obj): def default(self, obj):
if isinstance(obj, (str, int, float)): if isinstance(obj, str):
# instances based on primitive classes return str(obj)
return obj elif isinstance(obj, float):
return float(obj)
elif isinstance(obj, int):
return int(obj)
elif isinstance(obj, Decimal): elif isinstance(obj, Decimal):
if obj.as_tuple().exponent >= 0: if obj.as_tuple().exponent >= 0:
return int(obj) return int(obj)
@ -88,180 +91,175 @@ class ParameterStyle(enum.Enum):
DEEP_OBJECT = 'deepObject' DEEP_OBJECT = 'deepObject'
class PrefixSeparatorIterator:
# A class to store prefixes and separators for rfc6570 expansions
def __init__(self, prefix: str, separator: str):
self.prefix = prefix
self.separator = separator
self.first = True
if separator in {'.', '|', '%20'}:
item_separator = separator
else:
item_separator = ','
self.item_separator = item_separator
def __iter__(self):
return self
def __next__(self):
if self.first:
self.first = False
return self.prefix
return self.separator
class ParameterSerializerBase: class ParameterSerializerBase:
@staticmethod @classmethod
def __serialize_number( def get_default_explode(cls, style: ParameterStyle) -> bool:
in_data: typing.Union[int, float], name: str, prefix='' return False
) -> typing.Tuple[typing.Tuple[str, str]]:
return tuple([(name, prefix + str(in_data))])
@staticmethod @staticmethod
def __serialize_str( def __ref6570_item_value(in_data: typing.Any, percent_encode: bool):
in_data: str, name: str, prefix='' """
) -> typing.Tuple[typing.Tuple[str, str]]: Get representation if str/float/int/None/items in list/ values in dict
return tuple([(name, prefix + quote(in_data))]) None is returned if an item is undefined, use cases are value=
- None
@staticmethod - []
def __serialize_bool(in_data: bool, name: str, prefix='') -> typing.Tuple[typing.Tuple[str, str]]: - {}
if in_data: - [None, None None]
return tuple([(name, prefix + 'true')]) - {'a': None, 'b': None}
return tuple([(name, prefix + 'false')]) """
if type(in_data) in {str, float, int}:
@staticmethod if percent_encode:
def __urlencode(in_data: typing.Any) -> str: return quote(str(in_data))
return quote(str(in_data)) return str(in_data)
elif isinstance(in_data, none_type):
def __serialize_list( # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
self,
in_data: typing.List[typing.Any],
style: ParameterStyle,
name: str,
explode: bool,
empty_val: typing.Union[typing.Tuple[str, str], typing.Tuple] = tuple(),
prefix: str = '',
separator: str = ',',
) -> typing.Tuple[typing.Union[typing.Tuple[str, str], typing.Tuple], ...]:
if not in_data:
return empty_val
if explode and style in {
ParameterStyle.FORM,
ParameterStyle.MATRIX,
ParameterStyle.SPACE_DELIMITED,
ParameterStyle.PIPE_DELIMITED
}:
if style is ParameterStyle.FORM:
return tuple((name, prefix + self.__urlencode(val)) for val in in_data)
else:
joined_vals = prefix + separator.join(name + '=' + self.__urlencode(val) for val in in_data)
else:
joined_vals = prefix + separator.join(map(self.__urlencode, in_data))
return tuple([(name, joined_vals)])
def __form_item_representation(self, in_data: typing.Any) -> typing.Optional[str]:
if isinstance(in_data, none_type):
return None return None
elif isinstance(in_data, list): elif isinstance(in_data, list) and not in_data:
if not in_data: # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
return None return None
raise ApiValueError('Unable to generate a form representation of {}'.format(in_data)) elif isinstance(in_data, dict) and not in_data:
elif isinstance(in_data, dict): # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
if not in_data: return None
return None raise ApiValueError('Unable to generate a ref6570 item representation of {}'.format(in_data))
raise ApiValueError('Unable to generate a form representation of {}'.format(in_data))
elif isinstance(in_data, (bool, bytes)):
raise ApiValueError('Unable to generate a form representation of {}'.format(in_data))
# str, float, int
return self.__urlencode(in_data)
def __serialize_dict( @staticmethod
self, def to_dict(name: str, value: str):
in_data: typing.Dict[str, typing.Any], return {name: value}
style: ParameterStyle,
name: str, @classmethod
def ref6570_expansion(
cls,
variable_name: str,
in_data: typing.Any,
explode: bool, explode: bool,
empty_val: typing.Union[typing.Tuple[str, str], typing.Tuple] = tuple(), percent_encode: bool,
prefix: str = '', prefix_separator_iterator: PrefixSeparatorIterator
separator: str = ',', ) -> str:
) -> typing.Tuple[typing.Tuple[str, str]]: """
if not in_data: Separator is for separate variables like dict with explode true, not for array item separation
return empty_val """
if all(val is None for val in in_data.values()): named_parameter_expansion = prefix_separator_iterator.separator in {'&', ';'}
return empty_val var_name_piece = variable_name if named_parameter_expansion else ''
if type(in_data) in {str, float, int}:
form_items = {} item_value = cls.__ref6570_item_value(in_data, percent_encode)
if style is ParameterStyle.FORM: if item_value is None:
for key, val in in_data.items(): return next(prefix_separator_iterator) + var_name_piece
new_val = self.__form_item_representation(val) elif item_value == '' and prefix_separator_iterator.separator == ';':
if new_val is None: return next(prefix_separator_iterator) + var_name_piece
continue value_pair_equals = '=' if named_parameter_expansion else ''
form_items[key] = new_val return next(prefix_separator_iterator) + var_name_piece + value_pair_equals + item_value
elif isinstance(in_data, none_type):
if explode: # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
if style is ParameterStyle.FORM: return ""
return tuple((key, prefix + val) for key, val in form_items.items())
elif style in {
ParameterStyle.SIMPLE,
ParameterStyle.LABEL,
ParameterStyle.MATRIX,
ParameterStyle.SPACE_DELIMITED,
ParameterStyle.PIPE_DELIMITED
}:
joined_vals = prefix + separator.join(key + '=' + self.__urlencode(val) for key, val in in_data.items())
else:
raise ApiValueError(f'Invalid style {style} for dict serialization with explode=True')
elif style is ParameterStyle.FORM:
joined_vals = prefix + separator.join(key + separator + val for key, val in form_items.items())
else:
joined_vals = prefix + separator.join(
key + separator + self.__urlencode(val) for key, val in in_data.items())
return tuple([(name, joined_vals)])
def _serialize_x(
self,
in_data: typing.Union[None, int, float, str, bool, dict, list],
style: ParameterStyle,
name: str,
explode: bool,
empty_val: typing.Union[typing.Tuple[str, str], typing.Tuple] = (),
prefix: str = '',
separator: str = ',',
) -> typing.Tuple[typing.Tuple[str, str], ...]:
if isinstance(in_data, none_type):
return empty_val
elif isinstance(in_data, bool):
# must be before int check
return self.__serialize_bool(in_data, name=name, prefix=prefix)
elif isinstance(in_data, (int, float)):
return self.__serialize_number(in_data, name=name, prefix=prefix)
elif isinstance(in_data, str):
return self.__serialize_str(in_data, name=name, prefix=prefix)
elif isinstance(in_data, list): elif isinstance(in_data, list):
return self.__serialize_list( item_values = [cls.__ref6570_item_value(v, percent_encode) for v in in_data]
in_data, item_values = [v for v in item_values if v is not None]
style=style, if not item_values:
name=name, # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
explode=explode, return ""
empty_val=empty_val, value_pair_equals = '=' if named_parameter_expansion else ''
prefix=prefix, if not explode:
separator=separator return (
next(prefix_separator_iterator) +
var_name_piece +
value_pair_equals +
prefix_separator_iterator.item_separator.join(item_values)
)
# exploded
return next(prefix_separator_iterator) + next(prefix_separator_iterator).join(
[var_name_piece + value_pair_equals + val for val in item_values]
) )
elif isinstance(in_data, dict): elif isinstance(in_data, dict):
return self.__serialize_dict( in_data_transformed = {key: cls.__ref6570_item_value(val, percent_encode) for key, val in in_data.items()}
in_data, in_data_transformed = {key: val for key, val in in_data_transformed.items() if val is not None}
style=style, if not in_data_transformed:
name=name, # ignored by the expansion process https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.1
explode=explode, return ""
empty_val=empty_val, value_pair_equals = '=' if named_parameter_expansion else ''
prefix=prefix, if not explode:
separator=separator return (
next(prefix_separator_iterator) +
var_name_piece + value_pair_equals +
prefix_separator_iterator.item_separator.join(
prefix_separator_iterator.item_separator.join(
item_pair
) for item_pair in in_data_transformed.items()
)
)
# exploded
return next(prefix_separator_iterator) + next(prefix_separator_iterator).join(
[key + '=' + val for key, val in in_data_transformed.items()]
) )
# bool, bytes, etc
raise ApiValueError('Unable to generate a ref6570 representation of {}'.format(in_data))
class StyleFormSerializer(ParameterSerializerBase): class StyleFormSerializer(ParameterSerializerBase):
@classmethod
def get_default_explode(cls, style: ParameterStyle) -> bool:
if style is ParameterStyle.FORM:
return True
return super().get_default_explode(style)
def _serialize_form( def serialize_form(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list], in_data: typing.Union[None, int, float, str, bool, dict, list],
name: str, name: str,
explode: bool, explode: bool,
) -> typing.Tuple[typing.Tuple[str, str], ...]: percent_encode: bool,
return self._serialize_x(in_data, style=ParameterStyle.FORM, name=name, explode=explode) prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator] = None
) -> str:
if prefix_separator_iterator is None:
prefix_separator_iterator = PrefixSeparatorIterator('?', '&')
return self.ref6570_expansion(
variable_name=name,
in_data=in_data,
explode=explode,
percent_encode=percent_encode,
prefix_separator_iterator=prefix_separator_iterator
)
class StyleSimpleSerializer(ParameterSerializerBase): class StyleSimpleSerializer(ParameterSerializerBase):
def _serialize_simple_tuple( def serialize_simple(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list], in_data: typing.Union[None, int, float, str, bool, dict, list],
name: str, name: str,
explode: bool, explode: bool,
in_type: ParameterInType, percent_encode: bool
) -> typing.Tuple[typing.Tuple[str, str], ...]: ) -> str:
if in_type is ParameterInType.HEADER: prefix_separator_iterator = PrefixSeparatorIterator('', ',')
empty_val = () return self.ref6570_expansion(
else: variable_name=name,
empty_val = ((name, ''),) in_data=in_data,
return self._serialize_x(in_data, style=ParameterStyle.SIMPLE, name=name, explode=explode, empty_val=empty_val) explode=explode,
percent_encode=percent_encode,
prefix_separator_iterator=prefix_separator_iterator
)
@dataclass @dataclass
@ -349,8 +347,8 @@ class ParameterBase:
def _serialize_json( def _serialize_json(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list]
) -> typing.Tuple[typing.Tuple[str, str]]: ) -> str:
return tuple([(self.name, json.dumps(in_data))]) return json.dumps(in_data)
class PathParameter(ParameterBase, StyleSimpleSerializer): class PathParameter(ParameterBase, StyleSimpleSerializer):
@ -376,56 +374,45 @@ class PathParameter(ParameterBase, StyleSimpleSerializer):
content=content content=content
) )
def __serialize_label( def _serialize_label(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list]
) -> typing.Dict[str, str]: ) -> typing.Dict[str, str]:
empty_val = ((self.name, ''),) prefix_separator_iterator = PrefixSeparatorIterator('.', '.')
prefix = '.' value = self.ref6570_expansion(
separator = '.' variable_name=self.name,
return self._remove_empty_and_cast( in_data=in_data,
self._serialize_x( explode=self.explode,
in_data, percent_encode=True,
style=ParameterStyle.LABEL, prefix_separator_iterator=prefix_separator_iterator
name=self.name,
explode=self.explode,
empty_val=empty_val,
prefix=prefix,
separator=separator
)
) )
return self.to_dict(self.name, value)
def __serialize_matrix( def _serialize_matrix(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list]
) -> typing.Dict[str, str]: ) -> typing.Dict[str, str]:
separator = ',' prefix_separator_iterator = PrefixSeparatorIterator(';', ';')
if in_data == '': value = self.ref6570_expansion(
prefix = ';' + self.name variable_name=self.name,
elif isinstance(in_data, (dict, list)) and self.explode: in_data=in_data,
prefix = ';' explode=self.explode,
separator = ';' percent_encode=True,
else: prefix_separator_iterator=prefix_separator_iterator
prefix = ';' + self.name + '='
empty_val = ((self.name, ''),)
return self._remove_empty_and_cast(
self._serialize_x(
in_data,
style=ParameterStyle.MATRIX,
name=self.name,
explode=self.explode,
prefix=prefix,
empty_val=empty_val,
separator=separator
)
) )
return self.to_dict(self.name, value)
def _serialize_simple( def _serialize_simple(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list], in_data: typing.Union[None, int, float, str, bool, dict, list],
) -> typing.Dict[str, str]: ) -> typing.Dict[str, str]:
tuple_data = self._serialize_simple_tuple(in_data, self.name, self.explode, self.in_type) value = self.serialize_simple(
return self._remove_empty_and_cast(tuple_data) in_data=in_data,
name=self.name,
explode=self.explode,
percent_encode=True
)
return self.to_dict(self.name, value)
def serialize( def serialize(
self, self,
@ -448,16 +435,16 @@ class PathParameter(ParameterBase, StyleSimpleSerializer):
if self.style is ParameterStyle.SIMPLE: if self.style is ParameterStyle.SIMPLE:
return self._serialize_simple(cast_in_data) return self._serialize_simple(cast_in_data)
elif self.style is ParameterStyle.LABEL: elif self.style is ParameterStyle.LABEL:
return self.__serialize_label(cast_in_data) return self._serialize_label(cast_in_data)
elif self.style is ParameterStyle.MATRIX: elif self.style is ParameterStyle.MATRIX:
return self.__serialize_matrix(cast_in_data) return self._serialize_matrix(cast_in_data)
# self.content will be length one # self.content will be length one
for content_type, schema in self.content.items(): for content_type, schema in self.content.items():
cast_in_data = schema(in_data) cast_in_data = schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
if content_type == self._json_content_type: if content_type == self._json_content_type:
tuple_data = self._serialize_json(cast_in_data) value = self._serialize_json(cast_in_data)
return self._remove_empty_and_cast(tuple_data) return self.to_dict(self.name, value)
raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type)) raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type))
@ -468,17 +455,20 @@ class QueryParameter(ParameterBase, StyleFormSerializer):
name: str, name: str,
required: bool = False, required: bool = False,
style: typing.Optional[ParameterStyle] = None, style: typing.Optional[ParameterStyle] = None,
explode: bool = False, explode: typing.Optional[bool] = None,
allow_reserved: typing.Optional[bool] = None, allow_reserved: typing.Optional[bool] = None,
schema: typing.Optional[typing.Type[Schema]] = None, schema: typing.Optional[typing.Type[Schema]] = None,
content: typing.Optional[typing.Dict[str, typing.Type[Schema]]] = None content: typing.Optional[typing.Dict[str, typing.Type[Schema]]] = None
): ):
used_style = ParameterStyle.FORM if style is None and content is None and schema else style
used_explode = self.get_default_explode(used_style) if explode is None else explode
super().__init__( super().__init__(
name, name,
in_type=ParameterInType.QUERY, in_type=ParameterInType.QUERY,
required=required, required=required,
style=style, style=used_style,
explode=explode, explode=used_explode,
allow_reserved=allow_reserved, allow_reserved=allow_reserved,
schema=schema, schema=schema,
content=content content=content
@ -486,39 +476,68 @@ class QueryParameter(ParameterBase, StyleFormSerializer):
def __serialize_space_delimited( def __serialize_space_delimited(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list],
) -> typing.Tuple[typing.Tuple[str, str], ...]: prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator]
separator = '%20' ) -> typing.Dict[str, str]:
empty_val = () if prefix_separator_iterator is None:
return self._serialize_x( prefix_separator_iterator = self.get_prefix_separator_iterator()
in_data, value = self.ref6570_expansion(
style=ParameterStyle.SPACE_DELIMITED, variable_name=self.name,
name=self.name, in_data=in_data,
explode=self.explode, explode=self.explode,
separator=separator, percent_encode=True,
empty_val=empty_val prefix_separator_iterator=prefix_separator_iterator
) )
return self.to_dict(self.name, value)
def __serialize_pipe_delimited( def __serialize_pipe_delimited(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list] in_data: typing.Union[None, int, float, str, bool, dict, list],
) -> typing.Tuple[typing.Tuple[str, str], ...]: prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator]
separator = '|' ) -> typing.Dict[str, str]:
empty_val = () if prefix_separator_iterator is None:
return self._serialize_x( prefix_separator_iterator = self.get_prefix_separator_iterator()
value = self.ref6570_expansion(
variable_name=self.name,
in_data=in_data,
explode=self.explode,
percent_encode=True,
prefix_separator_iterator=prefix_separator_iterator
)
return self.to_dict(self.name, value)
def __serialize_form(
self,
in_data: typing.Union[None, int, float, str, bool, dict, list],
prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator]
) -> typing.Dict[str, str]:
if prefix_separator_iterator is None:
prefix_separator_iterator = self.get_prefix_separator_iterator()
value = self.serialize_form(
in_data, in_data,
style=ParameterStyle.PIPE_DELIMITED,
name=self.name, name=self.name,
explode=self.explode, explode=self.explode,
separator=separator, percent_encode=True,
empty_val=empty_val prefix_separator_iterator=prefix_separator_iterator
) )
return self.to_dict(self.name, value)
def get_prefix_separator_iterator(self) -> typing.Optional[PrefixSeparatorIterator]:
if not self.schema:
return None
if self.style is ParameterStyle.FORM:
return PrefixSeparatorIterator('?', '&')
elif self.style is ParameterStyle.SPACE_DELIMITED:
return PrefixSeparatorIterator('', '%20')
elif self.style is ParameterStyle.PIPE_DELIMITED:
return PrefixSeparatorIterator('', '|')
def serialize( def serialize(
self, self,
in_data: typing.Union[ in_data: typing.Union[
Schema, Decimal, int, float, str, date, datetime, None, bool, list, tuple, dict, frozendict] Schema, Decimal, int, float, str, date, datetime, None, bool, list, tuple, dict, frozendict],
) -> typing.Tuple[typing.Tuple[str, str]]: prefix_separator_iterator: typing.Optional[PrefixSeparatorIterator] = None
) -> typing.Dict[str, str]:
if self.schema: if self.schema:
cast_in_data = self.schema(in_data) cast_in_data = self.schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
@ -538,17 +557,18 @@ class QueryParameter(ParameterBase, StyleFormSerializer):
if self.style: if self.style:
# TODO update query ones to omit setting values when [] {} or None is input # TODO update query ones to omit setting values when [] {} or None is input
if self.style is ParameterStyle.FORM: if self.style is ParameterStyle.FORM:
return self._serialize_form(cast_in_data, explode=self.explode, name=self.name) return self.__serialize_form(cast_in_data, prefix_separator_iterator)
elif self.style is ParameterStyle.SPACE_DELIMITED: elif self.style is ParameterStyle.SPACE_DELIMITED:
return self.__serialize_space_delimited(cast_in_data) return self.__serialize_space_delimited(cast_in_data, prefix_separator_iterator)
elif self.style is ParameterStyle.PIPE_DELIMITED: elif self.style is ParameterStyle.PIPE_DELIMITED:
return self.__serialize_pipe_delimited(cast_in_data) return self.__serialize_pipe_delimited(cast_in_data, prefix_separator_iterator)
# self.content will be length one # self.content will be length one
for content_type, schema in self.content.items(): for content_type, schema in self.content.items():
cast_in_data = schema(in_data) cast_in_data = schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
if content_type == self._json_content_type: if content_type == self._json_content_type:
return self._serialize_json(cast_in_data) value = self._serialize_json(cast_in_data)
return self.to_dict(self.name, value)
raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type)) raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type))
@ -559,17 +579,20 @@ class CookieParameter(ParameterBase, StyleFormSerializer):
name: str, name: str,
required: bool = False, required: bool = False,
style: typing.Optional[ParameterStyle] = None, style: typing.Optional[ParameterStyle] = None,
explode: bool = False, explode: typing.Optional[bool] = None,
allow_reserved: typing.Optional[bool] = None, allow_reserved: typing.Optional[bool] = None,
schema: typing.Optional[typing.Type[Schema]] = None, schema: typing.Optional[typing.Type[Schema]] = None,
content: typing.Optional[typing.Dict[str, typing.Type[Schema]]] = None content: typing.Optional[typing.Dict[str, typing.Type[Schema]]] = None
): ):
used_style = ParameterStyle.FORM if style is None and content is None and schema else style
used_explode = self.get_default_explode(used_style) if explode is None else explode
super().__init__( super().__init__(
name, name,
in_type=ParameterInType.COOKIE, in_type=ParameterInType.COOKIE,
required=required, required=required,
style=style, style=used_style,
explode=explode, explode=used_explode,
allow_reserved=allow_reserved, allow_reserved=allow_reserved,
schema=schema, schema=schema,
content=content content=content
@ -579,7 +602,7 @@ class CookieParameter(ParameterBase, StyleFormSerializer):
self, self,
in_data: typing.Union[ in_data: typing.Union[
Schema, Decimal, int, float, str, date, datetime, None, bool, list, tuple, dict, frozendict] Schema, Decimal, int, float, str, date, datetime, None, bool, list, tuple, dict, frozendict]
) -> typing.Tuple[typing.Tuple[str, str]]: ) -> typing.Dict[str, str]:
if self.schema: if self.schema:
cast_in_data = self.schema(in_data) cast_in_data = self.schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
@ -588,13 +611,25 @@ class CookieParameter(ParameterBase, StyleFormSerializer):
returns fields: tuple returns fields: tuple
""" """
if self.style: if self.style:
return self._serialize_form(cast_in_data, explode=self.explode, name=self.name) """
TODO add escaping of comma, space, equals
or turn encoding on
"""
value = self.serialize_form(
cast_in_data,
explode=self.explode,
name=self.name,
percent_encode=False,
prefix_separator_iterator=PrefixSeparatorIterator('', '&')
)
return self.to_dict(self.name, value)
# self.content will be length one # self.content will be length one
for content_type, schema in self.content.items(): for content_type, schema in self.content.items():
cast_in_data = schema(in_data) cast_in_data = schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
if content_type == self._json_content_type: if content_type == self._json_content_type:
return self._serialize_json(cast_in_data) value = self._serialize_json(cast_in_data)
return self.to_dict(self.name, value)
raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type)) raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type))
@ -632,9 +667,8 @@ class HeaderParameter(ParameterBase, StyleSimpleSerializer):
def _serialize_simple( def _serialize_simple(
self, self,
in_data: typing.Union[None, int, float, str, bool, dict, list], in_data: typing.Union[None, int, float, str, bool, dict, list],
) -> HTTPHeaderDict[str, str]: ) -> str:
tuple_data = self._serialize_simple_tuple(in_data, self.name, self.explode, self.in_type) return self.serialize_simple(in_data, self.name, self.explode, False)
return self.__to_headers(tuple_data)
def serialize( def serialize(
self, self,
@ -650,14 +684,15 @@ class HeaderParameter(ParameterBase, StyleSimpleSerializer):
returns headers: dict returns headers: dict
""" """
if self.style: if self.style:
return self._serialize_simple(cast_in_data) value = self._serialize_simple(cast_in_data)
return self.__to_headers(((self.name, value),))
# self.content will be length one # self.content will be length one
for content_type, schema in self.content.items(): for content_type, schema in self.content.items():
cast_in_data = schema(in_data) cast_in_data = schema(in_data)
cast_in_data = self._json_encoder.default(cast_in_data) cast_in_data = self._json_encoder.default(cast_in_data)
if content_type == self._json_content_type: if content_type == self._json_content_type:
tuple_data = self._serialize_json(cast_in_data) value = self._serialize_json(cast_in_data)
return self.__to_headers(tuple_data) return self.__to_headers(((self.name, value),))
raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type)) raise NotImplementedError('Serialization of {} has not yet been implemented'.format(content_type))
@ -935,8 +970,6 @@ class ApiClient:
self, self,
resource_path: str, resource_path: str,
method: str, method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None, headers: typing.Optional[HTTPHeaderDict] = None,
body: typing.Optional[typing.Union[str, bytes]] = None, body: typing.Optional[typing.Union[str, bytes]] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None, fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
@ -952,17 +985,8 @@ class ApiClient:
if self.cookie: if self.cookie:
headers['Cookie'] = self.cookie headers['Cookie'] = self.cookie
# path parameters
if path_params:
for k, v in path_params.items():
# specified safe chars, encode everything
resource_path = resource_path.replace(
'{%s}' % k,
quote(str(v), safe=self.configuration.safe_chars_for_path_param)
)
# auth setting # auth setting
self.update_params_for_auth(headers, query_params, self.update_params_for_auth(headers,
auth_settings, resource_path, method, body) auth_settings, resource_path, method, body)
# request url # request url
@ -976,7 +1000,6 @@ class ApiClient:
response = self.request( response = self.request(
method, method,
url, url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
body=body, body=body,
@ -989,8 +1012,6 @@ class ApiClient:
self, self,
resource_path: str, resource_path: str,
method: str, method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None, headers: typing.Optional[HTTPHeaderDict] = None,
body: typing.Optional[typing.Union[str, bytes]] = None, body: typing.Optional[typing.Union[str, bytes]] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None, fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
@ -1006,8 +1027,6 @@ class ApiClient:
:param resource_path: Path to method endpoint. :param resource_path: Path to method endpoint.
:param method: Method to call. :param method: Method to call.
:param path_params: Path parameters in the url.
:param query_params: Query parameters in the url.
:param headers: Header parameters to be :param headers: Header parameters to be
placed in the request header. placed in the request header.
:param body: Request body. :param body: Request body.
@ -1040,8 +1059,6 @@ class ApiClient:
return self.__call_api( return self.__call_api(
resource_path, resource_path,
method, method,
path_params,
query_params,
headers, headers,
body, body,
fields, fields,
@ -1056,8 +1073,6 @@ class ApiClient:
( (
resource_path, resource_path,
method, method,
path_params,
query_params,
headers, headers,
body, body,
json, json,
@ -1073,7 +1088,6 @@ class ApiClient:
self, self,
method: str, method: str,
url: str, url: str,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None, headers: typing.Optional[HTTPHeaderDict] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None, fields: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
body: typing.Optional[typing.Union[str, bytes]] = None, body: typing.Optional[typing.Union[str, bytes]] = None,
@ -1083,19 +1097,16 @@ class ApiClient:
"""Makes the HTTP request using RESTClient.""" """Makes the HTTP request using RESTClient."""
if method == "GET": if method == "GET":
return self.rest_client.GET(url, return self.rest_client.GET(url,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
headers=headers) headers=headers)
elif method == "HEAD": elif method == "HEAD":
return self.rest_client.HEAD(url, return self.rest_client.HEAD(url,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
headers=headers) headers=headers)
elif method == "OPTIONS": elif method == "OPTIONS":
return self.rest_client.OPTIONS(url, return self.rest_client.OPTIONS(url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
stream=stream, stream=stream,
@ -1103,7 +1114,6 @@ class ApiClient:
body=body) body=body)
elif method == "POST": elif method == "POST":
return self.rest_client.POST(url, return self.rest_client.POST(url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
stream=stream, stream=stream,
@ -1111,7 +1121,6 @@ class ApiClient:
body=body) body=body)
elif method == "PUT": elif method == "PUT":
return self.rest_client.PUT(url, return self.rest_client.PUT(url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
stream=stream, stream=stream,
@ -1119,7 +1128,6 @@ class ApiClient:
body=body) body=body)
elif method == "PATCH": elif method == "PATCH":
return self.rest_client.PATCH(url, return self.rest_client.PATCH(url,
query_params=query_params,
headers=headers, headers=headers,
fields=fields, fields=fields,
stream=stream, stream=stream,
@ -1127,7 +1135,6 @@ class ApiClient:
body=body) body=body)
elif method == "DELETE": elif method == "DELETE":
return self.rest_client.DELETE(url, return self.rest_client.DELETE(url,
query_params=query_params,
headers=headers, headers=headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
@ -1138,12 +1145,11 @@ class ApiClient:
" `POST`, `PATCH`, `PUT` or `DELETE`." " `POST`, `PATCH`, `PUT` or `DELETE`."
) )
def update_params_for_auth(self, headers, querys, auth_settings, def update_params_for_auth(self, headers, auth_settings,
resource_path, method, body): resource_path, method, body):
"""Updates header and query params based on authentication setting. """Updates header and query params based on authentication setting.
:param headers: Header parameters dict to be updated. :param headers: Header parameters dict to be updated.
:param querys: Query parameters tuple list to be updated.
:param auth_settings: Authentication setting identifiers list. :param auth_settings: Authentication setting identifiers list.
:param resource_path: A string representation of the HTTP request resource path. :param resource_path: A string representation of the HTTP request resource path.
:param method: A string representation of the HTTP request method. :param method: A string representation of the HTTP request method.
@ -1165,12 +1171,17 @@ class ApiClient:
# The HTTP signature scheme requires multiple HTTP headers # The HTTP signature scheme requires multiple HTTP headers
# that are calculated dynamically. # that are calculated dynamically.
signing_info = self.configuration.signing_info signing_info = self.configuration.signing_info
querys = tuple()
auth_headers = signing_info.get_http_signature_headers( auth_headers = signing_info.get_http_signature_headers(
resource_path, method, headers, body, querys) resource_path, method, headers, body, querys)
for key, value in auth_headers.items(): for key, value in auth_headers.items():
headers.add(key, value) headers.add(key, value)
elif auth_setting['in'] == 'query': elif auth_setting['in'] == 'query':
querys.append((auth_setting['key'], auth_setting['value'])) """ TODO implement auth in query
need to pass in prefix_separator_iterator
and need to output resource_path with query params added
"""
raise ApiValueError("Auth in query not yet implemented")
else: else:
raise ApiValueError( raise ApiValueError(
'Authentication token must be in `query` or `header`' 'Authentication token must be in `query` or `header`'
@ -1373,15 +1384,16 @@ class RequestBody(StyleFormSerializer, JSONDetector):
def __serialize_application_x_www_form_data( def __serialize_application_x_www_form_data(
self, in_data: typing.Any self, in_data: typing.Any
) -> typing.Dict[str, tuple[tuple[str, str], ...]]: ) -> SerializedRequestBody:
"""
POST submission of form data in body
"""
if not isinstance(in_data, frozendict): if not isinstance(in_data, frozendict):
raise ValueError( raise ValueError(
f'Unable to serialize {in_data} to application/x-www-form-urlencoded because it is not a dict of data') f'Unable to serialize {in_data} to application/x-www-form-urlencoded because it is not a dict of data')
cast_in_data = self.__json_encoder.default(in_data) cast_in_data = self.__json_encoder.default(in_data)
fields = self._serialize_form(cast_in_data, explode=True, name='') value = self.serialize_form(cast_in_data, name='', explode=True, percent_encode=False)
if not fields: return dict(body=value)
return {}
return {'fields': fields}
def serialize( def serialize(
self, in_data: typing.Any, content_type: str self, in_data: typing.Any, content_type: str

View File

@ -90,7 +90,6 @@ class RESTClientObject(object):
self, self,
method: str, method: str,
url: str, url: str,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None, headers: typing.Optional[HTTPHeaderDict] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, typing.Any], ...]] = None, fields: typing.Optional[typing.Tuple[typing.Tuple[str, typing.Any], ...]] = None,
body: typing.Optional[typing.Union[str, bytes]] = None, body: typing.Optional[typing.Union[str, bytes]] = None,
@ -101,7 +100,6 @@ class RESTClientObject(object):
:param method: http request method :param method: http request method
:param url: http request url :param url: http request url
:param query_params: query parameters in the url
:param headers: http request headers :param headers: http request headers
:param body: request body, for other types :param body: request body, for other types
:param fields: request parameters for :param fields: request parameters for
@ -137,13 +135,10 @@ class RESTClientObject(object):
try: try:
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
if query_params:
url += '?' + urlencode(query_params)
if 'Content-Type' not in headers and body is None: if 'Content-Type' not in headers and body is None:
r = self.pool_manager.request( r = self.pool_manager.request(
method, method,
url, url,
fields=query_params,
preload_content=not stream, preload_content=not stream,
timeout=timeout, timeout=timeout,
headers=headers headers=headers
@ -188,7 +183,6 @@ class RESTClientObject(object):
# For `GET`, `HEAD` # For `GET`, `HEAD`
else: else:
r = self.pool_manager.request(method, url, r = self.pool_manager.request(method, url,
fields=query_params,
preload_content=not stream, preload_content=not stream,
timeout=timeout, timeout=timeout,
headers=headers) headers=headers)
@ -202,63 +196,58 @@ class RESTClientObject(object):
return r return r
def GET(self, url, headers=None, query_params=None, stream=False, def GET(self, url, headers=None, stream=False,
timeout=None, fields=None) -> urllib3.HTTPResponse: timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("GET", url, return self.request("GET", url,
headers=headers, headers=headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
query_params=query_params, fields=fields) fields=fields)
def HEAD(self, url, headers=None, query_params=None, stream=False, def HEAD(self, url, headers=None, stream=False,
timeout=None, fields=None) -> urllib3.HTTPResponse: timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("HEAD", url, return self.request("HEAD", url,
headers=headers, headers=headers,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
query_params=query_params, fields=fields) fields=fields)
def OPTIONS(self, url, headers=None, query_params=None, def OPTIONS(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("OPTIONS", url, return self.request("OPTIONS", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)
def DELETE(self, url, headers=None, query_params=None, body=None, def DELETE(self, url, headers=None, body=None,
stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("DELETE", url, return self.request("DELETE", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)
def POST(self, url, headers=None, query_params=None, def POST(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("POST", url, return self.request("POST", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)
def PUT(self, url, headers=None, query_params=None, def PUT(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("PUT", url, return self.request("PUT", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)
def PATCH(self, url, headers=None, query_params=None, def PATCH(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse: body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("PATCH", url, return self.request("PATCH", url,
headers=headers, headers=headers,
query_params=query_params,
stream=stream, stream=stream,
timeout=timeout, timeout=timeout,
body=body, fields=fields) body=body, fields=fields)

View File

@ -0,0 +1,104 @@
import json
import typing
import unittest
import urllib3
from urllib3._collections import HTTPHeaderDict
from petstore_api import api_client
class ApiTestMixin(unittest.TestCase):
json_content_type = 'application/json'
user_agent = 'OpenAPI-Generator/1.0.0/python'
@classmethod
def assert_request_called_with(
cls,
mock_request,
url: str,
method: str = 'POST',
body: typing.Optional[bytes] = None,
content_type: typing.Optional[str] = 'application/json',
fields: typing.Optional[tuple[api_client.RequestField, ...]] = None,
accept_content_type: typing.Optional[str] = 'application/json',
stream: bool = False,
):
headers = {
'User-Agent': cls.user_agent
}
if accept_content_type:
headers['Accept'] = accept_content_type
if content_type:
headers['Content-Type'] = content_type
kwargs = dict(
headers=HTTPHeaderDict(headers),
fields=fields,
stream=stream,
timeout=None,
)
if method != 'GET':
kwargs['body'] = body
mock_request.assert_called_with(
method,
url,
**kwargs
)
@classmethod
def assert_pool_manager_request_called_with(
cls,
mock_request,
url: str,
method: str = 'POST',
body: typing.Optional[bytes] = None,
content_type: typing.Optional[str] = 'application/json',
accept_content_type: typing.Optional[str] = 'application/json',
stream: bool = False,
):
headers = {
'User-Agent': cls.user_agent
}
if accept_content_type:
headers['Accept'] = accept_content_type
if content_type:
headers['Content-Type'] = content_type
kwargs = dict(
headers=HTTPHeaderDict(headers),
preload_content=not stream,
timeout=None,
)
if content_type and method != 'GET':
kwargs['body'] = body
mock_request.assert_called_with(
method,
url,
**kwargs
)
@staticmethod
def headers_for_content_type(content_type: str) -> dict[str, str]:
return {'content-type': content_type}
@classmethod
def response(
cls,
body: typing.Union[str, bytes],
status: int = 200,
content_type: str = json_content_type,
headers: typing.Optional[dict[str, str]] = None,
preload_content: bool = True
) -> urllib3.HTTPResponse:
if headers is None:
headers = {}
headers.update(cls.headers_for_content_type(content_type))
return urllib3.HTTPResponse(
body,
headers=headers,
status=status,
preload_content=preload_content
)
@staticmethod
def json_bytes(in_data: typing.Any) -> bytes:
return json.dumps(in_data, separators=(",", ":"), ensure_ascii=False).encode('utf-8')

View File

@ -43,7 +43,6 @@ class ConfigurationTests(unittest.TestCase):
mock_request.assert_called_with( mock_request.assert_called_with(
'POST', 'POST',
'http://path-server-test.petstore.local/v2/pet', 'http://path-server-test.petstore.local/v2/pet',
query_params=None,
headers=HTTPHeaderDict({ headers=HTTPHeaderDict({
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'User-Agent': 'OpenAPI-Generator/1.0.0/python' 'User-Agent': 'OpenAPI-Generator/1.0.0/python'
@ -60,7 +59,6 @@ class ConfigurationTests(unittest.TestCase):
mock_request.assert_called_with( mock_request.assert_called_with(
'DELETE', 'DELETE',
'https://localhost:8080/v1/pet/123456789', 'https://localhost:8080/v1/pet/123456789',
query_params=None,
headers={'User-Agent': 'OpenAPI-Generator/1.0.0/python'}, headers={'User-Agent': 'OpenAPI-Generator/1.0.0/python'},
fields=None, fields=None,
body=None, body=None,

View File

@ -13,18 +13,17 @@ from email.mime import nonmultipart
import io import io
import sys import sys
import unittest import unittest
import json
import typing import typing
from unittest.mock import patch from unittest.mock import patch
import urllib3 import urllib3
from urllib3._collections import HTTPHeaderDict
import petstore_api import petstore_api
from petstore_api import api_client, schemas, exceptions from petstore_api import api_client, schemas, exceptions
from petstore_api.api.fake_api import FakeApi # noqa: E501 from petstore_api.api.fake_api import FakeApi # noqa: E501
from petstore_api.rest import RESTClientObject from petstore_api.rest import RESTClientObject
from . import ApiTestMixin
class MIMEFormdata(nonmultipart.MIMENonMultipart): class MIMEFormdata(nonmultipart.MIMENonMultipart):
def __init__(self, keyname, *args, **kwargs): def __init__(self, keyname, *args, **kwargs):
@ -33,108 +32,10 @@ class MIMEFormdata(nonmultipart.MIMENonMultipart):
"Content-Disposition", "form-data; name=\"%s\"" % keyname) "Content-Disposition", "form-data; name=\"%s\"" % keyname)
class TestFakeApi(unittest.TestCase): class TestFakeApi(ApiTestMixin):
"""FakeApi unit test stubs""" """FakeApi unit test stubs"""
json_content_type = 'application/json'
configuration = petstore_api.Configuration() configuration = petstore_api.Configuration()
api = FakeApi(api_client=api_client.ApiClient(configuration=configuration)) api = FakeApi(api_client=api_client.ApiClient(configuration=configuration))
user_agent = 'OpenAPI-Generator/1.0.0/python'
@staticmethod
def headers_for_content_type(content_type: str) -> dict[str, str]:
return {'content-type': content_type}
@classmethod
def __response(
cls,
body: typing.Union[str, bytes],
status: int = 200,
content_type: str = json_content_type,
headers: typing.Optional[dict[str, str]] = None,
preload_content: bool = True
) -> urllib3.HTTPResponse:
if headers is None:
headers = {}
headers.update(cls.headers_for_content_type(content_type))
return urllib3.HTTPResponse(
body,
headers=headers,
status=status,
preload_content=preload_content
)
@staticmethod
def __json_bytes(in_data: typing.Any) -> bytes:
return json.dumps(in_data, separators=(",", ":"), ensure_ascii=False).encode('utf-8')
@classmethod
def __assert_request_called_with(
cls,
mock_request,
url: str,
method: str = 'POST',
body: typing.Optional[bytes] = None,
content_type: typing.Optional[str] = 'application/json',
fields: typing.Optional[tuple[api_client.RequestField, ...]] = None,
accept_content_type: str = 'application/json',
stream: bool = False,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None
):
headers = {
'Accept': accept_content_type,
'User-Agent': cls.user_agent
}
if accept_content_type:
headers['Accept'] = accept_content_type
if content_type:
headers['Content-Type'] = content_type
kwargs = dict(
headers=HTTPHeaderDict(headers),
query_params=query_params,
fields=fields,
stream=stream,
timeout=None,
)
if method != 'GET':
kwargs['body'] = body
mock_request.assert_called_with(
method,
url,
**kwargs
)
@classmethod
def __assert_pool_manager_request_called_with(
cls,
mock_request,
url: str,
method: str = 'POST',
body: typing.Optional[bytes] = None,
content_type: typing.Optional[str] = 'application/json',
accept_content_type: typing.Optional[str] = 'application/json',
stream: bool = False,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
):
headers = {
'User-Agent': cls.user_agent
}
if accept_content_type:
headers['Accept'] = accept_content_type
if content_type:
headers['Content-Type'] = content_type
kwargs = dict(
headers=HTTPHeaderDict(headers),
fields=query_params,
preload_content=not stream,
timeout=None,
)
if content_type and method != 'GET':
kwargs['body'] = body
mock_request.assert_called_with(
method,
url,
**kwargs
)
def test_array_model(self): def test_array_model(self):
from petstore_api.model import animal_farm, animal from petstore_api.model import animal_farm, animal
@ -142,17 +43,17 @@ class TestFakeApi(unittest.TestCase):
# serialization + deserialization works # serialization + deserialization works
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
json_data = [{"className": "Cat", "color": "black"}] json_data = [{"className": "Cat", "color": "black"}]
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(json_data) self.json_bytes(json_data)
) )
cat = animal.Animal(className="Cat", color="black") cat = animal.Animal(className="Cat", color="black")
body = animal_farm.AnimalFarm([cat]) body = animal_farm.AnimalFarm([cat])
api_response = self.api.array_model(body=body) api_response = self.api.array_model(body=body)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/refs/arraymodel', 'http://petstore.swagger.io:80/v2/fake/refs/arraymodel',
body=self.__json_bytes(json_data) body=self.json_bytes(json_data)
) )
assert isinstance(api_response.body, animal_farm.AnimalFarm) assert isinstance(api_response.body, animal_farm.AnimalFarm)
@ -172,15 +73,15 @@ class TestFakeApi(unittest.TestCase):
value = [string_enum.StringEnum("placed")] value = [string_enum.StringEnum("placed")]
body = array_of_enums.ArrayOfEnums(value) body = array_of_enums.ArrayOfEnums(value)
value_simple = ["placed"] value_simple = ["placed"]
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(value_simple) self.json_bytes(value_simple)
) )
api_response = self.api.array_of_enums(body=body) api_response = self.api.array_of_enums(body=body)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/refs/array-of-enums', 'http://petstore.swagger.io:80/v2/fake/refs/array-of-enums',
body=self.__json_bytes(value_simple) body=self.json_bytes(value_simple)
) )
assert isinstance(api_response.body, array_of_enums.ArrayOfEnums) assert isinstance(api_response.body, array_of_enums.ArrayOfEnums)
@ -193,15 +94,15 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
value = 10.0 value = 10.0
body = number_with_validations.NumberWithValidations(value) body = number_with_validations.NumberWithValidations(value)
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(value) self.json_bytes(value)
) )
api_response = self.api.number_with_validations(body=body) api_response = self.api.number_with_validations(body=body)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/refs/number', 'http://petstore.swagger.io:80/v2/fake/refs/number',
body=self.__json_bytes(value) body=self.json_bytes(value)
) )
assert isinstance(api_response.body, number_with_validations.NumberWithValidations) assert isinstance(api_response.body, number_with_validations.NumberWithValidations)
@ -225,15 +126,15 @@ class TestFakeApi(unittest.TestCase):
] ]
for (body, value_simple) in cast_to_simple_value: for (body, value_simple) in cast_to_simple_value:
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(value_simple) self.json_bytes(value_simple)
) )
api_response = self.api.composed_one_of_different_types(body=body) api_response = self.api.composed_one_of_different_types(body=body)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/refs/composed_one_of_number_with_validations', 'http://petstore.swagger.io:80/v2/fake/refs/composed_one_of_number_with_validations',
body=self.__json_bytes(value_simple) body=self.json_bytes(value_simple)
) )
assert isinstance(api_response.body, composed_one_of_different_types.ComposedOneOfDifferentTypes) assert isinstance(api_response.body, composed_one_of_different_types.ComposedOneOfDifferentTypes)
@ -242,15 +143,15 @@ class TestFakeApi(unittest.TestCase):
# inputting the uncast values into the endpoint also works # inputting the uncast values into the endpoint also works
for (body, value_simple) in cast_to_simple_value: for (body, value_simple) in cast_to_simple_value:
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(value_simple) self.json_bytes(value_simple)
) )
api_response = self.api.composed_one_of_different_types(body=value_simple) api_response = self.api.composed_one_of_different_types(body=value_simple)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/refs/composed_one_of_number_with_validations', 'http://petstore.swagger.io:80/v2/fake/refs/composed_one_of_number_with_validations',
body=self.__json_bytes(value_simple) body=self.json_bytes(value_simple)
) )
assert isinstance(api_response.body, composed_one_of_different_types.ComposedOneOfDifferentTypes) assert isinstance(api_response.body, composed_one_of_different_types.ComposedOneOfDifferentTypes)
@ -261,15 +162,15 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
body = "blah" body = "blah"
value_simple = body value_simple = body
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(value_simple) self.json_bytes(value_simple)
) )
api_response = self.api.string(body=body) api_response = self.api.string(body=body)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/refs/string', 'http://petstore.swagger.io:80/v2/fake/refs/string',
body=self.__json_bytes(value_simple) body=self.json_bytes(value_simple)
) )
assert isinstance(api_response.body, str) assert isinstance(api_response.body, str)
@ -281,15 +182,15 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
value = "placed" value = "placed"
body = string_enum.StringEnum(value) body = string_enum.StringEnum(value)
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(value) self.json_bytes(value)
) )
api_response = self.api.string_enum(body=body) api_response = self.api.string_enum(body=body)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/refs/enum', 'http://petstore.swagger.io:80/v2/fake/refs/enum',
body=self.__json_bytes(value) body=self.json_bytes(value)
) )
assert isinstance(api_response.body, string_enum.StringEnum) assert isinstance(api_response.body, string_enum.StringEnum)
@ -301,15 +202,15 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
body = Mammal(className="BasquePig") body = Mammal(className="BasquePig")
value_simple = dict(className='BasquePig') value_simple = dict(className='BasquePig')
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(value_simple) self.json_bytes(value_simple)
) )
api_response = self.api.mammal(body=body) api_response = self.api.mammal(body=body)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/refs/mammal', 'http://petstore.swagger.io:80/v2/fake/refs/mammal',
body=self.__json_bytes(value_simple) body=self.json_bytes(value_simple)
) )
assert isinstance(api_response.body, Mammal) assert isinstance(api_response.body, Mammal)
@ -333,6 +234,36 @@ class TestFakeApi(unittest.TestCase):
with self.assertRaises(petstore_api.ApiValueError): with self.assertRaises(petstore_api.ApiValueError):
self.api.body_with_query_params(body=schemas.unset, query_params=dict(query=schemas.unset)) self.api.body_with_query_params(body=schemas.unset, query_params=dict(query=schemas.unset))
def test_body_with_query_params(self):
from petstore_api.model import user
with patch.object(RESTClientObject, 'request') as mock_request:
value_simple = dict(
id=1,
username='first last',
firstName='first',
lastName='last'
)
body = user.User(**value_simple)
mock_request.return_value = self.response(
b''
)
api_response = self.api.body_with_query_params(
body=body,
query_params=dict(query='hi there')
)
self.assert_request_called_with(
mock_request,
'http://petstore.swagger.io:80/v2/fake/body-with-query-params?query=hi%20there',
method='PUT',
body=self.json_bytes(value_simple),
accept_content_type=None
)
assert isinstance(api_response.body, api_client.Unset)
assert api_response.response.status == 200
def test_upload_download_file_tx_bytes_and_file(self): def test_upload_download_file_tx_bytes_and_file(self):
"""Test case for upload_download_file """Test case for upload_download_file
uploads a file and downloads a file using application/octet-stream # noqa: E501 uploads a file and downloads a file using application/octet-stream # noqa: E501
@ -346,7 +277,7 @@ class TestFakeApi(unittest.TestCase):
with open(file_path1, "rb") as some_file: with open(file_path1, "rb") as some_file:
file_bytes = some_file.read() file_bytes = some_file.read()
file1 = open(file_path1, "rb") file1 = open(file_path1, "rb")
mock_response = self.__response( mock_response = self.response(
file_bytes, file_bytes,
content_type='application/octet-stream' content_type='application/octet-stream'
) )
@ -354,7 +285,7 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = mock_response mock_request.return_value = mock_response
api_response = self.api.upload_download_file(body=file1) api_response = self.api.upload_download_file(body=file1)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile', 'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile',
body=file_bytes, body=file_bytes,
@ -374,7 +305,7 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = mock_response mock_request.return_value = mock_response
api_response = self.api.upload_download_file(body=file_bytes) api_response = self.api.upload_download_file(body=file_bytes)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile', 'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile',
body=file_bytes, body=file_bytes,
@ -411,7 +342,7 @@ class TestFakeApi(unittest.TestCase):
streamable_body = StreamableBody(file1) streamable_body = StreamableBody(file1)
mock_response = self.__response( mock_response = self.response(
streamable_body, streamable_body,
content_type='application/octet-stream', content_type='application/octet-stream',
preload_content=False preload_content=False
@ -419,7 +350,7 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = mock_response mock_request.return_value = mock_response
api_response = self.api.upload_download_file(body=file_bytes, stream=True) api_response = self.api.upload_download_file(body=file_bytes, stream=True)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile', 'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile',
body=file_bytes, body=file_bytes,
@ -443,7 +374,7 @@ class TestFakeApi(unittest.TestCase):
when streaming is used and the response contains the content disposition header with a filename when streaming is used and the response contains the content disposition header with a filename
that filename is used when saving the file locally that filename is used when saving the file locally
""" """
mock_response = self.__response( mock_response = self.response(
streamable_body, streamable_body,
content_type='application/octet-stream', content_type='application/octet-stream',
headers={'content-disposition': f'attachment; filename="{saved_file_name}"'}, headers={'content-disposition': f'attachment; filename="{saved_file_name}"'},
@ -452,7 +383,7 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = mock_response mock_request.return_value = mock_response
api_response = self.api.upload_download_file(body=file_bytes, stream=True) api_response = self.api.upload_download_file(body=file_bytes, stream=True)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile', 'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile',
body=file_bytes, body=file_bytes,
@ -489,11 +420,11 @@ class TestFakeApi(unittest.TestCase):
} }
try: try:
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(response_json) self.json_bytes(response_json)
) )
api_response = self.api.upload_file(body={'file': file1}) api_response = self.api.upload_file(body={'file': file1})
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/uploadFile', 'http://petstore.swagger.io:80/v2/fake/uploadFile',
fields=( fields=(
@ -514,11 +445,11 @@ class TestFakeApi(unittest.TestCase):
# sending just bytes works also # sending just bytes works also
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(response_json) self.json_bytes(response_json)
) )
api_response = self.api.upload_file(body={'file': file_bytes}) api_response = self.api.upload_file(body={'file': file_bytes})
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/uploadFile', 'http://petstore.swagger.io:80/v2/fake/uploadFile',
fields=( fields=(
@ -567,11 +498,11 @@ class TestFakeApi(unittest.TestCase):
} }
try: try:
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(response_json) self.json_bytes(response_json)
) )
api_response = self.api.upload_files(body={'files': [file1, file1]}) api_response = self.api.upload_files(body={'files': [file1, file1]})
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/uploadFiles', 'http://petstore.swagger.io:80/v2/fake/uploadFiles',
fields=( fields=(
@ -598,11 +529,11 @@ class TestFakeApi(unittest.TestCase):
# sending just bytes works also # sending just bytes works also
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(response_json) self.json_bytes(response_json)
) )
api_response = self.api.upload_files(body={'files': [file_bytes, file_bytes]}) api_response = self.api.upload_files(body={'files': [file_bytes, file_bytes]})
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/uploadFiles', 'http://petstore.swagger.io:80/v2/fake/uploadFiles',
fields=( fields=(
@ -640,11 +571,11 @@ class TestFakeApi(unittest.TestCase):
testing composed schemas at inline locations # noqa: E501 testing composed schemas at inline locations # noqa: E501
""" """
single_char_str = 'a' single_char_str = 'a'
json_bytes = self.__json_bytes(single_char_str) json_bytes = self.json_bytes(single_char_str)
# tx and rx json with composition at root level of schema for request + response body # tx and rx json with composition at root level of schema for request + response body
content_type = 'application/json' content_type = 'application/json'
mock_request.return_value = self.__response( mock_request.return_value = self.response(
json_bytes json_bytes
) )
api_response = self.api.inline_composition( api_response = self.api.inline_composition(
@ -655,12 +586,11 @@ class TestFakeApi(unittest.TestCase):
}, },
accept_content_types=(content_type,) accept_content_types=(content_type,)
) )
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/inlineComposition/', 'http://petstore.swagger.io:80/v2/fake/inlineComposition/?compositionAtRoot=a&someProp=a',
accept_content_type=content_type, accept_content_type=content_type,
content_type=content_type, content_type=content_type,
query_params=(('compositionAtRoot', 'a'), ('someProp', 'a')),
body=json_bytes body=json_bytes
) )
self.assertEqual(api_response.body, single_char_str) self.assertEqual(api_response.body, single_char_str)
@ -669,7 +599,7 @@ class TestFakeApi(unittest.TestCase):
# tx and rx json with composition at property level of schema for request + response body # tx and rx json with composition at property level of schema for request + response body
content_type = 'multipart/form-data' content_type = 'multipart/form-data'
multipart_response = self.__encode_multipart_formdata(fields={'someProp': single_char_str}) multipart_response = self.__encode_multipart_formdata(fields={'someProp': single_char_str})
mock_request.return_value = self.__response( mock_request.return_value = self.response(
bytes(multipart_response), bytes(multipart_response),
content_type=multipart_response.get_content_type() content_type=multipart_response.get_content_type()
) )
@ -682,12 +612,11 @@ class TestFakeApi(unittest.TestCase):
content_type=content_type, content_type=content_type,
accept_content_types=(content_type,) accept_content_types=(content_type,)
) )
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/inlineComposition/', 'http://petstore.swagger.io:80/v2/fake/inlineComposition/?compositionAtRoot=a&someProp=a',
accept_content_type=content_type, accept_content_type=content_type,
content_type=content_type, content_type=content_type,
query_params=(('compositionAtRoot', 'a'), ('someProp', 'a')),
fields=( fields=(
api_client.RequestField( api_client.RequestField(
name='someProp', name='someProp',
@ -707,7 +636,7 @@ class TestFakeApi(unittest.TestCase):
values[invalid_index] = invalid_value values[invalid_index] = invalid_value
with self.assertRaises(exceptions.ApiValueError): with self.assertRaises(exceptions.ApiValueError):
multipart_response = self.__encode_multipart_formdata(fields={'someProp': values[0]}) multipart_response = self.__encode_multipart_formdata(fields={'someProp': values[0]})
mock_request.return_value = self.__response( mock_request.return_value = self.response(
bytes(multipart_response), bytes(multipart_response),
content_type=multipart_response.get_content_type() content_type=multipart_response.get_content_type()
) )
@ -726,16 +655,16 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
body = None body = None
content_type_with_charset = 'application/json; charset=utf-8' content_type_with_charset = 'application/json; charset=utf-8'
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(body), self.json_bytes(body),
content_type=content_type_with_charset content_type=content_type_with_charset
) )
api_response = self.api.json_with_charset(body=body) api_response = self.api.json_with_charset(body=body)
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/jsonWithCharset', 'http://petstore.swagger.io:80/v2/fake/jsonWithCharset',
body=self.__json_bytes(body), body=self.json_bytes(body),
content_type=content_type_with_charset, content_type=content_type_with_charset,
accept_content_type=content_type_with_charset accept_content_type=content_type_with_charset
) )
@ -749,12 +678,12 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
body = None body = None
content_type = 'application/json' content_type = 'application/json'
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(body), self.json_bytes(body),
) )
api_response = self.api.response_without_schema() api_response = self.api.response_without_schema()
self.__assert_request_called_with( self.assert_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/responseWithoutSchema', 'http://petstore.swagger.io:80/v2/fake/responseWithoutSchema',
method='GET', method='GET',
@ -766,7 +695,7 @@ class TestFakeApi(unittest.TestCase):
with patch.object(RESTClientObject, 'request') as mock_request: with patch.object(RESTClientObject, 'request') as mock_request:
mock_request.return_value = self.__response( mock_request.return_value = self.response(
'blah', 'blah',
content_type='text/plain' content_type='text/plain'
) )
@ -779,12 +708,12 @@ class TestFakeApi(unittest.TestCase):
with patch.object(urllib3.PoolManager, 'request') as mock_request: with patch.object(urllib3.PoolManager, 'request') as mock_request:
body = None body = None
mock_request.return_value = self.__response( mock_request.return_value = self.response(
self.__json_bytes(body), self.json_bytes(body),
) )
api_response = self.api.delete_coffee(path_params=dict(id='1')) api_response = self.api.delete_coffee(path_params=dict(id='1'))
self.__assert_pool_manager_request_called_with( self.assert_pool_manager_request_called_with(
mock_request, mock_request,
'http://petstore.swagger.io:80/v2/fake/deleteCoffee/1', 'http://petstore.swagger.io:80/v2/fake/deleteCoffee/1',
method='DELETE', method='DELETE',

View File

@ -11,8 +11,7 @@
import unittest import unittest
import collections import collections
from petstore_api import api_client from petstore_api import api_client, exceptions, schemas
from petstore_api import schemas
ParamTestCase = collections.namedtuple('ParamTestCase', 'payload expected_serialization explode', defaults=[False]) ParamTestCase = collections.namedtuple('ParamTestCase', 'payload expected_serialization explode', defaults=[False])
@ -25,6 +24,11 @@ class TestParameter(unittest.TestCase):
api_client.ParameterInType.HEADER: api_client.HeaderParameter, api_client.ParameterInType.HEADER: api_client.HeaderParameter,
} }
invalid_inputs = (
True,
False
)
def test_throws_exception_when_schema_and_content_omitted(self): def test_throws_exception_when_schema_and_content_omitted(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
api_client.QueryParameter( api_client.QueryParameter(
@ -95,68 +99,52 @@ class TestParameter(unittest.TestCase):
test_cases = ( test_cases = (
ParamTestCase( ParamTestCase(
None, None,
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
1, 1,
(('color', '1'),) dict(color='?color=1')
), ),
ParamTestCase( ParamTestCase(
3.14, 3.14,
(('color', '3.14'),) dict(color='?color=3.14')
), ),
ParamTestCase( ParamTestCase(
'blue', 'blue',
(('color', 'blue'),) dict(color='?color=blue')
), ),
ParamTestCase( ParamTestCase(
'hello world', 'hello world',
(('color', 'hello%20world'),) dict(color='?color=hello%20world')
), ),
ParamTestCase( ParamTestCase(
'', '',
(('color', ''),) dict(color='?color=')
),
ParamTestCase(
True,
(('color', 'true'),)
),
ParamTestCase(
False,
(('color', 'false'),)
), ),
ParamTestCase( ParamTestCase(
[], [],
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
(('color', 'blue,black,brown'),) dict(color='?color=blue,black,brown')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
( dict(color='?color=blue&color=black&color=brown'),
('color', 'blue'),
('color', 'black'),
('color', 'brown'),
),
explode=True explode=True
), ),
ParamTestCase( ParamTestCase(
{}, {},
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
(('color', 'R,100,G,200,B,150'),) dict(color='?color=R,100,G,200,B,150')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
( dict(color='?R=100&G=200&B=150'),
('R', '100'),
('G', '200'),
('B', '150'),
),
explode=True explode=True
), ),
) )
@ -170,73 +158,68 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
for explode in (True, False):
parameter = api_client.QueryParameter(
name=name,
style=api_client.ParameterStyle.FORM,
schema=schemas.AnyTypeSchema,
explode=explode,
)
parameter.serialize(invalid_input)
def test_cookie_style_form_serialization(self): def test_cookie_style_form_serialization(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
ParamTestCase( ParamTestCase(
None, None,
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
1, 1,
(('color', '1'),) dict(color='color=1')
), ),
ParamTestCase( ParamTestCase(
3.14, 3.14,
(('color', '3.14'),) dict(color='color=3.14')
), ),
ParamTestCase( ParamTestCase(
'blue', 'blue',
(('color', 'blue'),) dict(color='color=blue')
), ),
ParamTestCase( ParamTestCase(
'hello world', 'hello world',
(('color', 'hello%20world'),) dict(color='color=hello world')
), ),
ParamTestCase( ParamTestCase(
'', '',
(('color', ''),) dict(color='color=')
),
ParamTestCase(
True,
(('color', 'true'),)
),
ParamTestCase(
False,
(('color', 'false'),)
), ),
ParamTestCase( ParamTestCase(
[], [],
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
(('color', 'blue,black,brown'),) dict(color='color=blue,black,brown')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
( dict(color='color=blue&color=black&color=brown'),
('color', 'blue'),
('color', 'black'),
('color', 'brown'),
),
explode=True explode=True
), ),
ParamTestCase( ParamTestCase(
{}, {},
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
(('color', 'R,100,G,200,B,150'),) dict(color='color=R,100,G,200,B,150')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
( dict(color='R=100&G=200&B=150'),
('R', '100'),
('G', '200'),
('B', '150'),
),
explode=True explode=True
), ),
) )
@ -250,6 +233,17 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
for explode in (True, False):
parameter = api_client.CookieParameter(
name=name,
style=api_client.ParameterStyle.FORM,
schema=schemas.AnyTypeSchema,
explode=explode,
)
parameter.serialize(invalid_input)
def test_style_simple_in_path_serialization(self): def test_style_simple_in_path_serialization(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
@ -277,14 +271,6 @@ class TestParameter(unittest.TestCase):
'', '',
dict(color='') dict(color='')
), ),
ParamTestCase(
True,
dict(color='true')
),
ParamTestCase(
False,
dict(color='false')
),
ParamTestCase( ParamTestCase(
[], [],
dict(color='') dict(color='')
@ -322,12 +308,23 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
for explode in (True, False):
parameter = api_client.PathParameter(
name=name,
style=api_client.ParameterStyle.SIMPLE,
schema=schemas.AnyTypeSchema,
explode=explode,
)
parameter.serialize(invalid_input)
def test_style_simple_in_header_serialization(self): def test_style_simple_in_header_serialization(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
ParamTestCase( ParamTestCase(
None, None,
{} dict(color='')
), ),
ParamTestCase( ParamTestCase(
1, 1,
@ -343,23 +340,15 @@ class TestParameter(unittest.TestCase):
), ),
ParamTestCase( ParamTestCase(
'hello world', 'hello world',
dict(color='hello%20world') dict(color='hello world')
), ),
ParamTestCase( ParamTestCase(
'', '',
dict(color='') dict(color='')
), ),
ParamTestCase(
True,
dict(color='true')
),
ParamTestCase(
False,
dict(color='false')
),
ParamTestCase( ParamTestCase(
[], [],
{} dict(color='')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
@ -372,7 +361,7 @@ class TestParameter(unittest.TestCase):
), ),
ParamTestCase( ParamTestCase(
{}, {},
{} dict(color='')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
@ -385,7 +374,6 @@ class TestParameter(unittest.TestCase):
), ),
) )
for test_case in test_cases: for test_case in test_cases:
print(test_case.payload)
parameter = api_client.HeaderParameter( parameter = api_client.HeaderParameter(
name=name, name=name,
style=api_client.ParameterStyle.SIMPLE, style=api_client.ParameterStyle.SIMPLE,
@ -395,6 +383,17 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
for explode in (True, False):
parameter = api_client.HeaderParameter(
name=name,
style=api_client.ParameterStyle.SIMPLE,
schema=schemas.AnyTypeSchema,
explode=explode,
)
parameter.serialize(invalid_input)
def test_style_label_in_path_serialization(self): def test_style_label_in_path_serialization(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
@ -422,14 +421,6 @@ class TestParameter(unittest.TestCase):
'', '',
dict(color='.') dict(color='.')
), ),
ParamTestCase(
True,
dict(color='.true')
),
ParamTestCase(
False,
dict(color='.false')
),
ParamTestCase( ParamTestCase(
[], [],
dict(color='') dict(color='')
@ -467,6 +458,17 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
for explode in (True, False):
parameter = api_client.PathParameter(
name=name,
style=api_client.ParameterStyle.LABEL,
schema=schemas.AnyTypeSchema,
explode=explode,
)
parameter.serialize(invalid_input)
def test_style_matrix_in_path_serialization(self): def test_style_matrix_in_path_serialization(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
@ -494,14 +496,6 @@ class TestParameter(unittest.TestCase):
'', '',
dict(color=';color') dict(color=';color')
), ),
ParamTestCase(
True,
dict(color=';color=true')
),
ParamTestCase(
False,
dict(color=';color=false')
),
ParamTestCase( ParamTestCase(
[], [],
dict(color='') dict(color='')
@ -539,66 +533,59 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
for explode in (True, False):
parameter = api_client.PathParameter(
name=name,
style=api_client.ParameterStyle.MATRIX,
schema=schemas.AnyTypeSchema,
explode=explode,
)
parameter.serialize(invalid_input)
def test_style_space_delimited_serialization(self): def test_style_space_delimited_serialization(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
ParamTestCase( ParamTestCase(
None, None,
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
1, 1,
(('color', '1'),) dict(color='1')
), ),
ParamTestCase( ParamTestCase(
3.14, 3.14,
(('color', '3.14'),) dict(color='3.14')
), ),
ParamTestCase( ParamTestCase(
'blue', 'blue',
(('color', 'blue'),) dict(color='blue')
), ),
ParamTestCase( ParamTestCase(
'hello world', 'hello world',
(('color', 'hello%20world'),) dict(color='hello%20world')
), ),
ParamTestCase( ParamTestCase(
'', '',
(('color', ''),) dict(color='')
),
ParamTestCase(
True,
(('color', 'true'),)
),
ParamTestCase(
False,
(('color', 'false'),)
), ),
ParamTestCase( ParamTestCase(
[], [],
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
(('color', 'blue%20black%20brown'),) dict(color='blue%20black%20brown')
),
ParamTestCase(
['blue', 'black', 'brown'],
(('color', 'color=blue%20color=black%20color=brown'),),
explode=True
), ),
ParamTestCase( ParamTestCase(
{}, {},
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
(('color', 'R%20100%20G%20200%20B%20150'),) dict(color='R%20100%20G%20200%20B%20150')
),
ParamTestCase(
dict(R=100, G=200, B=150),
(('color', 'R=100%20G=200%20B=150'),),
explode=True
), ),
) )
for test_case in test_cases: for test_case in test_cases:
@ -611,66 +598,59 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
for explode in (True, False):
parameter = api_client.QueryParameter(
name=name,
style=api_client.ParameterStyle.SPACE_DELIMITED,
schema=schemas.AnyTypeSchema,
explode=explode,
)
parameter.serialize(invalid_input)
def test_style_pipe_delimited_serialization(self): def test_style_pipe_delimited_serialization(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
ParamTestCase( ParamTestCase(
None, None,
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
1, 1,
(('color', '1'),) dict(color='1')
), ),
ParamTestCase( ParamTestCase(
3.14, 3.14,
(('color', '3.14'),) dict(color='3.14')
), ),
ParamTestCase( ParamTestCase(
'blue', 'blue',
(('color', 'blue'),) dict(color='blue')
), ),
ParamTestCase( ParamTestCase(
'hello world', 'hello world',
(('color', 'hello%20world'),) dict(color='hello%20world')
), ),
ParamTestCase( ParamTestCase(
'', '',
(('color', ''),) dict(color='')
),
ParamTestCase(
True,
(('color', 'true'),)
),
ParamTestCase(
False,
(('color', 'false'),)
), ),
ParamTestCase( ParamTestCase(
[], [],
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
(('color', 'blue|black|brown'),) dict(color='blue|black|brown')
),
ParamTestCase(
['blue', 'black', 'brown'],
(('color', 'color=blue|color=black|color=brown'),),
explode=True
), ),
ParamTestCase( ParamTestCase(
{}, {},
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
(('color', 'R|100|G|200|B|150'),) dict(color='R|100|G|200|B|150')
),
ParamTestCase(
dict(R=100, G=200, B=150),
(('color', 'R=100|G=200|B=150'),),
explode=True
), ),
) )
for test_case in test_cases: for test_case in test_cases:
@ -683,6 +663,17 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
for explode in (True, False):
parameter = api_client.QueryParameter(
name=name,
style=api_client.ParameterStyle.PIPE_DELIMITED,
schema=schemas.AnyTypeSchema,
explode=explode,
)
parameter.serialize(invalid_input)
def test_path_params_no_style(self): def test_path_params_no_style(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
@ -710,14 +701,6 @@ class TestParameter(unittest.TestCase):
'', '',
dict(color='') dict(color='')
), ),
ParamTestCase(
True,
dict(color='true')
),
ParamTestCase(
False,
dict(color='false')
),
ParamTestCase( ParamTestCase(
[], [],
dict(color='') dict(color='')
@ -743,12 +726,20 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
parameter = api_client.PathParameter(
name=name,
schema=schemas.AnyTypeSchema,
)
parameter.serialize(invalid_input)
def test_header_params_no_style(self): def test_header_params_no_style(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
ParamTestCase( ParamTestCase(
None, None,
{} dict(color='')
), ),
ParamTestCase( ParamTestCase(
1, 1,
@ -764,23 +755,15 @@ class TestParameter(unittest.TestCase):
), ),
ParamTestCase( ParamTestCase(
'hello world', 'hello world',
dict(color='hello%20world') dict(color='hello world')
), ),
ParamTestCase( ParamTestCase(
'', '',
dict(color='') dict(color='')
), ),
ParamTestCase(
True,
dict(color='true')
),
ParamTestCase(
False,
dict(color='false')
),
ParamTestCase( ParamTestCase(
[], [],
{} dict(color='')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
@ -788,7 +771,7 @@ class TestParameter(unittest.TestCase):
), ),
ParamTestCase( ParamTestCase(
{}, {},
{} dict(color='')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
@ -803,67 +786,136 @@ class TestParameter(unittest.TestCase):
serialization = parameter.serialize(test_case.payload) serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization) self.assertEqual(serialization, test_case.expected_serialization)
def test_query_or_cookie_params_no_style(self): with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
parameter = api_client.HeaderParameter(
name=name,
schema=schemas.AnyTypeSchema,
)
parameter.serialize(invalid_input)
def test_query_params_no_style(self):
name = 'color' name = 'color'
test_cases = ( test_cases = (
ParamTestCase( ParamTestCase(
None, None,
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
1, 1,
(('color', '1'),) dict(color='?color=1')
), ),
ParamTestCase( ParamTestCase(
3.14, 3.14,
(('color', '3.14'),) dict(color='?color=3.14')
), ),
ParamTestCase( ParamTestCase(
'blue', 'blue',
(('color', 'blue'),) dict(color='?color=blue')
), ),
ParamTestCase( ParamTestCase(
'hello world', 'hello world',
(('color', 'hello%20world'),) dict(color='?color=hello%20world')
), ),
ParamTestCase( ParamTestCase(
'', '',
(('color', ''),) dict(color='?color=')
),
ParamTestCase(
True,
(('color', 'true'),)
),
ParamTestCase(
False,
(('color', 'false'),)
), ),
ParamTestCase( ParamTestCase(
[], [],
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
['blue', 'black', 'brown'], ['blue', 'black', 'brown'],
(('color', 'blue,black,brown'),) dict(color='?color=blue&color=black&color=brown')
), ),
ParamTestCase( ParamTestCase(
{}, {},
() dict(color='')
), ),
ParamTestCase( ParamTestCase(
dict(R=100, G=200, B=150), dict(R=100, G=200, B=150),
(('color', 'R,100,G,200,B,150'),) dict(color='?R=100&G=200&B=150')
), ),
) )
for in_type in {api_client.ParameterInType.QUERY, api_client.ParameterInType.COOKIE}: for test_case in test_cases:
for test_case in test_cases: parameter = api_client.QueryParameter(
parameter_cls = self.in_type_to_parameter_cls[in_type] name=name,
parameter = parameter_cls( schema=schemas.AnyTypeSchema,
)
print(parameter.explode)
print(test_case.payload)
serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
parameter = api_client.QueryParameter(
name=name, name=name,
schema=schemas.AnyTypeSchema, schema=schemas.AnyTypeSchema,
) )
serialization = parameter.serialize(test_case.payload) parameter.serialize(invalid_input)
self.assertEqual(serialization, test_case.expected_serialization)
def test_cookie_params_no_style(self):
name = 'color'
test_cases = (
ParamTestCase(
None,
dict(color='')
),
ParamTestCase(
1,
dict(color='color=1')
),
ParamTestCase(
3.14,
dict(color='color=3.14')
),
ParamTestCase(
'blue',
dict(color='color=blue')
),
ParamTestCase(
'hello world',
dict(color='color=hello world')
),
ParamTestCase(
'',
dict(color='color=')
),
ParamTestCase(
[],
dict(color='')
),
ParamTestCase(
['blue', 'black', 'brown'],
dict(color='color=blue&color=black&color=brown')
),
ParamTestCase(
{},
dict(color='')
),
ParamTestCase(
dict(R=100, G=200, B=150),
dict(color='R=100&G=200&B=150')
),
)
for test_case in test_cases:
parameter = api_client.CookieParameter(
name=name,
schema=schemas.AnyTypeSchema,
)
print(test_case.payload)
serialization = parameter.serialize(test_case.payload)
self.assertEqual(serialization, test_case.expected_serialization)
with self.assertRaises(exceptions.ApiValueError):
for invalid_input in self.invalid_inputs:
parameter = api_client.CookieParameter(
name=name,
schema=schemas.AnyTypeSchema,
)
parameter.serialize(invalid_input)
def test_checks_content_lengths(self): def test_checks_content_lengths(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):

View File

@ -123,13 +123,13 @@ class TestParameter(unittest.TestCase):
serialization = request_body.serialize(payload, content_type) serialization = request_body.serialize(payload, content_type)
self.assertEqual( self.assertEqual(
serialization, serialization,
{'fields': (('some_str', 'a'), ('some_int', '1'), ('some_float', '3.14'))} dict(body='?some_str=a&some_int=1&some_float=3.14')
) )
serialization = request_body.serialize({}, content_type) serialization = request_body.serialize({}, content_type)
self.assertEqual( self.assertEqual(
serialization, serialization,
{} dict(body='')
) )
invalid_payloads = [ invalid_payloads = [

View File

@ -0,0 +1,108 @@
# coding: utf-8
"""
OpenAPI Petstore
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
The version of the OpenAPI document: 1.0.0
Generated by: https://openapi-generator.tech
"""
import unittest
from unittest.mock import patch
import petstore_api
from petstore_api import api_client
from petstore_api.api.user_api import UserApi
from petstore_api.rest import RESTClientObject
from . import ApiTestMixin
class TestUserApi(ApiTestMixin):
"""UserApi unit test stubs"""
configuration = petstore_api.Configuration()
api = UserApi(api_client=api_client.ApiClient(configuration=configuration))
def test_create_user(self):
"""Test case for create_user
Create user # noqa: E501
"""
pass
def test_create_users_with_array_input(self):
"""Test case for create_users_with_array_input
Creates list of users with given input array # noqa: E501
"""
pass
def test_create_users_with_list_input(self):
"""Test case for create_users_with_list_input
Creates list of users with given input array # noqa: E501
"""
pass
def test_delete_user(self):
"""Test case for delete_user
Delete user # noqa: E501
"""
pass
def test_get_user_by_name(self):
from petstore_api.model import user
# serialization + deserialization works
with patch.object(RESTClientObject, 'request') as mock_request:
value_simple = dict(
id=1,
username='first last',
firstName='first',
lastName='last'
)
body = user.User(**value_simple)
mock_request.return_value = self.response(
self.json_bytes(value_simple)
)
api_response = self.api.get_user_by_name(
path_params=dict(username='first last')
)
self.assert_request_called_with(
mock_request,
'http://petstore.swagger.io:80/v2/user/first%20last',
method='GET',
accept_content_type='application/xml, application/json',
content_type=None
)
assert isinstance(api_response.body, user.User)
assert api_response.body == body
def test_login_user(self):
"""Test case for login_user
Logs user into the system # noqa: E501
"""
pass
def test_logout_user(self):
"""Test case for logout_user
Logs out current logged in user session # noqa: E501
"""
pass
def test_update_user(self):
"""Test case for update_user
Updated user # noqa: E501
"""
pass
if __name__ == '__main__':
unittest.main()