Skip to content

Commit c0bf4fa

Browse files
committed
improve api_client in python client
1 parent 2ee50ce commit c0bf4fa

7 files changed

Lines changed: 28 additions & 28 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class ApiClient:
319319
return_data = self.__deserialize_file(response_data)
320320
elif response_type is not None:
321321
match = None
322-
content_type = response_data.headers.get('content-type')
322+
content_type = response_data.getheader('content-type')
323323
if content_type is not None:
324324
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
325325
encoding = match.group(1) if match else "utf-8"
@@ -336,7 +336,7 @@ class ApiClient:
336336
return ApiResponse(
337337
status_code = response_data.status,
338338
data = return_data,
339-
headers = response_data.headers,
339+
headers = response_data.getheaders(),
340340
raw_data = response_data.data
341341
)
342342

@@ -717,14 +717,14 @@ class ApiClient:
717717
os.close(fd)
718718
os.remove(path)
719719

720-
content_disposition = response.headers.get("Content-Disposition")
720+
content_disposition = response.getheaders("Content-Disposition")
721721
if content_disposition:
722722
m = re.search(
723723
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
724724
content_disposition
725725
)
726726
assert m is not None, "Unexpected 'content-disposition' header value"
727-
filename = m.group(1)
727+
filename = os.path.basename(m.group(1)) # Strip any directory traversal
728728
path = os.path.join(os.path.dirname(path), filename)
729729

730730
with open(path, "wb") as f:

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def response_deserialize(
312312
return_data = self.__deserialize_file(response_data)
313313
elif response_type is not None:
314314
match = None
315-
content_type = response_data.headers.get('content-type')
315+
content_type = response_data.getheader('content-type')
316316
if content_type is not None:
317317
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
318318
encoding = match.group(1) if match else "utf-8"
@@ -329,7 +329,7 @@ def response_deserialize(
329329
return ApiResponse(
330330
status_code = response_data.status,
331331
data = return_data,
332-
headers = response_data.headers,
332+
headers = response_data.getheaders(),
333333
raw_data = response_data.data
334334
)
335335

@@ -701,14 +701,14 @@ def __deserialize_file(self, response):
701701
os.close(fd)
702702
os.remove(path)
703703

704-
content_disposition = response.headers.get("Content-Disposition")
704+
content_disposition = response.getheaders("Content-Disposition")
705705
if content_disposition:
706706
m = re.search(
707707
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
708708
content_disposition
709709
)
710710
assert m is not None, "Unexpected 'content-disposition' header value"
711-
filename = m.group(1)
711+
filename = os.path.basename(m.group(1)) # Strip any directory traversal
712712
path = os.path.join(os.path.dirname(path), filename)
713713

714714
with open(path, "wb") as f:

samples/client/echo_api/python/openapi_client/api_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def response_deserialize(
312312
return_data = self.__deserialize_file(response_data)
313313
elif response_type is not None:
314314
match = None
315-
content_type = response_data.headers.get('content-type')
315+
content_type = response_data.getheader('content-type')
316316
if content_type is not None:
317317
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
318318
encoding = match.group(1) if match else "utf-8"
@@ -329,7 +329,7 @@ def response_deserialize(
329329
return ApiResponse(
330330
status_code = response_data.status,
331331
data = return_data,
332-
headers = response_data.headers,
332+
headers = response_data.getheaders(),
333333
raw_data = response_data.data
334334
)
335335

@@ -701,14 +701,14 @@ def __deserialize_file(self, response):
701701
os.close(fd)
702702
os.remove(path)
703703

704-
content_disposition = response.headers.get("Content-Disposition")
704+
content_disposition = response.getheaders("Content-Disposition")
705705
if content_disposition:
706706
m = re.search(
707707
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
708708
content_disposition
709709
)
710710
assert m is not None, "Unexpected 'content-disposition' header value"
711-
filename = m.group(1)
711+
filename = os.path.basename(m.group(1)) # Strip any directory traversal
712712
path = os.path.join(os.path.dirname(path), filename)
713713

714714
with open(path, "wb") as f:

samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def response_deserialize(
314314
return_data = self.__deserialize_file(response_data)
315315
elif response_type is not None:
316316
match = None
317-
content_type = response_data.headers.get('content-type')
317+
content_type = response_data.getheader('content-type')
318318
if content_type is not None:
319319
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
320320
encoding = match.group(1) if match else "utf-8"
@@ -331,7 +331,7 @@ def response_deserialize(
331331
return ApiResponse(
332332
status_code = response_data.status,
333333
data = return_data,
334-
headers = response_data.headers,
334+
headers = response_data.getheaders(),
335335
raw_data = response_data.data
336336
)
337337

@@ -710,14 +710,14 @@ def __deserialize_file(self, response):
710710
os.close(fd)
711711
os.remove(path)
712712

713-
content_disposition = response.headers.get("Content-Disposition")
713+
content_disposition = response.getheaders("Content-Disposition")
714714
if content_disposition:
715715
m = re.search(
716716
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
717717
content_disposition
718718
)
719719
assert m is not None, "Unexpected 'content-disposition' header value"
720-
filename = m.group(1)
720+
filename = os.path.basename(m.group(1)) # Strip any directory traversal
721721
path = os.path.join(os.path.dirname(path), filename)
722722

723723
with open(path, "wb") as f:

samples/openapi3/client/petstore/python-httpx/petstore_api/api_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def response_deserialize(
314314
return_data = self.__deserialize_file(response_data)
315315
elif response_type is not None:
316316
match = None
317-
content_type = response_data.headers.get('content-type')
317+
content_type = response_data.getheader('content-type')
318318
if content_type is not None:
319319
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
320320
encoding = match.group(1) if match else "utf-8"
@@ -331,7 +331,7 @@ def response_deserialize(
331331
return ApiResponse(
332332
status_code = response_data.status,
333333
data = return_data,
334-
headers = response_data.headers,
334+
headers = response_data.getheaders(),
335335
raw_data = response_data.data
336336
)
337337

@@ -710,14 +710,14 @@ def __deserialize_file(self, response):
710710
os.close(fd)
711711
os.remove(path)
712712

713-
content_disposition = response.headers.get("Content-Disposition")
713+
content_disposition = response.getheaders("Content-Disposition")
714714
if content_disposition:
715715
m = re.search(
716716
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
717717
content_disposition
718718
)
719719
assert m is not None, "Unexpected 'content-disposition' header value"
720-
filename = m.group(1)
720+
filename = os.path.basename(m.group(1)) # Strip any directory traversal
721721
path = os.path.join(os.path.dirname(path), filename)
722722

723723
with open(path, "wb") as f:

samples/openapi3/client/petstore/python-lazyImports/petstore_api/api_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def response_deserialize(
311311
return_data = self.__deserialize_file(response_data)
312312
elif response_type is not None:
313313
match = None
314-
content_type = response_data.headers.get('content-type')
314+
content_type = response_data.getheader('content-type')
315315
if content_type is not None:
316316
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
317317
encoding = match.group(1) if match else "utf-8"
@@ -328,7 +328,7 @@ def response_deserialize(
328328
return ApiResponse(
329329
status_code = response_data.status,
330330
data = return_data,
331-
headers = response_data.headers,
331+
headers = response_data.getheaders(),
332332
raw_data = response_data.data
333333
)
334334

@@ -707,14 +707,14 @@ def __deserialize_file(self, response):
707707
os.close(fd)
708708
os.remove(path)
709709

710-
content_disposition = response.headers.get("Content-Disposition")
710+
content_disposition = response.getheaders("Content-Disposition")
711711
if content_disposition:
712712
m = re.search(
713713
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
714714
content_disposition
715715
)
716716
assert m is not None, "Unexpected 'content-disposition' header value"
717-
filename = m.group(1)
717+
filename = os.path.basename(m.group(1)) # Strip any directory traversal
718718
path = os.path.join(os.path.dirname(path), filename)
719719

720720
with open(path, "wb") as f:

samples/openapi3/client/petstore/python/petstore_api/api_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def response_deserialize(
311311
return_data = self.__deserialize_file(response_data)
312312
elif response_type is not None:
313313
match = None
314-
content_type = response_data.headers.get('content-type')
314+
content_type = response_data.getheader('content-type')
315315
if content_type is not None:
316316
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
317317
encoding = match.group(1) if match else "utf-8"
@@ -328,7 +328,7 @@ def response_deserialize(
328328
return ApiResponse(
329329
status_code = response_data.status,
330330
data = return_data,
331-
headers = response_data.headers,
331+
headers = response_data.getheaders(),
332332
raw_data = response_data.data
333333
)
334334

@@ -707,14 +707,14 @@ def __deserialize_file(self, response):
707707
os.close(fd)
708708
os.remove(path)
709709

710-
content_disposition = response.headers.get("Content-Disposition")
710+
content_disposition = response.getheaders("Content-Disposition")
711711
if content_disposition:
712712
m = re.search(
713713
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
714714
content_disposition
715715
)
716716
assert m is not None, "Unexpected 'content-disposition' header value"
717-
filename = m.group(1)
717+
filename = os.path.basename(m.group(1)) # Strip any directory traversal
718718
path = os.path.join(os.path.dirname(path), filename)
719719

720720
with open(path, "wb") as f:

0 commit comments

Comments
 (0)