From d7aaaea0df842c9da2d7b3e8aca287c1aadde2c2 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Wed, 27 May 2015 18:37:34 +0800 Subject: [PATCH] updated config.py of python client. --- .../src/main/resources/python/config.mustache | 8 +++++--- .../src/main/resources/python/swagger.mustache | 2 +- .../SwaggerPetstore-python/SwaggerPetstore/config.py | 8 +++++--- .../SwaggerPetstore-python/SwaggerPetstore/swagger.py | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/config.mustache b/modules/swagger-codegen/src/main/resources/python/config.mustache index a6de7299cb..5fb2db2832 100644 --- a/modules/swagger-codegen/src/main/resources/python/config.mustache +++ b/modules/swagger-codegen/src/main/resources/python/config.mustache @@ -1,20 +1,22 @@ import base64 +import urllib3 def get_api_key_with_prefix(key): global api_key global api_key_prefix - if api_key_prefix[key]: + if api_key.get(key) and api_key_prefix.get(key): return api_key_prefix[key] + ' ' + api_key[key] - else: + elif api_key.get(key): return api_key[key] def get_basic_auth_token(): global username global password - return base64.base64encode('Basic ' + username + password) + if username and password: + return urllib3.util.make_headers(basic_auth=username + ':' + password).get('authorization') def auth_settings(): return { {{#authMethods}}{{#isApiKey}} diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index bd47882043..f01192dd46 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -87,7 +87,7 @@ class ApiClient(object): post_params = self.sanitize_for_serialization(post_params) # auth setting - self.update_params_for_auth(header_params, query_params, auth_settings) + self.update_params_for_auth(headers, query_params, auth_settings) # body if body: diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/config.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/config.py index edcee6fe90..ec3dbe8efb 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/config.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/config.py @@ -1,20 +1,22 @@ import base64 +import urllib3 def get_api_key_with_prefix(key): global api_key global api_key_prefix - if api_key_prefix[key]: + if api_key.get(key) and api_key_prefix.get(key): return api_key_prefix[key] + ' ' + api_key[key] - else: + elif api_key.get(key): return api_key[key] def get_basic_auth_token(): global username global password - return base64.base64encode('Basic ' + username + password) + if username and password: + return urllib3.util.make_headers(basic_auth=username + ':' + password).get('authorization') def auth_settings(): return { diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py index bd47882043..f01192dd46 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py @@ -87,7 +87,7 @@ class ApiClient(object): post_params = self.sanitize_for_serialization(post_params) # auth setting - self.update_params_for_auth(header_params, query_params, auth_settings) + self.update_params_for_auth(headers, query_params, auth_settings) # body if body: