Skip to content

Commit 5daeb9d

Browse files
committed
Stop including optional query parameters when value is set to None
1 parent 8404bd2 commit 5daeb9d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## 0.1.1 - 2020-03-06
88
- Fix mypy issue in generated models `from_dict` with datetime or reference properties
99
- Generated clients now raise an `ApiResponseError` if they receive a response that was not declared
10+
- Stop including optional query parameters when value is set to None
1011

1112
## 0.1.0 - 2020-02-28
1213
- Initial Release

openapi_python_client/templates/endpoint_module.pyi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ def {{ endpoint.name }}(
4747
{% if endpoint.query_parameters %}
4848
params = {
4949
{% for parameter in endpoint.query_parameters %}
50-
"{{ parameter.name }}": {{ parameter.transform() }},
50+
{% if parameter.required %}
51+
"{{ parameter.name }}": {{ parameter.transform() }},
52+
{% endif %}
5153
{% endfor %}
5254
}
55+
{% for parameter in endpoint.query_parameters %}
56+
{% if not parameter.required %}
57+
if {{ parameter.name }} is not None:
58+
params["{{ parameter.name }}"] = {{ parameter.transform() }}
59+
{% endif %}
60+
{% endfor %}
5361
{% endif %}
5462

5563
response = requests.{{ endpoint.method }}(

0 commit comments

Comments
 (0)