Skip to content

Commit 245ce64

Browse files
committed
add test cases for ApiClient.select_header_accept and
ApiClient.select_header_content_type of python client.
1 parent bc9abce commit 245ce64

File tree

7 files changed

+144
-86
lines changed

7 files changed

+144
-86
lines changed

modules/swagger-codegen/src/main/resources/python/api.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ class {{classname}}(object):
7171
body_params = {{#bodyParam}}params.get('{{paramName}}'){{/bodyParam}}{{^bodyParam}}None{{/bodyParam}}
7272

7373
# HTTP header `Accept`
74-
accepts = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]
75-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
74+
header_params['Accept'] = ApiClient.select_header_accept([{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}])
75+
if not header_params['Accept']:
76+
del header_params['Accept']
7677

7778
# HTTP header `Content-Type`
78-
content_types = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]
79-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
79+
header_params['Content-Type'] = ApiClient.select_header_content_type([{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}])
8080

8181
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
8282
body=body_params, post_params=form_params, files=files,

modules/swagger-codegen/src/main/resources/python/swagger.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class ApiClient(object):
259259
Return `Accept` based on an array of accepts provided
260260
"""
261261
if not accepts:
262-
return 'application/json'
262+
return
263263
if 'application/json'.lower() in accepts:
264264
return 'application/json'
265265
else:

samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/pet_api.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def update_pet(self, **kwargs):
6666
body_params = params.get('body')
6767

6868
# HTTP header `Accept`
69-
accepts = ['application/json', 'application/xml']
70-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
69+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
70+
if not header_params['Accept']:
71+
del header_params['Accept']
7172

7273
# HTTP header `Content-Type`
73-
content_types = ['application/json', 'application/xml']
74-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
74+
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml'])
7575

7676
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
7777
body=body_params, post_params=form_params, files=files,
@@ -107,12 +107,12 @@ def add_pet(self, **kwargs):
107107
body_params = params.get('body')
108108

109109
# HTTP header `Accept`
110-
accepts = ['application/json', 'application/xml']
111-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
110+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
111+
if not header_params['Accept']:
112+
del header_params['Accept']
112113

113114
# HTTP header `Content-Type`
114-
content_types = ['application/json', 'application/xml']
115-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
115+
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/json', 'application/xml'])
116116

117117
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
118118
body=body_params, post_params=form_params, files=files,
@@ -148,12 +148,12 @@ def find_pets_by_status(self, **kwargs):
148148
body_params = None
149149

150150
# HTTP header `Accept`
151-
accepts = ['application/json', 'application/xml']
152-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
151+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
152+
if not header_params['Accept']:
153+
del header_params['Accept']
153154

154155
# HTTP header `Content-Type`
155-
content_types = []
156-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
156+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
157157

158158
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
159159
body=body_params, post_params=form_params, files=files,
@@ -191,12 +191,12 @@ def find_pets_by_tags(self, **kwargs):
191191
body_params = None
192192

193193
# HTTP header `Accept`
194-
accepts = ['application/json', 'application/xml']
195-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
194+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
195+
if not header_params['Accept']:
196+
del header_params['Accept']
196197

197198
# HTTP header `Content-Type`
198-
content_types = []
199-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
199+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
200200

201201
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
202202
body=body_params, post_params=form_params, files=files,
@@ -238,12 +238,12 @@ def get_pet_by_id(self, pet_id, **kwargs):
238238
body_params = None
239239

240240
# HTTP header `Accept`
241-
accepts = ['application/json', 'application/xml']
242-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
241+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
242+
if not header_params['Accept']:
243+
del header_params['Accept']
243244

244245
# HTTP header `Content-Type`
245-
content_types = []
246-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
246+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
247247

248248
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
249249
body=body_params, post_params=form_params, files=files,
@@ -287,12 +287,12 @@ def update_pet_with_form(self, pet_id, **kwargs):
287287
body_params = None
288288

289289
# HTTP header `Accept`
290-
accepts = ['application/json', 'application/xml']
291-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
290+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
291+
if not header_params['Accept']:
292+
del header_params['Accept']
292293

293294
# HTTP header `Content-Type`
294-
content_types = ['application/x-www-form-urlencoded']
295-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
295+
header_params['Content-Type'] = ApiClient.select_header_content_type(['application/x-www-form-urlencoded'])
296296

297297
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
298298
body=body_params, post_params=form_params, files=files,
@@ -333,12 +333,12 @@ def delete_pet(self, pet_id, **kwargs):
333333
body_params = None
334334

335335
# HTTP header `Accept`
336-
accepts = ['application/json', 'application/xml']
337-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
336+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
337+
if not header_params['Accept']:
338+
del header_params['Accept']
338339

339340
# HTTP header `Content-Type`
340-
content_types = []
341-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
341+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
342342

343343
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
344344
body=body_params, post_params=form_params, files=files,
@@ -380,12 +380,12 @@ def upload_file(self, pet_id, **kwargs):
380380
body_params = None
381381

382382
# HTTP header `Accept`
383-
accepts = ['application/json', 'application/xml']
384-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
383+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
384+
if not header_params['Accept']:
385+
del header_params['Accept']
385386

386387
# HTTP header `Content-Type`
387-
content_types = ['multipart/form-data']
388-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
388+
header_params['Content-Type'] = ApiClient.select_header_content_type(['multipart/form-data'])
389389

390390
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
391391
body=body_params, post_params=form_params, files=files,

samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/store_api.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ def get_inventory(self, **kwargs):
6565
body_params = None
6666

6767
# HTTP header `Accept`
68-
accepts = ['application/json', 'application/xml']
69-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
68+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
69+
if not header_params['Accept']:
70+
del header_params['Accept']
7071

7172
# HTTP header `Content-Type`
72-
content_types = []
73-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
73+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
7474

7575
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
7676
body=body_params, post_params=form_params, files=files,
@@ -108,12 +108,12 @@ def place_order(self, **kwargs):
108108
body_params = params.get('body')
109109

110110
# HTTP header `Accept`
111-
accepts = ['application/json', 'application/xml']
112-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
111+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
112+
if not header_params['Accept']:
113+
del header_params['Accept']
113114

114115
# HTTP header `Content-Type`
115-
content_types = []
116-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
116+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
117117

118118
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
119119
body=body_params, post_params=form_params, files=files,
@@ -155,12 +155,12 @@ def get_order_by_id(self, order_id, **kwargs):
155155
body_params = None
156156

157157
# HTTP header `Accept`
158-
accepts = ['application/json', 'application/xml']
159-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
158+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
159+
if not header_params['Accept']:
160+
del header_params['Accept']
160161

161162
# HTTP header `Content-Type`
162-
content_types = []
163-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
163+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
164164

165165
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
166166
body=body_params, post_params=form_params, files=files,
@@ -202,12 +202,12 @@ def delete_order(self, order_id, **kwargs):
202202
body_params = None
203203

204204
# HTTP header `Accept`
205-
accepts = ['application/json', 'application/xml']
206-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
205+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
206+
if not header_params['Accept']:
207+
del header_params['Accept']
207208

208209
# HTTP header `Content-Type`
209-
content_types = []
210-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
210+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
211211

212212
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
213213
body=body_params, post_params=form_params, files=files,

samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/apis/user_api.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def create_user(self, **kwargs):
6666
body_params = params.get('body')
6767

6868
# HTTP header `Accept`
69-
accepts = ['application/json', 'application/xml']
70-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
69+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
70+
if not header_params['Accept']:
71+
del header_params['Accept']
7172

7273
# HTTP header `Content-Type`
73-
content_types = []
74-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
74+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
7575

7676
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
7777
body=body_params, post_params=form_params, files=files,
@@ -107,12 +107,12 @@ def create_users_with_array_input(self, **kwargs):
107107
body_params = params.get('body')
108108

109109
# HTTP header `Accept`
110-
accepts = ['application/json', 'application/xml']
111-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
110+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
111+
if not header_params['Accept']:
112+
del header_params['Accept']
112113

113114
# HTTP header `Content-Type`
114-
content_types = []
115-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
115+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
116116

117117
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
118118
body=body_params, post_params=form_params, files=files,
@@ -148,12 +148,12 @@ def create_users_with_list_input(self, **kwargs):
148148
body_params = params.get('body')
149149

150150
# HTTP header `Accept`
151-
accepts = ['application/json', 'application/xml']
152-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
151+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
152+
if not header_params['Accept']:
153+
del header_params['Accept']
153154

154155
# HTTP header `Content-Type`
155-
content_types = []
156-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
156+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
157157

158158
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
159159
body=body_params, post_params=form_params, files=files,
@@ -190,12 +190,12 @@ def login_user(self, **kwargs):
190190
body_params = None
191191

192192
# HTTP header `Accept`
193-
accepts = ['application/json', 'application/xml']
194-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
193+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
194+
if not header_params['Accept']:
195+
del header_params['Accept']
195196

196197
# HTTP header `Content-Type`
197-
content_types = []
198-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
198+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
199199

200200
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
201201
body=body_params, post_params=form_params, files=files,
@@ -232,12 +232,12 @@ def logout_user(self, **kwargs):
232232
body_params = None
233233

234234
# HTTP header `Accept`
235-
accepts = ['application/json', 'application/xml']
236-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
235+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
236+
if not header_params['Accept']:
237+
del header_params['Accept']
237238

238239
# HTTP header `Content-Type`
239-
content_types = []
240-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
240+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
241241

242242
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
243243
body=body_params, post_params=form_params, files=files,
@@ -277,12 +277,12 @@ def get_user_by_name(self, username, **kwargs):
277277
body_params = None
278278

279279
# HTTP header `Accept`
280-
accepts = ['application/json', 'application/xml']
281-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
280+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
281+
if not header_params['Accept']:
282+
del header_params['Accept']
282283

283284
# HTTP header `Content-Type`
284-
content_types = []
285-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
285+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
286286

287287
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
288288
body=body_params, post_params=form_params, files=files,
@@ -325,12 +325,12 @@ def update_user(self, username, **kwargs):
325325
body_params = params.get('body')
326326

327327
# HTTP header `Accept`
328-
accepts = ['application/json', 'application/xml']
329-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
328+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
329+
if not header_params['Accept']:
330+
del header_params['Accept']
330331

331332
# HTTP header `Content-Type`
332-
content_types = []
333-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
333+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
334334

335335
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
336336
body=body_params, post_params=form_params, files=files,
@@ -370,12 +370,12 @@ def delete_user(self, username, **kwargs):
370370
body_params = None
371371

372372
# HTTP header `Accept`
373-
accepts = ['application/json', 'application/xml']
374-
header_params['Accept'] = ApiClient.select_header_accept(accepts)
373+
header_params['Accept'] = ApiClient.select_header_accept(['application/json', 'application/xml'])
374+
if not header_params['Accept']:
375+
del header_params['Accept']
375376

376377
# HTTP header `Content-Type`
377-
content_types = []
378-
header_params['Content-Type'] = ApiClient.select_header_content_type(content_types)
378+
header_params['Content-Type'] = ApiClient.select_header_content_type([])
379379

380380
response = self.api_client.call_api(resource_path, method, path_params, query_params, header_params,
381381
body=body_params, post_params=form_params, files=files,

samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/swagger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def select_header_accept(accepts):
259259
Return `Accept` based on an array of accepts provided
260260
"""
261261
if not accepts:
262-
return 'application/json'
262+
return
263263
if 'application/json'.lower() in accepts:
264264
return 'application/json'
265265
else:

0 commit comments

Comments
 (0)