From 10a9d298d74eed082f02180cdd922dddf6888419 Mon Sep 17 00:00:00 2001 From: geekerzp Date: Mon, 13 Apr 2015 17:30:43 +0800 Subject: [PATCH] Fixed request content-type in objc client. In api.mustache the name of content-type is `Content-Type`, but in swagger.mustache the name of content-type is `Content-type`. --- .../src/main/resources/python/api.mustache | 7 ++- .../main/resources/python/swagger.mustache | 8 +-- .../SwaggerPetstore/pet_api.py | 56 +++++++++++++------ .../SwaggerPetstore/store_api.py | 28 +++++++--- .../SwaggerPetstore/swagger.py | 8 +-- .../SwaggerPetstore/user_api.py | 56 +++++++++++++------ 6 files changed, 113 insertions(+), 50 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/python/api.mustache b/modules/swagger-codegen/src/main/resources/python/api.mustache index 658a37f5fa..791d905278 100644 --- a/modules/swagger-codegen/src/main/resources/python/api.mustache +++ b/modules/swagger-codegen/src/main/resources/python/api.mustache @@ -65,8 +65,11 @@ class {{classname}}(object): files = {} bodyParam = None - headerParams['Accept'] = '{{#produces}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/produces}}' - headerParams['Content-Type'] = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}' + accepts = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' {{#queryParams}} if ('{{paramName}}' in params): diff --git a/modules/swagger-codegen/src/main/resources/python/swagger.mustache b/modules/swagger-codegen/src/main/resources/python/swagger.mustache index 018e92536c..53933ba50d 100644 --- a/modules/swagger-codegen/src/main/resources/python/swagger.mustache +++ b/modules/swagger-codegen/src/main/resources/python/swagger.mustache @@ -82,12 +82,12 @@ class ApiClient(object): elif method in ['POST', 'PUT', 'DELETE']: if postData: postData = ApiClient.sanitizeForSerialization(postData) - if 'Content-type' not in headers: - headers['Content-type'] = 'application/json' + if 'Content-Type' not in headers: + headers['Content-Type'] = 'application/json' data = json.dumps(postData) - elif headers['Content-type'] == 'multipart/form-data': + elif headers['Content-Type'] == 'multipart/form-data': data = self.buildMultipartFormData(postData, files) - headers['Content-type'] = 'multipart/form-data; boundary={0}'.format(self.boundary) + headers['Content-Type'] = 'multipart/form-data; boundary={0}'.format(self.boundary) headers['Content-length'] = str(len(data)) else: data = urllib.urlencode(postData) diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py index d0a85e4a69..5a96b4b649 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py @@ -64,8 +64,11 @@ class PetApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = 'application/json,application/xml,' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = ['application/json', 'application/xml', ] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -120,8 +123,11 @@ class PetApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = 'application/json,application/xml,' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = ['application/json', 'application/xml', ] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -176,8 +182,11 @@ class PetApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' if ('status' in params): @@ -238,8 +247,11 @@ class PetApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' if ('tags' in params): @@ -300,8 +312,11 @@ class PetApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -371,8 +386,11 @@ class PetApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = 'application/x-www-form-urlencoded,' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = ['application/x-www-form-urlencoded', ] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -439,8 +457,11 @@ class PetApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -507,8 +528,11 @@ class PetApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = 'multipart/form-data,' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = ['multipart/form-data', ] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py index a7befb9762..49010daf1a 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py @@ -61,8 +61,11 @@ class StoreApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -120,8 +123,11 @@ class StoreApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -182,8 +188,11 @@ class StoreApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -247,8 +256,11 @@ class StoreApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py index 018e92536c..53933ba50d 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py @@ -82,12 +82,12 @@ class ApiClient(object): elif method in ['POST', 'PUT', 'DELETE']: if postData: postData = ApiClient.sanitizeForSerialization(postData) - if 'Content-type' not in headers: - headers['Content-type'] = 'application/json' + if 'Content-Type' not in headers: + headers['Content-Type'] = 'application/json' data = json.dumps(postData) - elif headers['Content-type'] == 'multipart/form-data': + elif headers['Content-Type'] == 'multipart/form-data': data = self.buildMultipartFormData(postData, files) - headers['Content-type'] = 'multipart/form-data; boundary={0}'.format(self.boundary) + headers['Content-Type'] = 'multipart/form-data; boundary={0}'.format(self.boundary) headers['Content-length'] = str(len(data)) else: data = urllib.urlencode(postData) diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py index 432df9bb12..8d6f6670c6 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py @@ -64,8 +64,11 @@ class UserApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -120,8 +123,11 @@ class UserApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -176,8 +182,11 @@ class UserApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -235,8 +244,11 @@ class UserApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' if ('username' in params): @@ -297,8 +309,11 @@ class UserApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -350,8 +365,11 @@ class UserApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -418,8 +436,11 @@ class UserApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json' @@ -480,8 +501,11 @@ class UserApi(object): files = {} bodyParam = None - headerParams['Accept'] = 'application/json,application/xml' - headerParams['Content-Type'] = '' + accepts = ['application/json', 'application/xml'] + headerParams['Accept'] = ', '.join(accepts) + + content_types = [] + headerParams['Content-Type'] = content_types[0] if len(content_types) > 0 else 'application/json'