Skip to content
Open
Show file tree
Hide file tree
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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = 'application/json; profile="https://example.com/escape" + print("uh oh") + "'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ def _get_kwargs(
"url": "/bodies/json-like",
}

_kwargs["json"] = UNSET
if not isinstance(body, Unset):
_kwargs["json"] = body.to_dict()
if isinstance(_kwargs["json"], Unset):
del _kwargs["json"]
elif _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/vnd+json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ def _get_kwargs(
"url": "/bodies/optional",
}

_kwargs["json"] = UNSET
if not isinstance(body, Unset):
_kwargs["json"] = body.to_dict()
if isinstance(_kwargs["json"], Unset):
del _kwargs["json"]
elif _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ def _get_kwargs(
}

if isinstance(body, PostBodiesMultipleJsonBody):
_kwargs["json"] = UNSET
if not isinstance(body, Unset):
_kwargs["json"] = body.to_dict()
if isinstance(_kwargs["json"], Unset):
del _kwargs["json"]
elif _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"
if isinstance(body, File):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ def _get_kwargs(
"url": "/bodies/refs",
}

_kwargs["json"] = UNSET
if not isinstance(body, Unset):
_kwargs["json"] = body.to_dict()
if isinstance(_kwargs["json"], Unset):
del _kwargs["json"]
elif _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ def _get_kwargs(
"url": "/config/content-type-override",
}

if not isinstance(body, Unset):
_kwargs["json"] = body
_kwargs["json"] = body
if isinstance(_kwargs["json"], Unset):
del _kwargs["json"]
elif _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "openapi/python/client"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ def _get_kwargs(
"url": "/types/unions/duplicate-types",
}

if isinstance(body, AModel):
if isinstance(body, Unset):
_kwargs["json"] = UNSET
else:
_kwargs["json"] = body.to_dict()

if isinstance(_kwargs["json"], Unset):
del _kwargs["json"]
elif _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

_kwargs["headers"] = headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ def _get_kwargs(
"url": "/naming/property-conflict-with-import",
}

_kwargs["json"] = UNSET
if not isinstance(body, Unset):
_kwargs["json"] = body.to_dict()
if isinstance(_kwargs["json"], Unset):
del _kwargs["json"]
elif _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def _get_kwargs(
}

_kwargs["json"] = body
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def _get_kwargs(
}

_kwargs["json"] = body.to_dict()
if _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]

headers["Content-Type"] = "application/json"

Expand Down
15 changes: 10 additions & 5 deletions openapi_python_client/templates/endpoint_macros.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ if not isinstance(body, Unset):
{% set property = body.prop %}
{% import "property_templates/" + property.template as prop_template %}
{% if prop_template.transform %}
{{ prop_template.transform(property, property.python_name, "_kwargs[\"json\"]", skip_unset=True, declare_type=False) }}
{% elif property.required %}
_kwargs["json"] = {{ property.python_name }}
{{ prop_template.transform(property, property.python_name, "_kwargs[\"json\"]", declare_type=False) }}
{% else %}
if not isinstance({{property.python_name}}, Unset):
_kwargs["json"] = {{ property.python_name }}
_kwargs["json"] = {{ property.python_name }}
{% endif %}
{% if not property.required %}
if isinstance(_kwargs["json"], Unset):
del _kwargs["json"]
{% endif %}
{% if property.required %}if{% else %}elif{% endif %} _kwargs["json"] is None:
# HTTPX treats json=None as no body; send JSON null explicitly.
_kwargs["content"] = b"null"
del _kwargs["json"]
{% endmacro %}

{% macro multipart_body(body) %}
Expand Down