[Python] Add option to select/detect content-type. (#10978)

* [Python] Add option to select/detect content-type.

* Regenerate samples after rebase.

* Update samples.

* test: fix assertion
This commit is contained in:
Tomasz Prus
2021-12-08 22:15:26 +01:00
committed by GitHub
parent 347b75a024
commit b755ae288a
32 changed files with 855 additions and 61 deletions

View File

@@ -119,6 +119,9 @@ class AnotherFakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -147,6 +150,8 @@ class AnotherFakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body

View File

@@ -1132,6 +1132,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1160,6 +1163,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.array_model_endpoint.call_with_http_info(**kwargs)
@@ -1194,6 +1199,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1222,6 +1230,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.boolean_endpoint.call_with_http_info(**kwargs)
@@ -1258,6 +1268,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1286,6 +1299,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['xml_item'] = \
xml_item
@@ -1322,6 +1337,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1350,6 +1368,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.number_with_validations_endpoint.call_with_http_info(**kwargs)
@@ -1384,6 +1404,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1412,6 +1435,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.object_model_with_ref_props_endpoint.call_with_http_info(**kwargs)
@@ -1446,6 +1471,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1474,6 +1502,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.string_endpoint.call_with_http_info(**kwargs)
@@ -1508,6 +1538,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1536,6 +1569,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.string_enum_endpoint.call_with_http_info(**kwargs)
@@ -1572,6 +1607,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1600,6 +1638,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body
@@ -1639,6 +1679,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1667,6 +1710,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['query'] = \
query
@@ -1707,6 +1752,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1735,6 +1783,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body
@@ -1781,6 +1831,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1809,6 +1862,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['query_integer'] = \
query_integer
@@ -1871,6 +1926,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1899,6 +1957,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['number'] = \
number
@@ -1948,6 +2008,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1976,6 +2039,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.test_enum_parameters_endpoint.call_with_http_info(**kwargs)
@@ -2019,6 +2084,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -2047,6 +2115,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['required_string_group'] = \
required_string_group
@@ -2088,6 +2158,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -2116,6 +2189,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['param'] = \
param
@@ -2155,6 +2230,9 @@ class FakeApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -2183,6 +2261,8 @@ class FakeApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['param'] = \
param

View File

@@ -121,6 +121,9 @@ class FakeClassnameTags123Api(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -149,6 +152,8 @@ class FakeClassnameTags123Api(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body

View File

@@ -584,6 +584,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -612,6 +615,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body
@@ -650,6 +655,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -678,6 +686,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['pet_id'] = \
pet_id
@@ -716,6 +726,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -744,6 +757,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['status'] = \
status
@@ -782,6 +797,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -810,6 +828,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['tags'] = \
tags
@@ -848,6 +868,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -876,6 +899,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['pet_id'] = \
pet_id
@@ -913,6 +938,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -941,6 +969,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body
@@ -980,6 +1010,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1008,6 +1041,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['pet_id'] = \
pet_id
@@ -1048,6 +1083,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1076,6 +1114,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['pet_id'] = \
pet_id
@@ -1116,6 +1156,9 @@ class PetApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -1144,6 +1187,8 @@ class PetApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['pet_id'] = \
pet_id

View File

@@ -265,6 +265,9 @@ class StoreApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -293,6 +296,8 @@ class StoreApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['order_id'] = \
order_id
@@ -328,6 +333,9 @@ class StoreApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -356,6 +364,8 @@ class StoreApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.get_inventory_endpoint.call_with_http_info(**kwargs)
@@ -392,6 +402,9 @@ class StoreApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -420,6 +433,8 @@ class StoreApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['order_id'] = \
order_id
@@ -457,6 +472,9 @@ class StoreApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -485,6 +503,8 @@ class StoreApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body

View File

@@ -452,6 +452,9 @@ class UserApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -480,6 +483,8 @@ class UserApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body
@@ -517,6 +522,9 @@ class UserApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -545,6 +553,8 @@ class UserApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body
@@ -582,6 +592,9 @@ class UserApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -610,6 +623,8 @@ class UserApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['body'] = \
body
@@ -648,6 +663,9 @@ class UserApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -676,6 +694,8 @@ class UserApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['username'] = \
username
@@ -713,6 +733,9 @@ class UserApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -741,6 +764,8 @@ class UserApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['username'] = \
username
@@ -780,6 +805,9 @@ class UserApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -808,6 +836,8 @@ class UserApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['username'] = \
username
@@ -844,6 +874,9 @@ class UserApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -872,6 +905,8 @@ class UserApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
return self.logout_user_endpoint.call_with_http_info(**kwargs)
@@ -910,6 +945,9 @@ class UserApi(object):
_check_return_type (bool): specifies if type checking
should be done one the data received from the server.
Default is True.
_content_type (str/None): force body content-type.
Default is None and content-type will be predicted by allowed
content-types and body.
_host_index (int/None): specifies the index of the server
that we want to use.
Default is read from the configuration.
@@ -938,6 +976,8 @@ class UserApi(object):
kwargs['_check_return_type'] = kwargs.get(
'_check_return_type', True
)
kwargs['_content_type'] = kwargs.get(
'_content_type')
kwargs['_host_index'] = kwargs.get('_host_index')
kwargs['username'] = \
username

View File

@@ -131,7 +131,8 @@ class ApiClient(object):
_preload_content: bool = True,
_request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None
_check_type: typing.Optional[bool] = None,
_content_type: typing.Optional[str] = None
):
config = self.configuration
@@ -572,10 +573,12 @@ class ApiClient(object):
else:
return ', '.join(accepts)
def select_header_content_type(self, content_types):
def select_header_content_type(self, content_types, method=None, body=None):
"""Returns `Content-Type` based on an array of content_types provided.
:param content_types: List of content-types.
:param method: http method (e.g. POST, PATCH).
:param body: http body to send.
:return: Content-Type (e.g. application/json).
"""
if not content_types:
@@ -583,6 +586,11 @@ class ApiClient(object):
content_types = [x.lower() for x in content_types]
if (method == 'PATCH' and
'application/json-patch+json' in content_types and
isinstance(body, list)):
return 'application/json-patch+json'
if 'application/json' in content_types or '*/*' in content_types:
return 'application/json'
else:
@@ -664,7 +672,8 @@ class Endpoint(object):
'_request_timeout',
'_return_http_data_only',
'_check_input_type',
'_check_return_type'
'_check_return_type',
'_content_type'
])
self.params_map['nullable'].extend(['_request_timeout'])
self.validations = root_map['validations']
@@ -677,7 +686,8 @@ class Endpoint(object):
'_request_timeout': (none_type, float, (float,), [float], int, (int,), [int]),
'_return_http_data_only': (bool,),
'_check_input_type': (bool,),
'_check_return_type': (bool,)
'_check_return_type': (bool,),
'_content_type': (none_type, str)
}
self.openapi_types.update(extra_types)
self.attribute_map = root_map['attribute_map']
@@ -824,12 +834,16 @@ class Endpoint(object):
params['header']['Accept'] = self.api_client.select_header_accept(
accept_headers_list)
content_type_headers_list = self.headers_map['content_type']
if content_type_headers_list:
if params['body'] != "":
header_list = self.api_client.select_header_content_type(
content_type_headers_list)
params['header']['Content-Type'] = header_list
if kwargs.get('_content_type'):
params['header']['Content-Type'] = kwargs['_content_type']
else:
content_type_headers_list = self.headers_map['content_type']
if content_type_headers_list:
if params['body'] != "":
header_list = self.api_client.select_header_content_type(
content_type_headers_list, self.settings['http_method'],
params['body'])
params['header']['Content-Type'] = header_list
return self.api_client.call_api(
self.settings['endpoint_path'], self.settings['http_method'],

View File

@@ -121,6 +121,7 @@ class TestFakeApi(unittest.TestCase):
call_with_http_info.assert_called_with(
_check_input_type=True,
_check_return_type=True,
_content_type=None,
_host_index=None,
_preload_content=True,
_request_timeout=None,

View File

@@ -122,6 +122,16 @@ class ApiClientTests(unittest.TestCase):
content_type = self.api_client.select_header_content_type(content_types)
self.assertEqual(content_type, 'application/json')
content_types = ['application/json-patch+json', 'application/json']
content_type = self.api_client.select_header_content_type(content_types,
'PATCH', [{ "op": "add", "path": "/myPath", "value": ["myValue"]}])
self.assertEqual(content_type, 'application/json-patch+json')
content_types = ['application/json-patch+json', 'application/json']
content_type = self.api_client.select_header_content_type(content_types,
'PATCH', {"value": ["myValue"]})
self.assertEqual(content_type, 'application/json')
def test_sanitize_for_serialization(self):
# None
data = None

View File

@@ -391,7 +391,6 @@ class PetApiTests(unittest.TestCase):
file.close()
self.pet_api.upload_file(pet_id=self.pet.id, file=file)
def test_delete_pet(self):
self.pet_api.add_pet(self.pet)
self.pet_api.delete_pet(pet_id=self.pet.id, api_key="special-key")
@@ -402,5 +401,29 @@ class PetApiTests(unittest.TestCase):
except ApiException as e:
self.assertEqual(404, e.status)
@patch.object(petstore_api.ApiClient, 'call_api')
@patch.object(petstore_api.ApiClient, 'select_header_content_type')
def test_call_select_header_content_type(self, mock_select_ct, mock_call_api):
mock_select_ct.return_value = 'application/json'
self.pet_api.add_pet(self.pet)
# check if all arguments are passed to select_header_content_type
mock_select_ct.assert_called_once_with(
['application/json', 'application/xml'],
'POST',
self.pet)
mock_call_api.assert_called_once()
self.assertEqual(mock_call_api.mock_calls[0][1][4],
{'Content-Type': 'application/json'})
@patch.object(petstore_api.ApiClient, 'call_api')
def test_call_with_forced_content_type(self, mock_call_api):
# force content-type
self.pet_api.add_pet(self.pet, _content_type='application/xml')
mock_call_api.assert_called_once()
# check if content-type is used
self.assertEqual(mock_call_api.mock_calls[0][1][4],
{'Content-Type': 'application/xml'})
if __name__ == '__main__':
unittest.main()