Skip setting 'Content-Type' on file upload, when multiple bodies are supported

Open Beginner friendly
#947 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
api

Research direction

Start with openapi_python_client/templates/endpoint_module.py.jinja, especially the content-type handling around lines 48-63 and the existing multipart condition. Verify generated requests for endpoints supporting multiple body types, and consider the work complete when multipart uploads receive a Content-Type boundary without overriding httpx's header handling.

Written by the indexing model from the issue text.

Description

Describe the bug
Form-style submissions to endpoints that support multiple different content types are missing the necessary "boundary" attribute on the Content-Type header.

POST https://.../items HTTP/1.1
Host: ...
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
User-Agent: python-httpx/0.25.2
Authorization: Bearer ...
Content-Type: multipart/form-data
Transfer-Encoding: chunked

Cause
https://github.com/openapi-generators/openapi-python-client/blob/660941dfe23a39ea9a22dd724e1db54afb130d08/openapi_python_client/templates/endpoint_module.py.jinja#L48-L63

In the template above, lines 60-62 have an "if content-type is not multipart/form-data" condition since httpx sets content type and multipart form boundary properly when files are provided. The same condition needs to be applied around line 54, which occurs when multiple body types are supported.

Dominant language
Python
Stars
2k
Forks
293
Avg merge
34m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openapi-generators/openapi-python-client

All issues in openapi-generators/openapi-python-client

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.