Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly set boundary for multipart/form-data #1005

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion openapi_python_client/templates/endpoint_module.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ def _get_kwargs(
{% set destination = "_" + body.body_type + "_body" %}
{{ body_to_kwarg(body, destination) | indent(8) }}
_kwargs["{{ body.body_type.value }}"] = {{ destination }}
{% if body.content_type == "multipart/form-data" %}
headers["Content-Type"] = "multipart/form-data; boundary=+++"
{% else %}
headers["Content-Type"] = "{{ body.content_type }}"
{% endif %}

{% 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 #}
{% if body.content_type == "multipart/form-data" %}
headers["Content-Type"] = "multipart/form-data; boundary=+++"
{% else %}
headers["Content-Type"] = "{{ body.content_type }}"
{% endif %}
{% endif %}
Expand Down
Loading