Skip to content

Commit ec99bef

Browse files
committed
Merge pull request #266 from FindTheBest/pull_request
Python binding generation pull request
2 parents 2fd29d7 + b8f3201 commit ec99bef

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/main/resources/python/api.mustache

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class {{classname}}(object):
5858

5959
queryParams = {}
6060
headerParams = {}
61+
formParams = {}
62+
bodyParam = None
6163

6264
{{#queryParams}}
6365
if ('{{paramName}}' in params):
@@ -76,7 +78,19 @@ class {{classname}}(object):
7678
replacement)
7779
{{/pathParams}}
7880

79-
postData = (params['body'] if 'body' in params else None)
81+
{{#formParams}}
82+
if ('{{paramName}}' in params):
83+
formParams['{{paramName}}'] = params['{{paramName}}']
84+
{{/formParams}}
85+
if formParams:
86+
headerParams['Content-type'] = 'application/x-www-form-urlencoded'
87+
88+
{{#bodyParam}}
89+
if ('{{paramName}}' in params):
90+
bodyParam = params['{{paramName}}']
91+
{{/bodyParam}}
92+
93+
postData = (formParams if formParams else bodyParam)
8094

8195
response = self.apiClient.callAPI(resourcePath, method, queryParams,
8296
postData, headerParams)

src/main/resources/python/swagger.mustache

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,12 @@ class ApiClient:
6060
elif method in ['POST', 'PUT', 'DELETE']:
6161

6262
if postData:
63-
headers['Content-type'] = 'application/json'
6463
data = self.sanitizeForSerialization(postData)
65-
data = json.dumps(data)
64+
if 'Content-type' not in headers:
65+
headers['Content-type'] = 'application/json'
66+
data = json.dumps(data)
67+
else:
68+
data = urllib.urlencode(data)
6669

6770
else:
6871
raise Exception('Method ' + method + ' is not recognized.')

0 commit comments

Comments
 (0)