Skip to content

fix: _get_kwargs bool headers are now converted to strings #553

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

Closed
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _get_kwargs(
cookies: Dict[str, Any] = client.get_cookies()

if keep_alive is not UNSET:
headers["keep-alive"] = keep_alive
headers["keep-alive"] = str(keep_alive).lower()

multipart_multipart_data = multipart_data.to_multipart()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _get_kwargs(
cookies: Dict[str, Any] = client.get_cookies()

if keep_alive is not UNSET:
headers["keep-alive"] = keep_alive
headers["keep-alive"] = str(keep_alive).lower()

multipart_multipart_data = []
for multipart_data_item_data in multipart_data:
Expand Down
11 changes: 9 additions & 2 deletions openapi_python_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ def _build_api(self) -> None:
encoding=self.file_encoding,
)

endpoint_template = self.env.get_template("endpoint_module.py.jinja")
endpoint_template = self.env.get_template(
"endpoint_module.py.jinja", globals={"isbool": lambda obj: obj.get_base_type_string() == "bool"}
)
for tag, collection in endpoint_collections_by_tag.items():
tag_dir = api_dir / tag
tag_dir.mkdir()
Expand All @@ -281,7 +283,12 @@ def _build_api(self) -> None:

for endpoint in collection.endpoints:
module_path = tag_dir / f"{utils.PythonIdentifier(endpoint.name, self.config.field_prefix)}.py"
module_path.write_text(endpoint_template.render(endpoint=endpoint), encoding=self.file_encoding)
module_path.write_text(
endpoint_template.render(
endpoint=endpoint,
),
encoding=self.file_encoding,
)


def _get_project_for_url_or_path( # pylint: disable=too-many-arguments
Expand Down
12 changes: 10 additions & 2 deletions openapi_python_client/templates/endpoint_macros.py.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
{% if endpoint.header_parameters %}
{% for parameter in endpoint.header_parameters.values() %}
{% if parameter.required %}
headers["{{ parameter.name | kebabcase}}"] = {{ parameter.python_name }}
headers["{{ parameter.name | kebabcase}}"] = {% if isbool(parameter) %}
str({{ parameter.python_name }}).lower()
{% else %}
{{ parameter.python_name}}
{% endif %}
{% else %}
if {{ parameter.python_name }} is not UNSET:
headers["{{ parameter.name | kebabcase}}"] = {{ parameter.python_name }}
headers["{{ parameter.name | kebabcase}}"] = {% if isbool(parameter) %}
str({{ parameter.python_name }}).lower()
{% else %}
{{ parameter.python_name}}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
Expand Down