From 52807c0724f9e879bed3907ca7c962899a5557b8 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 22 May 2015 10:45:38 +0800 Subject: [PATCH 1/5] minor improvement to python client accept and content-type header --- .../src/main/resources/python/api.mustache | 8 ++- .../main/resources/python/swagger.mustache | 25 +++++++- .../SwaggerPetstore/apis/pet_api.py | 57 +++++++++++++------ .../SwaggerPetstore/apis/store_api.py | 26 ++++++--- .../SwaggerPetstore/apis/user_api.py | 50 ++++++++++------ .../SwaggerPetstore/swagger.py | 25 +++++++- 6 files changed, 144 insertions(+), 47 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/api.mustache b/modules/swagger-codegen/src/main/resources/python/api.mustache index b853cbc9c95..eb85a10a203 100644 --- a/modules/swagger-codegen/src/main/resources/python/api.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api.mustache @@ -29,6 +29,8 @@ from six import iteritems from ..util import remove_none +from ..swagger import ApiClient + {{#operations}} class {{classname}}(object): @@ -68,11 +70,13 @@ class {{classname}}(object): files = remove_none(dict({{#formParams}}{{#isFile}}{{baseName}}=params.get('{{paramName}}'){{#hasMore}}, {{/hasMore}}{{/isFile}}{{/formParams}})) body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}} + # HTTP header `Accept` accepts = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index 549106014e3..7b284376a58 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -253,7 +253,28 @@ class ApiClient(object): return params - - + @staticmethod + def select_header_accept(accepts): + """ + Return `Accept` based on an array of accepts provided + """ + if not accepts: + return 'application/json' + if 'application/json'.lower() in accepts: + return 'application/json' + else: + return ', '.join(accepts) + + @staticmethod + def select_header_content_type(content_types): + """ + Return `Content-Type` baseed on an array of content_types provided + """ + if not content_types: + return 'application/json' + if 'application/json'.lower() in content_types: + return 'application/json' + else: + return content_types[0] diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py index bf8a51d7ca2..b06447c8c47 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py @@ -29,6 +29,8 @@ from six import iteritems from ..util import remove_none +from ..swagger import ApiClient + class PetApi(object): def __init__(self, api_client): @@ -63,11 +65,13 @@ class PetApi(object): files = remove_none(dict()) body_params = params.get('body') + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = ['application/json', 'application/xml'] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -102,11 +106,13 @@ class PetApi(object): files = remove_none(dict()) body_params = params.get('body') + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = ['application/json', 'application/xml'] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -141,11 +147,13 @@ class PetApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -182,11 +190,13 @@ class PetApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -227,11 +237,18 @@ class PetApi(object): files = remove_none(dict()) body_params = None - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + # HTTP header `Accept` + accepts = [] + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + + print('-----------------------------') + print('header_params: ', header_params) + print('-----------------------------') + return response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -274,11 +291,13 @@ class PetApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = ['application/x-www-form-urlencoded'] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -318,11 +337,13 @@ class PetApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -363,11 +384,13 @@ class PetApi(object): files = remove_none(dict(file=params.get('file'))) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = ['multipart/form-data'] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py index 0df9a84fe75..19ece346938 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py @@ -29,6 +29,8 @@ from six import iteritems from ..util import remove_none +from ..swagger import ApiClient + class StoreApi(object): def __init__(self, api_client): @@ -62,11 +64,13 @@ class StoreApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -103,11 +107,13 @@ class StoreApi(object): files = remove_none(dict()) body_params = params.get('body') + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -148,11 +154,13 @@ class StoreApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -193,11 +201,13 @@ class StoreApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py index 720843bd508..a705567306a 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py @@ -29,6 +29,8 @@ from six import iteritems from ..util import remove_none +from ..swagger import ApiClient + class UserApi(object): def __init__(self, api_client): @@ -63,11 +65,13 @@ class UserApi(object): files = remove_none(dict()) body_params = params.get('body') + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -102,11 +106,13 @@ class UserApi(object): files = remove_none(dict()) body_params = params.get('body') + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -141,11 +147,13 @@ class UserApi(object): files = remove_none(dict()) body_params = params.get('body') + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -181,11 +189,13 @@ class UserApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -221,11 +231,13 @@ class UserApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -264,11 +276,13 @@ class UserApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -310,11 +324,13 @@ class UserApi(object): files = remove_none(dict()) body_params = params.get('body') + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -353,11 +369,13 @@ class UserApi(object): files = remove_none(dict()) body_params = None + # HTTP header `Accept` accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ', '.join(accepts) + header_params['Accept'] = ApiClient.select_header_accept(accepts) + # HTTP header `Content-Type` content_types = [] - header_params['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' + header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py index 549106014e3..7b284376a58 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py @@ -253,7 +253,28 @@ class ApiClient(object): return params - - + @staticmethod + def select_header_accept(accepts): + """ + Return `Accept` based on an array of accepts provided + """ + if not accepts: + return 'application/json' + if 'application/json'.lower() in accepts: + return 'application/json' + else: + return ', '.join(accepts) + + @staticmethod + def select_header_content_type(content_types): + """ + Return `Content-Type` baseed on an array of content_types provided + """ + if not content_types: + return 'application/json' + if 'application/json'.lower() in content_types: + return 'application/json' + else: + return content_types[0] From 8a311d693bb8a79fc1878c7bb912b97781b4c14b Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 22 May 2015 10:50:11 +0800 Subject: [PATCH 2/5] updated python client samples --- .../python/SwaggerPetstore-python/.coverage | Bin 0 -> 3086 bytes .../SwaggerPetstore.egg-info/PKG-INFO | 12 +++++++++ .../SwaggerPetstore.egg-info/SOURCES.txt | 24 ++++++++++++++++++ .../dependency_links.txt | 1 + .../SwaggerPetstore.egg-info/pbr.json | 1 + .../SwaggerPetstore.egg-info/requires.txt | 2 ++ .../SwaggerPetstore.egg-info/top_level.txt | 2 ++ .../SwaggerPetstore/apis/pet_api.py | 7 +---- .../dev-requirements.txt.log | 5 ++++ 9 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/.coverage create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/PKG-INFO create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/SOURCES.txt create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/dependency_links.txt create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/pbr.json create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/requires.txt create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/top_level.txt create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/dev-requirements.txt.log diff --git a/samples/client/petstore/python/SwaggerPetstore-python/.coverage b/samples/client/petstore/python/SwaggerPetstore-python/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..6a74db3c6e5e88a712dac38a59b3bb7ffb014318 GIT binary patch literal 3086 zcmc(hX>1f_7{`4Ir7gWrdQ*w5Wkriyl;&so-sZ%yS2si^Y+thCfS+)yzlS%|K5?bA(I?> zmM7@3&~8Ma-E)X1YTk(e#K4M>MZe-7362 zq(%DNUaty|UzQ^P>ovDNyvo~u^n-Y;T;^|dg2aJ`p`5)m7N$*I@>U_r%GBcS(~v8 z$KwRF;6$8+lW_`GVii{7RII^zv|=OLunCOQQ604 z$(grc&oRtg2QrX_*~msN@{o@L6v})S+XGOED%8jTSo66UjWVN6GNsKnSj(|Ouu34c zPN3RgLj}R=bb)F!wm`?3*eZA#Hd>uf0+tV^02LLSF2SxOOnY#Jz%-80O#;#w?iPIR z#eKLR4`44I5|kcEg7lP)(lY|n0la8q^a@@TlqNtrBp`i+kMRjUvr+m|V6ss9K|uN$ zzX(XbB~kjzhUpmMbm9!+OyZnzq>62-%4B<{qmf)LU%(f2xvWjfGt7Jk2s4q6S!$X( zd~%=y!z}zSkkFHv@+wSQ%OzlV|^H?6S;*=O>=|r4%r4LL? z9C3w}rpz$sOr%LDcOmL+?KWbGJ=9Ja>*K^2En*96sMkUkF_zlYVHL6SmK$b;18JBc z#3!mL&n~4zB~{3=q008MW#vRAIi-@8+K#i5uM@wu0k+)|RdfbACe_h4+jo}jE)d@- z@m-g=t_LBznj&^N^^5BUumi)mI9XJqQc_n>vYq9++r@QbQcw@trrRfO+b>mg5O3iS z-V>i4R(d?OYdCpKD-E;is4= 1.10 +six >= 1.9 diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/top_level.txt b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/top_level.txt new file mode 100644 index 00000000000..28c004b4315 --- /dev/null +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/top_level.txt @@ -0,0 +1,2 @@ +SwaggerPetstore +tests diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py index b06447c8c47..db12623e75d 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py @@ -238,18 +238,13 @@ class PetApi(object): body_params = None # HTTP header `Accept` - accepts = [] + accepts = ['application/json', 'application/xml'] header_params['Accept'] = ApiClient.select_header_accept(accepts) # HTTP header `Content-Type` content_types = [] header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) - print('-----------------------------') - print('header_params: ', header_params) - print('-----------------------------') - return - response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, response='Pet') diff --git a/samples/client/petstore/python/SwaggerPetstore-python/dev-requirements.txt.log b/samples/client/petstore/python/SwaggerPetstore-python/dev-requirements.txt.log new file mode 100644 index 00000000000..0549f97e65f --- /dev/null +++ b/samples/client/petstore/python/SwaggerPetstore-python/dev-requirements.txt.log @@ -0,0 +1,5 @@ +Requirement already satisfied (use --upgrade to upgrade): nose in /Users/geekerzp/.virtualenvs/python2/lib/python2.7/site-packages (from -r dev-requirements.txt (line 1)) +Requirement already satisfied (use --upgrade to upgrade): tox in /Users/geekerzp/.virtualenvs/python2/lib/python2.7/site-packages (from -r dev-requirements.txt (line 2)) +Requirement already satisfied (use --upgrade to upgrade): coverage in /Users/geekerzp/.virtualenvs/python2/lib/python2.7/site-packages (from -r dev-requirements.txt (line 3)) +Requirement already satisfied (use --upgrade to upgrade): randomize in /Users/geekerzp/.virtualenvs/python2/lib/python2.7/site-packages (from -r dev-requirements.txt (line 4)) +Cleaning up... From bc9abceef3b767249943b7df863c88fb964c27ee Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 22 May 2015 11:12:35 +0800 Subject: [PATCH 3/5] removed temp files from python client --- .../python/SwaggerPetstore-python/.coverage | Bin 3086 -> 0 bytes .../SwaggerPetstore.egg-info/PKG-INFO | 12 --------- .../SwaggerPetstore.egg-info/SOURCES.txt | 24 ------------------ .../dependency_links.txt | 1 - .../SwaggerPetstore.egg-info/pbr.json | 1 - .../SwaggerPetstore.egg-info/requires.txt | 2 -- .../SwaggerPetstore.egg-info/top_level.txt | 2 -- .../dev-requirements.txt.log | 5 ---- 8 files changed, 47 deletions(-) delete mode 100644 samples/client/petstore/python/SwaggerPetstore-python/.coverage delete mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/PKG-INFO delete mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/SOURCES.txt delete mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/dependency_links.txt delete mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/pbr.json delete mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/requires.txt delete mode 100644 samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/top_level.txt delete mode 100644 samples/client/petstore/python/SwaggerPetstore-python/dev-requirements.txt.log diff --git a/samples/client/petstore/python/SwaggerPetstore-python/.coverage b/samples/client/petstore/python/SwaggerPetstore-python/.coverage deleted file mode 100644 index 6a74db3c6e5e88a712dac38a59b3bb7ffb014318..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3086 zcmc(hX>1f_7{`4Ir7gWrdQ*w5Wkriyl;&so-sZ%yS2si^Y+thCfS+)yzlS%|K5?bA(I?> zmM7@3&~8Ma-E)X1YTk(e#K4M>MZe-7362 zq(%DNUaty|UzQ^P>ovDNyvo~u^n-Y;T;^|dg2aJ`p`5)m7N$*I@>U_r%GBcS(~v8 z$KwRF;6$8+lW_`GVii{7RII^zv|=OLunCOQQ604 z$(grc&oRtg2QrX_*~msN@{o@L6v})S+XGOED%8jTSo66UjWVN6GNsKnSj(|Ouu34c zPN3RgLj}R=bb)F!wm`?3*eZA#Hd>uf0+tV^02LLSF2SxOOnY#Jz%-80O#;#w?iPIR z#eKLR4`44I5|kcEg7lP)(lY|n0la8q^a@@TlqNtrBp`i+kMRjUvr+m|V6ss9K|uN$ zzX(XbB~kjzhUpmMbm9!+OyZnzq>62-%4B<{qmf)LU%(f2xvWjfGt7Jk2s4q6S!$X( zd~%=y!z}zSkkFHv@+wSQ%OzlV|^H?6S;*=O>=|r4%r4LL? z9C3w}rpz$sOr%LDcOmL+?KWbGJ=9Ja>*K^2En*96sMkUkF_zlYVHL6SmK$b;18JBc z#3!mL&n~4zB~{3=q008MW#vRAIi-@8+K#i5uM@wu0k+)|RdfbACe_h4+jo}jE)d@- z@m-g=t_LBznj&^N^^5BUumi)mI9XJqQc_n>vYq9++r@QbQcw@trrRfO+b>mg5O3iS z-V>i4R(d?OYdCpKD-E;is4= 1.10 -six >= 1.9 diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/top_level.txt b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/top_level.txt deleted file mode 100644 index 28c004b4315..00000000000 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore.egg-info/top_level.txt +++ /dev/null @@ -1,2 +0,0 @@ -SwaggerPetstore -tests diff --git a/samples/client/petstore/python/SwaggerPetstore-python/dev-requirements.txt.log b/samples/client/petstore/python/SwaggerPetstore-python/dev-requirements.txt.log deleted file mode 100644 index 0549f97e65f..00000000000 --- a/samples/client/petstore/python/SwaggerPetstore-python/dev-requirements.txt.log +++ /dev/null @@ -1,5 +0,0 @@ -Requirement already satisfied (use --upgrade to upgrade): nose in /Users/geekerzp/.virtualenvs/python2/lib/python2.7/site-packages (from -r dev-requirements.txt (line 1)) -Requirement already satisfied (use --upgrade to upgrade): tox in /Users/geekerzp/.virtualenvs/python2/lib/python2.7/site-packages (from -r dev-requirements.txt (line 2)) -Requirement already satisfied (use --upgrade to upgrade): coverage in /Users/geekerzp/.virtualenvs/python2/lib/python2.7/site-packages (from -r dev-requirements.txt (line 3)) -Requirement already satisfied (use --upgrade to upgrade): randomize in /Users/geekerzp/.virtualenvs/python2/lib/python2.7/site-packages (from -r dev-requirements.txt (line 4)) -Cleaning up... From 245ce642cec8d494254fa60f97a6d7bd5bf5cfa0 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 22 May 2015 15:28:36 +0800 Subject: [PATCH 4/5] add test cases for ApiClient.select_header_accept and ApiClient.select_header_content_type of python client. --- .../src/main/resources/python/api.mustache | 8 +-- .../main/resources/python/swagger.mustache | 2 +- .../SwaggerPetstore/apis/pet_api.py | 64 +++++++++---------- .../SwaggerPetstore/apis/store_api.py | 32 +++++----- .../SwaggerPetstore/apis/user_api.py | 64 +++++++++---------- .../SwaggerPetstore/swagger.py | 2 +- .../tests/test_api_client.py | 58 +++++++++++++++++ 7 files changed, 144 insertions(+), 86 deletions(-) create mode 100644 samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py diff --git a/modules/swagger-codegen/src/main/resources/python/api.mustache b/modules/swagger-codegen/src/main/resources/python/api.mustache index eb85a10a203..fc779a66653 100644 --- a/modules/swagger-codegen/src/main/resources/python/api.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api.mustache @@ -71,12 +71,12 @@ class {{classname}}(object): body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}} # HTTP header `Accept` - accepts = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept([{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index 7b284376a58..569f0cd9e8d 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -259,7 +259,7 @@ class ApiClient(object): Return `Accept` based on an array of accepts provided """ if not accepts: - return 'application/json' + return if 'application/json'.lower() in accepts: return 'application/json' else: diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py index db12623e75d..a599aeaabc1 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py @@ -66,12 +66,12 @@ class PetApi(object): body_params = params.get('body') # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = ['application/json', 'application/xml'] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml']) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -107,12 +107,12 @@ class PetApi(object): body_params = params.get('body') # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = ['application/json', 'application/xml'] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml']) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -148,12 +148,12 @@ class PetApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -191,12 +191,12 @@ class PetApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -238,12 +238,12 @@ class PetApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -287,12 +287,12 @@ class PetApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = ['application/x-www-form-urlencoded'] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type(['application/x-www-form-urlencoded']) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -333,12 +333,12 @@ class PetApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -380,12 +380,12 @@ class PetApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = ['multipart/form-data'] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type(['multipart/form-data']) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py index 19ece346938..7f9b852f7ca 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py @@ -65,12 +65,12 @@ class StoreApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -108,12 +108,12 @@ class StoreApi(object): body_params = params.get('body') # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -155,12 +155,12 @@ class StoreApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -202,12 +202,12 @@ class StoreApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py index a705567306a..2471970c436 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py @@ -66,12 +66,12 @@ class UserApi(object): body_params = params.get('body') # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -107,12 +107,12 @@ class UserApi(object): body_params = params.get('body') # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -148,12 +148,12 @@ class UserApi(object): body_params = params.get('body') # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -190,12 +190,12 @@ class UserApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -232,12 +232,12 @@ class UserApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -277,12 +277,12 @@ class UserApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -325,12 +325,12 @@ class UserApi(object): body_params = params.get('body') # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, @@ -370,12 +370,12 @@ class UserApi(object): body_params = None # HTTP header `Accept` - accepts = ['application/json', 'application/xml'] - header_params['Accept'] = ApiClient.select_header_accept(accepts) + header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml']) + if not header_params['Accept']: + del header_params['Accept'] # HTTP header `Content-Type` - content_types = [] - header_params['Content-Type'] = ApiClient.select_header_content_type(content_types) + header_params['Content-Type'] = ApiClient.select_header_content_type([]) response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params, body=body_params, post_params=form_params, files=files, diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py index 7b284376a58..569f0cd9e8d 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py @@ -259,7 +259,7 @@ class ApiClient(object): Return `Accept` based on an array of accepts provided """ if not accepts: - return 'application/json' + return if 'application/json'.lower() in accepts: return 'application/json' else: diff --git a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py new file mode 100644 index 00000000000..437e94d09c6 --- /dev/null +++ b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py @@ -0,0 +1,58 @@ +# coding: utf-8 + +""" +Run the tests. +$ pip install nose (optional) +$ cd SwaggerPetstore-python +$ nosetests -v +""" + +import os +import time +import unittest + +import SwaggerPetstore + +HOST = 'http://petstore.swagger.io/v2' + + +class ApiClientTests(unittest.TestCase): + + def setUp(self): + self.api_client = SwaggerPetstore.ApiClient(HOST) + + def test_select_header_accept(self): + accepts = ['application/json', 'application/xml'] + accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) + self.assertEqual(accept, 'application/json') + + accepts = ['application/xml', 'application/json'] + accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) + self.assertEqual(accept, 'application/json') + + accepts = ['text/plain', 'application/xml'] + accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) + self.assertEqual(accept, 'text/plain, application/xml') + + accepts = [] + accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) + self.assertEqual(accept, None) + + def test_select_header_content_type(self): + content_types = ['application/json', 'application/xml'] + content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) + self.assertEqual(content_type, 'application/json') + + content_types = ['application/xml', 'application/json'] + content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) + self.assertEqual(content_type, 'application/json') + + content_types = ['text/plain', 'application/xml'] + content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) + self.assertEqual(content_type, 'text/plain') + + content_types = [] + content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) + self.assertEqual(content_type, 'application/json') + + From 8d0efd812cbfe088c2a8c47bc7c93263d8ac6aa6 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Fri, 22 May 2015 15:50:09 +0800 Subject: [PATCH 5/5] updated unittests of python client --- .../src/main/resources/python/swagger.mustache | 16 ++++++++++------ .../SwaggerPetstore/swagger.py | 16 ++++++++++------ .../tests/test_api_client.py | 8 ++++++++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index 569f0cd9e8d..ab45eace646 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -105,7 +105,7 @@ class ApiClient(object): def to_path_value(self, obj): """ Convert a string or object to a path-friendly value - + :param obj: object or string value :return string: quoted value @@ -259,8 +259,11 @@ class ApiClient(object): Return `Accept` based on an array of accepts provided """ if not accepts: - return - if 'application/json'.lower() in accepts: + return + + accepts = list(map(lambda x: x.lower(), accepts)) + + if 'application/json' in accepts: return 'application/json' else: return ', '.join(accepts) @@ -272,9 +275,10 @@ class ApiClient(object): """ if not content_types: return 'application/json' - if 'application/json'.lower() in content_types: + + content_types = list(map(lambda x: x.lower(), content_types)) + + if 'application/json' in content_types: return 'application/json' else: return content_types[0] - - diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py index 569f0cd9e8d..ab45eace646 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py @@ -105,7 +105,7 @@ class ApiClient(object): def to_path_value(self, obj): """ Convert a string or object to a path-friendly value - + :param obj: object or string value :return string: quoted value @@ -259,8 +259,11 @@ class ApiClient(object): Return `Accept` based on an array of accepts provided """ if not accepts: - return - if 'application/json'.lower() in accepts: + return + + accepts = list(map(lambda x: x.lower(), accepts)) + + if 'application/json' in accepts: return 'application/json' else: return ', '.join(accepts) @@ -272,9 +275,10 @@ class ApiClient(object): """ if not content_types: return 'application/json' - if 'application/json'.lower() in content_types: + + content_types = list(map(lambda x: x.lower(), content_types)) + + if 'application/json' in content_types: return 'application/json' else: return content_types[0] - - diff --git a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py index 437e94d09c6..9adf7cdb99d 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/tests/test_api_client.py @@ -22,6 +22,10 @@ class ApiClientTests(unittest.TestCase): self.api_client = SwaggerPetstore.ApiClient(HOST) def test_select_header_accept(self): + accepts = ['APPLICATION/JSON', 'APPLICATION/XML'] + accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) + self.assertEqual(accept, 'application/json') + accepts = ['application/json', 'application/xml'] accept = SwaggerPetstore.ApiClient.select_header_accept(accepts) self.assertEqual(accept, 'application/json') @@ -39,6 +43,10 @@ class ApiClientTests(unittest.TestCase): self.assertEqual(accept, None) def test_select_header_content_type(self): + content_types = ['APPLICATION/JSON', 'APPLICATION/XML'] + content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) + self.assertEqual(content_type, 'application/json') + content_types = ['application/json', 'application/xml'] content_type = SwaggerPetstore.ApiClient.select_header_content_type(content_types) self.assertEqual(content_type, 'application/json')