Repository navigation
Open
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
openapi-python-client/openapi_python_client/templates/endpoint_module.py.jinja
Lines 48 to 63 in 660941d
| {% if endpoint.bodies | length > 1 %} | |
| {% for body in endpoint.bodies %} | |
| if isinstance(body, {{body.prop.get_type_string() }}): | |
| {% set destination = "_" + body.body_type + "_body" %} | |
| {{ body_to_kwarg(body, destination) | indent(8) }} | |
| _kwargs["{{ body.body_type.value }}"] = {{ destination }} | |
| headers["Content-Type"] = "{{ body.content_type }}" | |
| {% endfor %} | |
| {% elif endpoint.bodies | length == 1 %} | |
| {% set body = endpoint.bodies[0] %} | |
| {{ body_to_kwarg(body, "_body") | indent(4) }} | |
| _kwargs["{{ body.body_type.value }}"] = _body | |
| {% if body.content_type != "multipart/form-data" %}{# Need httpx to set the boundary automatically #} | |
| headers["Content-Type"] = "{{ body.content_type }}" | |
| {% endif %} | |
| {% endif %} |
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.
Metadata
Metadata
Assignees
Labels
No labels
Activity
fix: Let httpx2 choose the multipart/form-data boundary (openapi-gene…
Release 0.30.0 (openapi-generators#1510)