forked from loafle/openapi-generator-original
[python-experimental] Enhance octet-stream deserialize (#13402)
* [python-experimental] Enhance octet-stream deserialization When the headers didn't provide the filename, use the url of response to extract filename. * [python-experimental] Remove todo comment. * [python-experimental] Fix test code. * Update samples * [python-experimental] Refined the method and the test + Early return when the url is empty or `None`. + Removed unused f-string prefix. * [python-experimental] Comapre url is None explicitly. * Update samples.
This commit is contained in:
parent
194d421d83
commit
8e66294bfe
@ -15,7 +15,7 @@ import tempfile
|
|||||||
import typing
|
import typing
|
||||||
import urllib3
|
import urllib3
|
||||||
from urllib3._collections import HTTPHeaderDict
|
from urllib3._collections import HTTPHeaderDict
|
||||||
from urllib.parse import quote
|
from urllib.parse import urlparse, quote
|
||||||
from urllib3.fields import RequestField as RequestFieldBase
|
from urllib3.fields import RequestField as RequestFieldBase
|
||||||
|
|
||||||
{{#if tornado}}
|
{{#if tornado}}
|
||||||
@ -832,6 +832,19 @@ class OpenApiResponse(JSONDetector):
|
|||||||
# python must be >= 3.9 so we can pass in bytes into json.loads
|
# python must be >= 3.9 so we can pass in bytes into json.loads
|
||||||
return json.loads(response.data)
|
return json.loads(response.data)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __file_name_from_response_url(response_url: typing.Optional[str]) -> typing.Optional[str]:
|
||||||
|
if response_url is None:
|
||||||
|
return None
|
||||||
|
url_path = urlparse(response_url).path
|
||||||
|
if url_path:
|
||||||
|
path_basename = os.path.basename(url_path)
|
||||||
|
if path_basename:
|
||||||
|
_filename, ext = os.path.splitext(path_basename)
|
||||||
|
if ext:
|
||||||
|
return path_basename
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __file_name_from_content_disposition(cls, content_disposition: typing.Optional[str]) -> typing.Optional[str]:
|
def __file_name_from_content_disposition(cls, content_disposition: typing.Optional[str]) -> typing.Optional[str]:
|
||||||
if content_disposition is None:
|
if content_disposition is None:
|
||||||
@ -851,13 +864,16 @@ class OpenApiResponse(JSONDetector):
|
|||||||
a file will be written and returned
|
a file will be written and returned
|
||||||
"""
|
"""
|
||||||
if response.supports_chunked_reads():
|
if response.supports_chunked_reads():
|
||||||
file_name = self.__file_name_from_content_disposition(response.headers.get('content-disposition'))
|
file_name = (
|
||||||
|
self.__file_name_from_content_disposition(response.headers.get('content-disposition'))
|
||||||
|
or self.__file_name_from_response_url(response.geturl())
|
||||||
|
)
|
||||||
|
|
||||||
if file_name is None:
|
if file_name is None:
|
||||||
_fd, path = tempfile.mkstemp()
|
_fd, path = tempfile.mkstemp()
|
||||||
else:
|
else:
|
||||||
path = os.path.join(tempfile.gettempdir(), file_name)
|
path = os.path.join(tempfile.gettempdir(), file_name)
|
||||||
# TODO get file_name from the filename at the end of the url if it exists
|
|
||||||
with open(path, 'wb') as new_file:
|
with open(path, 'wb') as new_file:
|
||||||
chunk_size = 1024
|
chunk_size = 1024
|
||||||
while True:
|
while True:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Api.AnotherFake do
|
defmodule OpenapiPetstore.Api.AnotherFake do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Api.Default do
|
defmodule OpenapiPetstore.Api.Default do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Api.Fake do
|
defmodule OpenapiPetstore.Api.Fake do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Api.FakeClassnameTags123 do
|
defmodule OpenapiPetstore.Api.FakeClassnameTags123 do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Api.Pet do
|
defmodule OpenapiPetstore.Api.Pet do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Api.Store do
|
defmodule OpenapiPetstore.Api.Store do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Api.User do
|
defmodule OpenapiPetstore.Api.User do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Connection do
|
defmodule OpenapiPetstore.Connection do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Deserializer do
|
defmodule OpenapiPetstore.Deserializer do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.FooGetDefaultResponse do
|
defmodule OpenapiPetstore.Model.FooGetDefaultResponse do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.SpecialModelName do
|
defmodule OpenapiPetstore.Model.SpecialModelName do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.AdditionalPropertiesClass do
|
defmodule OpenapiPetstore.Model.AdditionalPropertiesClass do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.AllOfWithSingleRef do
|
defmodule OpenapiPetstore.Model.AllOfWithSingleRef do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Animal do
|
defmodule OpenapiPetstore.Model.Animal do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.ApiResponse do
|
defmodule OpenapiPetstore.Model.ApiResponse do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.ArrayOfArrayOfNumberOnly do
|
defmodule OpenapiPetstore.Model.ArrayOfArrayOfNumberOnly do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.ArrayOfNumberOnly do
|
defmodule OpenapiPetstore.Model.ArrayOfNumberOnly do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.ArrayTest do
|
defmodule OpenapiPetstore.Model.ArrayTest do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Capitalization do
|
defmodule OpenapiPetstore.Model.Capitalization do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Cat do
|
defmodule OpenapiPetstore.Model.Cat do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.CatAllOf do
|
defmodule OpenapiPetstore.Model.CatAllOf do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Category do
|
defmodule OpenapiPetstore.Model.Category do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.ClassModel do
|
defmodule OpenapiPetstore.Model.ClassModel do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Client do
|
defmodule OpenapiPetstore.Model.Client do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.DeprecatedObject do
|
defmodule OpenapiPetstore.Model.DeprecatedObject do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Dog do
|
defmodule OpenapiPetstore.Model.Dog do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.DogAllOf do
|
defmodule OpenapiPetstore.Model.DogAllOf do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.EnumArrays do
|
defmodule OpenapiPetstore.Model.EnumArrays do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.EnumClass do
|
defmodule OpenapiPetstore.Model.EnumClass do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.EnumTest do
|
defmodule OpenapiPetstore.Model.EnumTest do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.File do
|
defmodule OpenapiPetstore.Model.File do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.FileSchemaTestClass do
|
defmodule OpenapiPetstore.Model.FileSchemaTestClass do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Foo do
|
defmodule OpenapiPetstore.Model.Foo do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.FormatTest do
|
defmodule OpenapiPetstore.Model.FormatTest do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.HasOnlyReadOnly do
|
defmodule OpenapiPetstore.Model.HasOnlyReadOnly do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.HealthCheckResult do
|
defmodule OpenapiPetstore.Model.HealthCheckResult do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.List do
|
defmodule OpenapiPetstore.Model.List do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.MapTest do
|
defmodule OpenapiPetstore.Model.MapTest do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.MixedPropertiesAndAdditionalPropertiesClass do
|
defmodule OpenapiPetstore.Model.MixedPropertiesAndAdditionalPropertiesClass do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Model200Response do
|
defmodule OpenapiPetstore.Model.Model200Response do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Name do
|
defmodule OpenapiPetstore.Model.Name do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.NullableClass do
|
defmodule OpenapiPetstore.Model.NullableClass do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.NumberOnly do
|
defmodule OpenapiPetstore.Model.NumberOnly do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.ObjectWithDeprecatedFields do
|
defmodule OpenapiPetstore.Model.ObjectWithDeprecatedFields do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Order do
|
defmodule OpenapiPetstore.Model.Order do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.OuterComposite do
|
defmodule OpenapiPetstore.Model.OuterComposite do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.OuterEnum do
|
defmodule OpenapiPetstore.Model.OuterEnum do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.OuterEnumDefaultValue do
|
defmodule OpenapiPetstore.Model.OuterEnumDefaultValue do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.OuterEnumInteger do
|
defmodule OpenapiPetstore.Model.OuterEnumInteger do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.OuterEnumIntegerDefaultValue do
|
defmodule OpenapiPetstore.Model.OuterEnumIntegerDefaultValue do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.OuterObjectWithEnumProperty do
|
defmodule OpenapiPetstore.Model.OuterObjectWithEnumProperty do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Pet do
|
defmodule OpenapiPetstore.Model.Pet do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.ReadOnlyFirst do
|
defmodule OpenapiPetstore.Model.ReadOnlyFirst do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Return do
|
defmodule OpenapiPetstore.Model.Return do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.SingleRefType do
|
defmodule OpenapiPetstore.Model.SingleRefType do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.Tag do
|
defmodule OpenapiPetstore.Model.Tag do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.Model.User do
|
defmodule OpenapiPetstore.Model.User do
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# NOTE: This file is auto generated by OpenAPI Generator 6.1.0-SNAPSHOT (https://openapi-generator.tech).
|
# NOTE: This file is auto generated by OpenAPI Generator 6.1.1-SNAPSHOT (https://openapi-generator.tech).
|
||||||
# Do not edit this file manually.
|
# Do not edit this file manually.
|
||||||
|
|
||||||
defmodule OpenapiPetstore.RequestBuilder do
|
defmodule OpenapiPetstore.RequestBuilder do
|
||||||
|
@ -22,7 +22,7 @@ import tempfile
|
|||||||
import typing
|
import typing
|
||||||
import urllib3
|
import urllib3
|
||||||
from urllib3._collections import HTTPHeaderDict
|
from urllib3._collections import HTTPHeaderDict
|
||||||
from urllib.parse import quote
|
from urllib.parse import urlparse, quote
|
||||||
from urllib3.fields import RequestField as RequestFieldBase
|
from urllib3.fields import RequestField as RequestFieldBase
|
||||||
|
|
||||||
import frozendict
|
import frozendict
|
||||||
@ -836,6 +836,19 @@ class OpenApiResponse(JSONDetector):
|
|||||||
# python must be >= 3.9 so we can pass in bytes into json.loads
|
# python must be >= 3.9 so we can pass in bytes into json.loads
|
||||||
return json.loads(response.data)
|
return json.loads(response.data)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __file_name_from_response_url(response_url: typing.Optional[str]) -> typing.Optional[str]:
|
||||||
|
if response_url is None:
|
||||||
|
return None
|
||||||
|
url_path = urlparse(response_url).path
|
||||||
|
if url_path:
|
||||||
|
path_basename = os.path.basename(url_path)
|
||||||
|
if path_basename:
|
||||||
|
_filename, ext = os.path.splitext(path_basename)
|
||||||
|
if ext:
|
||||||
|
return path_basename
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __file_name_from_content_disposition(cls, content_disposition: typing.Optional[str]) -> typing.Optional[str]:
|
def __file_name_from_content_disposition(cls, content_disposition: typing.Optional[str]) -> typing.Optional[str]:
|
||||||
if content_disposition is None:
|
if content_disposition is None:
|
||||||
@ -855,13 +868,16 @@ class OpenApiResponse(JSONDetector):
|
|||||||
a file will be written and returned
|
a file will be written and returned
|
||||||
"""
|
"""
|
||||||
if response.supports_chunked_reads():
|
if response.supports_chunked_reads():
|
||||||
file_name = self.__file_name_from_content_disposition(response.headers.get('content-disposition'))
|
file_name = (
|
||||||
|
self.__file_name_from_content_disposition(response.headers.get('content-disposition'))
|
||||||
|
or self.__file_name_from_response_url(response.geturl())
|
||||||
|
)
|
||||||
|
|
||||||
if file_name is None:
|
if file_name is None:
|
||||||
_fd, path = tempfile.mkstemp()
|
_fd, path = tempfile.mkstemp()
|
||||||
else:
|
else:
|
||||||
path = os.path.join(tempfile.gettempdir(), file_name)
|
path = os.path.join(tempfile.gettempdir(), file_name)
|
||||||
# TODO get file_name from the filename at the end of the url if it exists
|
|
||||||
with open(path, 'wb') as new_file:
|
with open(path, 'wb') as new_file:
|
||||||
chunk_size = 1024
|
chunk_size = 1024
|
||||||
while True:
|
while True:
|
||||||
|
@ -22,7 +22,7 @@ import tempfile
|
|||||||
import typing
|
import typing
|
||||||
import urllib3
|
import urllib3
|
||||||
from urllib3._collections import HTTPHeaderDict
|
from urllib3._collections import HTTPHeaderDict
|
||||||
from urllib.parse import quote
|
from urllib.parse import urlparse, quote
|
||||||
from urllib3.fields import RequestField as RequestFieldBase
|
from urllib3.fields import RequestField as RequestFieldBase
|
||||||
|
|
||||||
import frozendict
|
import frozendict
|
||||||
@ -836,6 +836,19 @@ class OpenApiResponse(JSONDetector):
|
|||||||
# python must be >= 3.9 so we can pass in bytes into json.loads
|
# python must be >= 3.9 so we can pass in bytes into json.loads
|
||||||
return json.loads(response.data)
|
return json.loads(response.data)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __file_name_from_response_url(response_url: typing.Optional[str]) -> typing.Optional[str]:
|
||||||
|
if response_url is None:
|
||||||
|
return None
|
||||||
|
url_path = urlparse(response_url).path
|
||||||
|
if url_path:
|
||||||
|
path_basename = os.path.basename(url_path)
|
||||||
|
if path_basename:
|
||||||
|
_filename, ext = os.path.splitext(path_basename)
|
||||||
|
if ext:
|
||||||
|
return path_basename
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __file_name_from_content_disposition(cls, content_disposition: typing.Optional[str]) -> typing.Optional[str]:
|
def __file_name_from_content_disposition(cls, content_disposition: typing.Optional[str]) -> typing.Optional[str]:
|
||||||
if content_disposition is None:
|
if content_disposition is None:
|
||||||
@ -855,13 +868,16 @@ class OpenApiResponse(JSONDetector):
|
|||||||
a file will be written and returned
|
a file will be written and returned
|
||||||
"""
|
"""
|
||||||
if response.supports_chunked_reads():
|
if response.supports_chunked_reads():
|
||||||
file_name = self.__file_name_from_content_disposition(response.headers.get('content-disposition'))
|
file_name = (
|
||||||
|
self.__file_name_from_content_disposition(response.headers.get('content-disposition'))
|
||||||
|
or self.__file_name_from_response_url(response.geturl())
|
||||||
|
)
|
||||||
|
|
||||||
if file_name is None:
|
if file_name is None:
|
||||||
_fd, path = tempfile.mkstemp()
|
_fd, path = tempfile.mkstemp()
|
||||||
else:
|
else:
|
||||||
path = os.path.join(tempfile.gettempdir(), file_name)
|
path = os.path.join(tempfile.gettempdir(), file_name)
|
||||||
# TODO get file_name from the filename at the end of the url if it exists
|
|
||||||
with open(path, 'wb') as new_file:
|
with open(path, 'wb') as new_file:
|
||||||
chunk_size = 1024
|
chunk_size = 1024
|
||||||
while True:
|
while True:
|
||||||
|
@ -400,6 +400,42 @@ class TestFakeApi(ApiTestMixin):
|
|||||||
api_response.body.close()
|
api_response.body.close()
|
||||||
os.unlink(api_response.body.name)
|
os.unlink(api_response.body.name)
|
||||||
|
|
||||||
|
"""
|
||||||
|
when streaming is used and the response contains the content disposition header without a filename
|
||||||
|
the url of response is used to extract the filename.
|
||||||
|
"""
|
||||||
|
file1 = open(file_path1, "rb")
|
||||||
|
streamable_body = StreamableBody(file1)
|
||||||
|
expected_filename = "the_file.ext"
|
||||||
|
|
||||||
|
no_filename_mock_response = self.response(
|
||||||
|
streamable_body,
|
||||||
|
content_type='application/octet-stream',
|
||||||
|
headers={'content-disposition': 'attachment'},
|
||||||
|
preload_content=False
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch.object(RESTClientObject, 'request') as mock_request:
|
||||||
|
no_filename_mock_response.geturl = lambda: f'http://foo.bar/{expected_filename}'
|
||||||
|
mock_request.return_value = no_filename_mock_response
|
||||||
|
api_response = self.api.upload_download_file(body=file_bytes, stream=True)
|
||||||
|
self.assert_request_called_with(
|
||||||
|
mock_request,
|
||||||
|
'http://petstore.swagger.io:80/v2/fake/uploadDownloadFile',
|
||||||
|
body=file_bytes,
|
||||||
|
content_type='application/octet-stream',
|
||||||
|
accept_content_type='application/octet-stream',
|
||||||
|
stream=True
|
||||||
|
)
|
||||||
|
self.assertTrue(file1.closed)
|
||||||
|
self.assertTrue(isinstance(api_response.body, schemas.BinarySchema))
|
||||||
|
self.assertTrue(isinstance(api_response.body, schemas.FileSchema))
|
||||||
|
self.assertTrue(isinstance(api_response.body, schemas.FileIO))
|
||||||
|
self.assertTrue(api_response.body.name.endswith(expected_filename))
|
||||||
|
self.assertEqual(api_response.body.read(), file_bytes)
|
||||||
|
api_response.body.close()
|
||||||
|
os.unlink(api_response.body.name)
|
||||||
|
|
||||||
def test_upload_file(self):
|
def test_upload_file(self):
|
||||||
"""Test case for upload_file
|
"""Test case for upload_file
|
||||||
uploads a file using multipart/form-data # noqa: E501
|
uploads a file using multipart/form-data # noqa: E501
|
||||||
|
Loading…
x
Reference in New Issue
Block a user