Skip to content

Commit 53f1094

Browse files
authored
[Python] Allow Overriding Accept Header (#19025)
* [Python] Allow Overriding Accept Header * generate samples * add tests
1 parent 44e9ff5 commit 53f1094

31 files changed

Lines changed: 779 additions & 619 deletions

File tree

modules/openapi-generator/src/main/resources/python/api.mustache

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,12 @@ class {{classname}}:
186186

187187
{{#hasProduces}}
188188
# set the HTTP header `Accept`
189-
_header_params['Accept'] = self.api_client.select_header_accept(
190-
[{{#produces}}
191-
'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}
192-
]
193-
)
189+
if 'Accept' not in _header_params:
190+
_header_params['Accept'] = self.api_client.select_header_accept(
191+
[{{#produces}}
192+
'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}
193+
]
194+
)
194195
{{/hasProduces}}
195196

196197
{{#hasConsumes}}

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/auth_api.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,12 @@ def _test_auth_http_basic_serialize(
250250

251251

252252
# set the HTTP header `Accept`
253-
_header_params['Accept'] = self.api_client.select_header_accept(
254-
[
255-
'text/plain'
256-
]
257-
)
253+
if 'Accept' not in _header_params:
254+
_header_params['Accept'] = self.api_client.select_header_accept(
255+
[
256+
'text/plain'
257+
]
258+
)
258259

259260

260261
# authentication setting
@@ -493,11 +494,12 @@ def _test_auth_http_bearer_serialize(
493494

494495

495496
# set the HTTP header `Accept`
496-
_header_params['Accept'] = self.api_client.select_header_accept(
497-
[
498-
'text/plain'
499-
]
500-
)
497+
if 'Accept' not in _header_params:
498+
_header_params['Accept'] = self.api_client.select_header_accept(
499+
[
500+
'text/plain'
501+
]
502+
)
501503

502504

503505
# authentication setting

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/body_api.py

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,12 @@ def _test_binary_gif_serialize(
255255

256256

257257
# set the HTTP header `Accept`
258-
_header_params['Accept'] = self.api_client.select_header_accept(
259-
[
260-
'image/gif'
261-
]
262-
)
258+
if 'Accept' not in _header_params:
259+
_header_params['Accept'] = self.api_client.select_header_accept(
260+
[
261+
'image/gif'
262+
]
263+
)
263264

264265

265266
# authentication setting
@@ -517,11 +518,12 @@ def _test_body_application_octetstream_binary_serialize(
517518

518519

519520
# set the HTTP header `Accept`
520-
_header_params['Accept'] = self.api_client.select_header_accept(
521-
[
522-
'text/plain'
523-
]
524-
)
521+
if 'Accept' not in _header_params:
522+
_header_params['Accept'] = self.api_client.select_header_accept(
523+
[
524+
'text/plain'
525+
]
526+
)
525527

526528
# set the HTTP header `Content-Type`
527529
if _content_type:
@@ -788,11 +790,12 @@ def _test_body_multipart_formdata_array_of_binary_serialize(
788790

789791

790792
# set the HTTP header `Accept`
791-
_header_params['Accept'] = self.api_client.select_header_accept(
792-
[
793-
'text/plain'
794-
]
795-
)
793+
if 'Accept' not in _header_params:
794+
_header_params['Accept'] = self.api_client.select_header_accept(
795+
[
796+
'text/plain'
797+
]
798+
)
796799

797800
# set the HTTP header `Content-Type`
798801
if _content_type:
@@ -1058,11 +1061,12 @@ def _test_body_multipart_formdata_single_binary_serialize(
10581061

10591062

10601063
# set the HTTP header `Accept`
1061-
_header_params['Accept'] = self.api_client.select_header_accept(
1062-
[
1063-
'text/plain'
1064-
]
1065-
)
1064+
if 'Accept' not in _header_params:
1065+
_header_params['Accept'] = self.api_client.select_header_accept(
1066+
[
1067+
'text/plain'
1068+
]
1069+
)
10661070

10671071
# set the HTTP header `Content-Type`
10681072
if _content_type:
@@ -1328,11 +1332,12 @@ def _test_echo_body_all_of_pet_serialize(
13281332

13291333

13301334
# set the HTTP header `Accept`
1331-
_header_params['Accept'] = self.api_client.select_header_accept(
1332-
[
1333-
'application/json'
1334-
]
1335-
)
1335+
if 'Accept' not in _header_params:
1336+
_header_params['Accept'] = self.api_client.select_header_accept(
1337+
[
1338+
'application/json'
1339+
]
1340+
)
13361341

13371342
# set the HTTP header `Content-Type`
13381343
if _content_type:
@@ -1598,11 +1603,12 @@ def _test_echo_body_free_form_object_response_string_serialize(
15981603

15991604

16001605
# set the HTTP header `Accept`
1601-
_header_params['Accept'] = self.api_client.select_header_accept(
1602-
[
1603-
'text/plain'
1604-
]
1605-
)
1606+
if 'Accept' not in _header_params:
1607+
_header_params['Accept'] = self.api_client.select_header_accept(
1608+
[
1609+
'text/plain'
1610+
]
1611+
)
16061612

16071613
# set the HTTP header `Content-Type`
16081614
if _content_type:
@@ -1868,11 +1874,12 @@ def _test_echo_body_pet_serialize(
18681874

18691875

18701876
# set the HTTP header `Accept`
1871-
_header_params['Accept'] = self.api_client.select_header_accept(
1872-
[
1873-
'application/json'
1874-
]
1875-
)
1877+
if 'Accept' not in _header_params:
1878+
_header_params['Accept'] = self.api_client.select_header_accept(
1879+
[
1880+
'application/json'
1881+
]
1882+
)
18761883

18771884
# set the HTTP header `Content-Type`
18781885
if _content_type:
@@ -2138,11 +2145,12 @@ def _test_echo_body_pet_response_string_serialize(
21382145

21392146

21402147
# set the HTTP header `Accept`
2141-
_header_params['Accept'] = self.api_client.select_header_accept(
2142-
[
2143-
'text/plain'
2144-
]
2145-
)
2148+
if 'Accept' not in _header_params:
2149+
_header_params['Accept'] = self.api_client.select_header_accept(
2150+
[
2151+
'text/plain'
2152+
]
2153+
)
21462154

21472155
# set the HTTP header `Content-Type`
21482156
if _content_type:
@@ -2408,11 +2416,12 @@ def _test_echo_body_string_enum_serialize(
24082416

24092417

24102418
# set the HTTP header `Accept`
2411-
_header_params['Accept'] = self.api_client.select_header_accept(
2412-
[
2413-
'application/json'
2414-
]
2415-
)
2419+
if 'Accept' not in _header_params:
2420+
_header_params['Accept'] = self.api_client.select_header_accept(
2421+
[
2422+
'application/json'
2423+
]
2424+
)
24162425

24172426
# set the HTTP header `Content-Type`
24182427
if _content_type:
@@ -2678,11 +2687,12 @@ def _test_echo_body_tag_response_string_serialize(
26782687

26792688

26802689
# set the HTTP header `Accept`
2681-
_header_params['Accept'] = self.api_client.select_header_accept(
2682-
[
2683-
'text/plain'
2684-
]
2685-
)
2690+
if 'Accept' not in _header_params:
2691+
_header_params['Accept'] = self.api_client.select_header_accept(
2692+
[
2693+
'text/plain'
2694+
]
2695+
)
26862696

26872697
# set the HTTP header `Content-Type`
26882698
if _content_type:

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/form_api.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,12 @@ def _test_form_integer_boolean_string_serialize(
297297

298298

299299
# set the HTTP header `Accept`
300-
_header_params['Accept'] = self.api_client.select_header_accept(
301-
[
302-
'text/plain'
303-
]
304-
)
300+
if 'Accept' not in _header_params:
301+
_header_params['Accept'] = self.api_client.select_header_accept(
302+
[
303+
'text/plain'
304+
]
305+
)
305306

306307
# set the HTTP header `Content-Type`
307308
if _content_type:
@@ -567,11 +568,12 @@ def _test_form_object_multipart_serialize(
567568

568569

569570
# set the HTTP header `Accept`
570-
_header_params['Accept'] = self.api_client.select_header_accept(
571-
[
572-
'text/plain'
573-
]
574-
)
571+
if 'Accept' not in _header_params:
572+
_header_params['Accept'] = self.api_client.select_header_accept(
573+
[
574+
'text/plain'
575+
]
576+
)
575577

576578
# set the HTTP header `Content-Type`
577579
if _content_type:
@@ -912,11 +914,12 @@ def _test_form_oneof_serialize(
912914

913915

914916
# set the HTTP header `Accept`
915-
_header_params['Accept'] = self.api_client.select_header_accept(
916-
[
917-
'text/plain'
918-
]
919-
)
917+
if 'Accept' not in _header_params:
918+
_header_params['Accept'] = self.api_client.select_header_accept(
919+
[
920+
'text/plain'
921+
]
922+
)
920923

921924
# set the HTTP header `Content-Type`
922925
if _content_type:

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/header_api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,12 @@ def _test_header_integer_boolean_string_enums_serialize(
327327

328328

329329
# set the HTTP header `Accept`
330-
_header_params['Accept'] = self.api_client.select_header_accept(
331-
[
332-
'text/plain'
333-
]
334-
)
330+
if 'Accept' not in _header_params:
331+
_header_params['Accept'] = self.api_client.select_header_accept(
332+
[
333+
'text/plain'
334+
]
335+
)
335336

336337

337338
# authentication setting

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api/path_api.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,12 @@ def _tests_path_string_path_string_integer_path_integer_enum_nonref_string_path_
311311

312312

313313
# set the HTTP header `Accept`
314-
_header_params['Accept'] = self.api_client.select_header_accept(
315-
[
316-
'text/plain'
317-
]
318-
)
314+
if 'Accept' not in _header_params:
315+
_header_params['Accept'] = self.api_client.select_header_accept(
316+
[
317+
'text/plain'
318+
]
319+
)
319320

320321

321322
# authentication setting

0 commit comments

Comments
 (0)