From df695ee2c47d0b69eb2330dc229ef5870ef14ee5 Mon Sep 17 00:00:00 2001 From: Laurynas Date: Mon, 4 Jul 2016 15:22:54 -0400 Subject: [PATCH 1/4] Python vnd content-type header support Adding vendor header support like : "Content-Type: application/vnd.api+json" and "Content-Type: application/vnd.api+json; version=1" --- modules/swagger-codegen/src/main/resources/python/rest.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index 1a6cf193b6c..bb3747021f5 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -121,7 +121,7 @@ class RESTClientObject(object): if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if query_params: url += '?' + urlencode(query_params) - if headers['Content-Type'] == 'application/json': + if headers['Content-Type'].find('+json') != -1: request_body = None if body: request_body = json.dumps(body) From 23b81324d16adb9bacf24b7a7424e3f790a53a19 Mon Sep 17 00:00:00 2001 From: Laurynas Date: Mon, 4 Jul 2016 15:27:54 -0400 Subject: [PATCH 2/4] Python vnd content-type header support Adding vendor header support like : "Content-Type: application/vnd.api+json" and "Content-Type: application/vnd.api+json; version=1" --- modules/swagger-codegen/src/main/resources/python/rest.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index bb3747021f5..a2e70b6ec7c 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -121,7 +121,7 @@ class RESTClientObject(object): if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if query_params: url += '?' + urlencode(query_params) - if headers['Content-Type'].find('+json') != -1: + if headers['Content-Type'].find('json') != -1: request_body = None if body: request_body = json.dumps(body) From 560f50ab9af839cbd88a63405941c06630251e7e Mon Sep 17 00:00:00 2001 From: laurynas Date: Tue, 5 Jul 2016 11:31:18 -0400 Subject: [PATCH 3/4] case insensitive search for "json" in content-type headers --- .../swagger-codegen/src/main/resources/python/rest.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/python/rest.mustache b/modules/swagger-codegen/src/main/resources/python/rest.mustache index a2e70b6ec7c..19ec32440f8 100644 --- a/modules/swagger-codegen/src/main/resources/python/rest.mustache +++ b/modules/swagger-codegen/src/main/resources/python/rest.mustache @@ -10,6 +10,7 @@ import json import ssl import certifi import logging +import re # python 2 and python 3 compatibility library from six import iteritems @@ -121,7 +122,7 @@ class RESTClientObject(object): if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if query_params: url += '?' + urlencode(query_params) - if headers['Content-Type'].find('json') != -1: + if re.search('json', headers['Content-Type'], re.IGNORECASE): request_body = None if body: request_body = json.dumps(body) From fa9cb66d75f92e404928973251207221819434bc Mon Sep 17 00:00:00 2001 From: laurynas Date: Tue, 5 Jul 2016 11:34:27 -0400 Subject: [PATCH 4/4] ./bin/python-petstore.sh after enhancement of content-type header parsing for vnd headers note: looks like this was not run for some time, so it has changes from other commits too --- samples/client/petstore/python/README.md | 34 +++--- .../client/petstore/python/docs/ArrayTest.md | 1 - .../client/petstore/python/docs/FakeApi.md | 45 -------- .../client/petstore/python/docs/MapTest.md | 1 - .../python/petstore_api/apis/fake_api.py | 101 ------------------ .../python/petstore_api/configuration.py | 14 +-- .../python/petstore_api/models/array_test.py | 38 +------ .../python/petstore_api/models/map_test.py | 34 +----- .../petstore/python/petstore_api/rest.py | 3 +- 9 files changed, 35 insertions(+), 236 deletions(-) diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index 02734b20678..68d7f11b6dd 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -5,7 +5,7 @@ This Python package is automatically generated by the [Swagger Codegen](https:// - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-06-28T16:59:47.081+08:00 +- Build date: 2016-07-05T10:32:24.684-04:00 - Build package: class io.swagger.codegen.languages.PythonClientCodegen ## Requirements. @@ -52,13 +52,24 @@ from petstore_api.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = petstore_api.FakeApi -test_code_inject__end = 'test_code_inject__end_example' # str | To test code injection */ =end (optional) +number = 3.4 # float | None +double = 1.2 # float | None +string = 'string_example' # str | None +byte = 'B' # str | None +integer = 56 # int | None (optional) +int32 = 56 # int | None (optional) +int64 = 789 # int | None (optional) +float = 3.4 # float | None (optional) +binary = 'B' # str | None (optional) +date = '2013-10-20' # date | None (optional) +date_time = '2013-10-20T19:20:30+01:00' # datetime | None (optional) +password = 'password_example' # str | None (optional) try: - # To test code injection */ =end - api_instance.test_code_inject__end(test_code_inject__end=test_code_inject__end) + # Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 + api_instance.test_endpoint_parameters(number, double, string, byte, integer=integer, int32=int32, int64=int64, float=float, binary=binary, date=date, date_time=date_time, password=password) except ApiException as e: - print "Exception when calling FakeApi->test_code_inject__end: %s\n" % e + print "Exception when calling FakeApi->test_endpoint_parameters: %s\n" % e ``` @@ -68,7 +79,6 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*FakeApi* | [**test_code_inject__end**](docs/FakeApi.md#test_code_inject__end) | **PUT** /fake | To test code injection */ =end *FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 *FakeApi* | [**test_enum_query_parameters**](docs/FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters *PetApi* | [**add_pet**](docs/PetApi.md#add_pet) | **POST** /pet | Add a new pet to the store @@ -126,12 +136,6 @@ Class | Method | HTTP request | Description ## Documentation For Authorization -## api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - ## petstore_auth - **Type**: OAuth @@ -141,6 +145,12 @@ Class | Method | HTTP request | Description - **write:pets**: modify pets in your account - **read:pets**: read your pets +## api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + ## Author diff --git a/samples/client/petstore/python/docs/ArrayTest.md b/samples/client/petstore/python/docs/ArrayTest.md index 902710efe0e..6ab0d137806 100644 --- a/samples/client/petstore/python/docs/ArrayTest.md +++ b/samples/client/petstore/python/docs/ArrayTest.md @@ -6,7 +6,6 @@ Name | Type | Description | Notes **array_of_string** | **list[str]** | | [optional] **array_array_of_integer** | **list[list[int]]** | | [optional] **array_array_of_model** | **list[list[ReadOnlyFirst]]** | | [optional] -**array_of_enum** | **list[str]** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python/docs/FakeApi.md b/samples/client/petstore/python/docs/FakeApi.md index 2f670f5e26f..7c818407a76 100644 --- a/samples/client/petstore/python/docs/FakeApi.md +++ b/samples/client/petstore/python/docs/FakeApi.md @@ -4,55 +4,10 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**test_code_inject__end**](FakeApi.md#test_code_inject__end) | **PUT** /fake | To test code injection */ =end [**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 [**test_enum_query_parameters**](FakeApi.md#test_enum_query_parameters) | **GET** /fake | To test enum query parameters -# **test_code_inject__end** -> test_code_inject__end(test_code_inject__end=test_code_inject__end) - -To test code injection */ =end - -### Example -```python -import time -import petstore_api -from petstore_api.rest import ApiException -from pprint import pprint - -# create an instance of the API class -api_instance = petstore_api.FakeApi() -test_code_inject__end = 'test_code_inject__end_example' # str | To test code injection */ =end (optional) - -try: - # To test code injection */ =end - api_instance.test_code_inject__end(test_code_inject__end=test_code_inject__end) -except ApiException as e: - print "Exception when calling FakeApi->test_code_inject__end: %s\n" % e -``` - -### Parameters - -Name | Type | Description | Notes -------------- | ------------- | ------------- | ------------- - **test_code_inject__end** | **str**| To test code injection */ =end | [optional] - -### Return type - -void (empty response body) - -### Authorization - -No authorization required - -### HTTP request headers - - - **Content-Type**: application/json, */ =end));(phpinfo( - - **Accept**: application/json, */ end - -[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) - # **test_endpoint_parameters** > test_endpoint_parameters(number, double, string, byte, integer=integer, int32=int32, int64=int64, float=float, binary=binary, date=date, date_time=date_time, password=password) diff --git a/samples/client/petstore/python/docs/MapTest.md b/samples/client/petstore/python/docs/MapTest.md index 3e71b5130d7..63cdab0374a 100644 --- a/samples/client/petstore/python/docs/MapTest.md +++ b/samples/client/petstore/python/docs/MapTest.md @@ -4,7 +4,6 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **map_map_of_string** | [**dict(str, dict(str, str))**](dict.md) | | [optional] -**map_map_of_enum** | [**dict(str, dict(str, str))**](dict.md) | | [optional] **map_of_enum_string** | **dict(str, str)** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/client/petstore/python/petstore_api/apis/fake_api.py b/samples/client/petstore/python/petstore_api/apis/fake_api.py index df4838bde82..5e8fc3d1195 100644 --- a/samples/client/petstore/python/petstore_api/apis/fake_api.py +++ b/samples/client/petstore/python/petstore_api/apis/fake_api.py @@ -51,107 +51,6 @@ class FakeApi(object): config.api_client = ApiClient() self.api_client = config.api_client - def test_code_inject__end(self, **kwargs): - """ - To test code injection */ =end - - - This method makes a synchronous HTTP request by default. To make an - asynchronous HTTP request, please define a `callback` function - to be invoked when receiving the response. - >>> def callback_function(response): - >>> pprint(response) - >>> - >>> thread = api.test_code_inject__end(callback=callback_function) - - :param callback function: The callback function - for asynchronous request. (optional) - :param str test_code_inject__end: To test code injection */ =end - :return: None - If the method is called asynchronously, - returns the request thread. - """ - kwargs['_return_http_data_only'] = True - if kwargs.get('callback'): - return self.test_code_inject__end_with_http_info(**kwargs) - else: - (data) = self.test_code_inject__end_with_http_info(**kwargs) - return data - - def test_code_inject__end_with_http_info(self, **kwargs): - """ - To test code injection */ =end - - - This method makes a synchronous HTTP request by default. To make an - asynchronous HTTP request, please define a `callback` function - to be invoked when receiving the response. - >>> def callback_function(response): - >>> pprint(response) - >>> - >>> thread = api.test_code_inject__end_with_http_info(callback=callback_function) - - :param callback function: The callback function - for asynchronous request. (optional) - :param str test_code_inject__end: To test code injection */ =end - :return: None - If the method is called asynchronously, - returns the request thread. - """ - - all_params = ['test_code_inject__end'] - all_params.append('callback') - all_params.append('_return_http_data_only') - - params = locals() - for key, val in iteritems(params['kwargs']): - if key not in all_params: - raise TypeError( - "Got an unexpected keyword argument '%s'" - " to method test_code_inject__end" % key - ) - params[key] = val - del params['kwargs'] - - resource_path = '/fake'.replace('{format}', 'json') - path_params = {} - - query_params = {} - - header_params = {} - - form_params = [] - local_var_files = {} - if 'test_code_inject__end' in params: - form_params.append(('test code inject */ =end', params['test_code_inject__end'])) - - body_params = None - - # HTTP header `Accept` - header_params['Accept'] = self.api_client.\ - select_header_accept(['application/json', '*/ end']) - if not header_params['Accept']: - del header_params['Accept'] - - # HTTP header `Content-Type` - header_params['Content-Type'] = self.api_client.\ - select_header_content_type(['application/json', '*/ =end));(phpinfo(']) - - # Authentication setting - auth_settings = [] - - return self.api_client.call_api(resource_path, 'PUT', - path_params, - query_params, - header_params, - body=body_params, - post_params=form_params, - files=local_var_files, - response_type=None, - auth_settings=auth_settings, - callback=params.get('callback'), - _return_http_data_only=params.get('_return_http_data_only')) - def test_endpoint_parameters(self, number, double, string, byte, **kwargs): """ Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 diff --git a/samples/client/petstore/python/petstore_api/configuration.py b/samples/client/petstore/python/petstore_api/configuration.py index 45cfef15472..4515b3a7466 100644 --- a/samples/client/petstore/python/petstore_api/configuration.py +++ b/samples/client/petstore/python/petstore_api/configuration.py @@ -221,13 +221,6 @@ class Configuration(object): :return: The Auth Settings information dict. """ return { - 'api_key': - { - 'type': 'api_key', - 'in': 'header', - 'key': 'api_key', - 'value': self.get_api_key_with_prefix('api_key') - }, 'petstore_auth': { @@ -236,6 +229,13 @@ class Configuration(object): 'key': 'Authorization', 'value': 'Bearer ' + self.access_token }, + 'api_key': + { + 'type': 'api_key', + 'in': 'header', + 'key': 'api_key', + 'value': self.get_api_key_with_prefix('api_key') + }, } diff --git a/samples/client/petstore/python/petstore_api/models/array_test.py b/samples/client/petstore/python/petstore_api/models/array_test.py index 5a6813b60eb..a8e15c0207e 100644 --- a/samples/client/petstore/python/petstore_api/models/array_test.py +++ b/samples/client/petstore/python/petstore_api/models/array_test.py @@ -32,7 +32,7 @@ class ArrayTest(object): NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. """ - def __init__(self, array_of_string=None, array_array_of_integer=None, array_array_of_model=None, array_of_enum=None): + def __init__(self, array_of_string=None, array_array_of_integer=None, array_array_of_model=None): """ ArrayTest - a model defined in Swagger @@ -44,21 +44,18 @@ class ArrayTest(object): self.swagger_types = { 'array_of_string': 'list[str]', 'array_array_of_integer': 'list[list[int]]', - 'array_array_of_model': 'list[list[ReadOnlyFirst]]', - 'array_of_enum': 'list[str]' + 'array_array_of_model': 'list[list[ReadOnlyFirst]]' } self.attribute_map = { 'array_of_string': 'array_of_string', 'array_array_of_integer': 'array_array_of_integer', - 'array_array_of_model': 'array_array_of_model', - 'array_of_enum': 'array_of_enum' + 'array_array_of_model': 'array_array_of_model' } self._array_of_string = array_of_string self._array_array_of_integer = array_array_of_integer self._array_array_of_model = array_array_of_model - self._array_of_enum = array_of_enum @property def array_of_string(self): @@ -129,35 +126,6 @@ class ArrayTest(object): self._array_array_of_model = array_array_of_model - @property - def array_of_enum(self): - """ - Gets the array_of_enum of this ArrayTest. - - - :return: The array_of_enum of this ArrayTest. - :rtype: list[str] - """ - return self._array_of_enum - - @array_of_enum.setter - def array_of_enum(self, array_of_enum): - """ - Sets the array_of_enum of this ArrayTest. - - - :param array_of_enum: The array_of_enum of this ArrayTest. - :type: list[str] - """ - allowed_values = [] - if array_of_enum not in allowed_values: - raise ValueError( - "Invalid value for `array_of_enum`, must be one of {0}" - .format(allowed_values) - ) - - self._array_of_enum = array_of_enum - def to_dict(self): """ Returns the model properties as a dict diff --git a/samples/client/petstore/python/petstore_api/models/map_test.py b/samples/client/petstore/python/petstore_api/models/map_test.py index e48a39d49e6..92c86e55702 100644 --- a/samples/client/petstore/python/petstore_api/models/map_test.py +++ b/samples/client/petstore/python/petstore_api/models/map_test.py @@ -32,7 +32,7 @@ class MapTest(object): NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. """ - def __init__(self, map_map_of_string=None, map_map_of_enum=None, map_of_enum_string=None): + def __init__(self, map_map_of_string=None, map_of_enum_string=None): """ MapTest - a model defined in Swagger @@ -43,18 +43,15 @@ class MapTest(object): """ self.swagger_types = { 'map_map_of_string': 'dict(str, dict(str, str))', - 'map_map_of_enum': 'dict(str, dict(str, str))', 'map_of_enum_string': 'dict(str, str)' } self.attribute_map = { 'map_map_of_string': 'map_map_of_string', - 'map_map_of_enum': 'map_map_of_enum', 'map_of_enum_string': 'map_of_enum_string' } self._map_map_of_string = map_map_of_string - self._map_map_of_enum = map_map_of_enum self._map_of_enum_string = map_of_enum_string @property @@ -80,35 +77,6 @@ class MapTest(object): self._map_map_of_string = map_map_of_string - @property - def map_map_of_enum(self): - """ - Gets the map_map_of_enum of this MapTest. - - - :return: The map_map_of_enum of this MapTest. - :rtype: dict(str, dict(str, str)) - """ - return self._map_map_of_enum - - @map_map_of_enum.setter - def map_map_of_enum(self, map_map_of_enum): - """ - Sets the map_map_of_enum of this MapTest. - - - :param map_map_of_enum: The map_map_of_enum of this MapTest. - :type: dict(str, dict(str, str)) - """ - allowed_values = [] - if map_map_of_enum not in allowed_values: - raise ValueError( - "Invalid value for `map_map_of_enum`, must be one of {0}" - .format(allowed_values) - ) - - self._map_map_of_enum = map_map_of_enum - @property def map_of_enum_string(self): """ diff --git a/samples/client/petstore/python/petstore_api/rest.py b/samples/client/petstore/python/petstore_api/rest.py index c42861d0581..632bba2055e 100644 --- a/samples/client/petstore/python/petstore_api/rest.py +++ b/samples/client/petstore/python/petstore_api/rest.py @@ -30,6 +30,7 @@ import json import ssl import certifi import logging +import re # python 2 and python 3 compatibility library from six import iteritems @@ -141,7 +142,7 @@ class RESTClientObject(object): if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']: if query_params: url += '?' + urlencode(query_params) - if headers['Content-Type'] == 'application/json': + if re.search('json', headers['Content-Type'], re.IGNORECASE): request_body = None if body: request_body = json.dumps(body)