Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !13402

[python-experimental] Enhance octet-stream deserialize

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/EltonChou/enhance-octet-stream-deserialize into master 2 years ago
  • Overview 5
  • Commits 8
  • Pipelines 0
  • Changes 62

Created by: EltonChou

@spacether

  • Add a method to extract filename when the headers of octet-stream resopnse didn't provide the filename.
  • Add test for the method.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master (6.1.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.
Compare
  • master (base)

and
  • latest version
    48a6e092
    8 commits, 2 years ago

62 files
+ 151
- 67

    Preferences

    File browser
    Compare changes
modules/…/…/…/…/p‎ython-experimental‎
api_client‎.handlebars‎ +19 -3
sam‎ples‎
client/petstore/…/l‎ib/openapi_petstore‎
a‎pi‎
another‎_fake.ex‎ +1 -1
defau‎lt.ex‎ +1 -1
fak‎e.ex‎ +1 -1
fake_classna‎me_tags123.ex‎ +1 -1
pet‎.ex‎ +1 -1
stor‎e.ex‎ +1 -1
use‎r.ex‎ +1 -1
mo‎del‎
_foo_get_defau‎lt_response.ex‎ +1 -1
_special_mo‎del_name_.ex‎ +1 -1
additional_prop‎erties_class.ex‎ +1 -1
all_of_with_‎single_ref.ex‎ +1 -1
anim‎al.ex‎ +1 -1
api_res‎ponse.ex‎ +1 -1
array_of_array_o‎f_number_only.ex‎ +1 -1
array_of_nu‎mber_only.ex‎ +1 -1
array_‎test.ex‎ +1 -1
capitali‎zation.ex‎ +1 -1
cat‎.ex‎ +1 -1
cat_al‎l_of.ex‎ +1 -1
categ‎ory.ex‎ +1 -1
class_m‎odel.ex‎ +1 -1
clie‎nt.ex‎ +1 -1
deprecated‎_object.ex‎ +1 -1
dog‎.ex‎ +1 -1
dog_al‎l_of.ex‎ +1 -1
enum_ar‎rays.ex‎ +1 -1
enum_c‎lass.ex‎ +1 -1
enum_t‎est.ex‎ +1 -1
fil‎e.ex‎ +1 -1
file_schema_‎test_class.ex‎ +1 -1
foo‎.ex‎ +1 -1
format_‎test.ex‎ +1 -1
has_only_r‎ead_only.ex‎ +1 -1
health_chec‎k_result.ex‎ +1 -1
lis‎t.ex‎ +1 -1
map_t‎est.ex‎ +1 -1
mixed_properties_and_addi‎tional_properties_class.ex‎ +1 -1
model_200_‎response.ex‎ +1 -1
nam‎e.ex‎ +1 -1
nullable‎_class.ex‎ +1 -1
number_‎only.ex‎ +1 -1
object_with_depr‎ecated_fields.ex‎ +1 -1
orde‎r.ex‎ +1 -1
outer_com‎posite.ex‎ +1 -1
outer_‎enum.ex‎ +1 -1
outer_enum_de‎fault_value.ex‎ +1 -1
outer_enum‎_integer.ex‎ +1 -1
outer_enum_intege‎r_default_value.ex‎ +1 -1
outer_object_with‎_enum_property.ex‎ +1 -1
pet‎.ex‎ +1 -1
read_only‎_first.ex‎ +1 -1
retu‎rn.ex‎ +1 -1
single_re‎f_type.ex‎ +1 -1
tag‎.ex‎ +1 -1
use‎r.ex‎ +1 -1
connec‎tion.ex‎ +1 -1
deseria‎lizer.ex‎ +1 -1
request_b‎uilder.ex‎ +1 -1
openapi‎3/client‎
3_0_3_unit_test‎/…/unit_test_api‎
api_cl‎ient.py‎ +19 -3
petstore/pytho‎n-experimental‎
petsto‎re_api‎
api_cl‎ient.py‎ +19 -3
tests_‎manual‎
test_fak‎e_api.py‎ +36 -0
modules/openapi-generator/src/main/resources/python-experimental/api_client.handlebars
+ 19
- 3
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


@@ -15,7 +15,7 @@ import tempfile
import typing
import urllib3
from urllib3._collections import HTTPHeaderDict
from urllib.parse import quote
from urllib.parse import urlparse, quote
from urllib3.fields import RequestField as RequestFieldBase
{{#if tornado}}
@@ -832,6 +832,19 @@ class OpenApiResponse(JSONDetector):
# python must be >= 3.9 so we can pass in bytes into json.loads
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
def __file_name_from_content_disposition(cls, content_disposition: typing.Optional[str]) -> typing.Optional[str]:
if content_disposition is None:
@@ -851,13 +864,16 @@ class OpenApiResponse(JSONDetector):
a file will be written and returned
"""
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:
_fd, path = tempfile.mkstemp()
else:
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:
chunk_size = 1024
while True:
modules/openapi-generator/src/main/resources/python-experimental/api_client.handlebars
+ 19
- 3
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


@@ -15,7 +15,7 @@ import tempfile
import typing
import urllib3
from urllib3._collections import HTTPHeaderDict
from urllib.parse import quote
from urllib.parse import urlparse, quote
from urllib3.fields import RequestField as RequestFieldBase
{{#if tornado}}
@@ -832,6 +832,19 @@ class OpenApiResponse(JSONDetector):
# python must be >= 3.9 so we can pass in bytes into json.loads
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
def __file_name_from_content_disposition(cls, content_disposition: typing.Optional[str]) -> typing.Optional[str]:
if content_disposition is None:
@@ -851,13 +864,16 @@ class OpenApiResponse(JSONDetector):
a file will be written and returned
"""
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:
_fd, path = tempfile.mkstemp()
else:
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:
chunk_size = 1024
while True:
samples/client/petstore/elixir/lib/openapi_petstore/api/another_fake.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Api.AnotherFake do
samples/client/petstore/elixir/lib/openapi_petstore/api/default.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Api.Default do
samples/client/petstore/elixir/lib/openapi_petstore/api/fake.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Api.Fake do
samples/client/petstore/elixir/lib/openapi_petstore/api/fake_classname_tags123.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Api.FakeClassnameTags123 do
samples/client/petstore/elixir/lib/openapi_petstore/api/pet.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Api.Pet do
samples/client/petstore/elixir/lib/openapi_petstore/api/store.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Api.Store do
samples/client/petstore/elixir/lib/openapi_petstore/api/user.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Api.User do
samples/client/petstore/elixir/lib/openapi_petstore/model/_foo_get_default_response.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Model.FooGetDefaultResponse do
samples/client/petstore/elixir/lib/openapi_petstore/model/_special_model_name_.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Model.SpecialModelName do
samples/client/petstore/elixir/lib/openapi_petstore/model/additional_properties_class.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Model.AdditionalPropertiesClass do
samples/client/petstore/elixir/lib/openapi_petstore/model/all_of_with_single_ref.ex
+ 1
- 1
  • View file @ 48a6e092

  • Edit in single-file editor

  • Open in Web IDE


# 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.
defmodule OpenapiPetstore.Model.AllOfWithSingleRef do
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
1
Client: Python
1
Client: Python
    Assign labels
  • Manage project labels

Milestone
6.2.0
6.2.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Administrator
Reference: OpenAPITools/openapi-generator!13402
Source branch: github/fork/EltonChou/enhance-octet-stream-deserialize

Menu

Explore Projects Groups Snippets