FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: preserve omitted and null JSON request bodies by CodingCossack · Pull Request #1488 · openapi-generators/openapi-python-client · GitHub

Repository navigation

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .jinja  (1) .py  (18) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
          • misc_metadata_escapes.py
          • non_string_example.py
          • property_escapes.py
          • with_braces_path.py
          • json_like.py
          • optional_body.py
          • post_bodies_multiple.py
          • refs.py
          • content_type_override.py
          • post_const_path.py
          • post_prefix_items.py

Large diffs are not rendered by default.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL