Skip to content
GitLab
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
  • Issues
  • #206
Closed
Open
Issue created Jun 02, 2018 by Administrator@rootContributor

[Python] Skip utf8 decoding for specific Content-Types in py3

Created by: g-bon

In rest.py if PY3 is used and _preload_content is True, the response content is always decoded as utf8. This doesn't make sense for non-text files, e.g. an api that returns a file.

if six.PY3:
    r.data = r.data.decode('utf8')

https://github.com/OpenAPITools/openapi-generator/blob/b5942624d6714f38c0bde9ae9c7400df1d48b1ed/modules/openapi-generator/src/main/resources/python/rest.mustache#L213

I welcome any suggestion on how to tackle this but the two solution that come to mind are:

  • Check on the content_type and make a whitelist/blacklist of content types that should be decoded to utf8.

A simple example would be something like

if six.PY3 and headers.get('Content-Type') not in ['application/octet-stream']:
    r.data = r.data.decode('utf8')

Where obviously the list of Content-Types to "skip" would be a meaningful one and not only octet-stream.

  • Another, harder approach would be to infer the content type from the actual data but feels fragile and overkill to me. Positive side would be that it would likely do the right thing even if the wrong or no content-type is specified in the response headers.

Happy to work on this when I have some confirmation the problem is here / feedback on the right approach.

Assignee
Assign to
Time tracking