OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.48k stars 6.5k forks source link

Wrong Content-Type for gzip files [BUG][PYTHON] #8021

Open ahrberg opened 3 years ago

ahrberg commented 3 years ago
Description

When uploading a gzip file the Content-Type is set to application/octet-stream. According to RFC6713 it should be application/gzip.

openapi-generator version

v4.3.1 but bug still exists in master

Suggest a fix

Possible fix inspired by this. Targeting this line.

filename = os.path.basename(f.name)
filedata = f.read()
mimetype = (mimetypes.guess_type(filename)[0] or
            'application/octet-stream')
# This is added
if mimetypes.guess_type(filename)[1] == "gzip":
    mimetype = "application/gzip"
# End of change

If accepted I can make a pull request.

wing328 commented 3 years ago

@ahrberg thanks for reporting the issue.

Instead of guessing the content-type from the file, what about using the content-type specified in the specifications (2.0, 3.0)?

e.g. https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml#L274

ahrberg commented 3 years ago

Thanks for reply @wing328 !

I guess the content-type from the specification could be used if only one content-type is accepted? But in my case the API accepts xml, and gzip. Or I'm I missing something?

One example with two accepted content-types I also found in the swagger documentation https://swagger.io/docs/specification/describing-request-body/multipart-requests/