Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/resources/python/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class {{classname}}(object):

queryParams = {}
headerParams = {}
formParams = {}
bodyParam = None

{{#queryParams}}
if ('{{paramName}}' in params):
Expand All @@ -76,7 +78,19 @@ class {{classname}}(object):
replacement)
{{/pathParams}}

postData = (params['body'] if 'body' in params else None)
{{#formParams}}
if ('{{paramName}}' in params):
formParams['{{paramName}}'] = params['{{paramName}}']
{{/formParams}}
if formParams:
headerParams['Content-type'] = 'application/x-www-form-urlencoded'

{{#bodyParam}}
if ('{{paramName}}' in params):
bodyParam = params['{{paramName}}']
{{/bodyParam}}

postData = (formParams if formParams else bodyParam)

response = self.apiClient.callAPI(resourcePath, method, queryParams,
postData, headerParams)
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/python/swagger.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ class ApiClient:
elif method in ['POST', 'PUT', 'DELETE']:

if postData:
headers['Content-type'] = 'application/json'
data = self.sanitizeForSerialization(postData)
data = json.dumps(data)
if 'Content-type' not in headers:
headers['Content-type'] = 'application/json'
data = json.dumps(data)
else:
data = urllib.urlencode(data)

else:
raise Exception('Method ' + method + ' is not recognized.')
Expand Down