Skip to content

Commit f7f6b9e

Browse files
Handle None as query param
1 parent 032a4a4 commit f7f6b9e

11 files changed

+29
-26
lines changed

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ def _get_kwargs(
3838
cookies: Dict[str, Any] = client.get_cookies()
3939

4040
json_not_required_not_nullable_datetime_prop: Union[Unset, str] = UNSET
41-
if not isinstance(not_required_not_nullable_datetime_prop, Unset):
41+
if (
42+
not isinstance(not_required_not_nullable_datetime_prop, Unset)
43+
and not_required_not_nullable_datetime_prop is not None
44+
):
4245
json_not_required_not_nullable_datetime_prop = not_required_not_nullable_datetime_prop.isoformat()
4346

4447
json_not_required_nullable_datetime_prop: Union[Unset, None, str] = UNSET
45-
if not isinstance(not_required_nullable_datetime_prop, Unset):
48+
if not isinstance(not_required_nullable_datetime_prop, Unset) and not_required_nullable_datetime_prop is not None:
4649
json_not_required_nullable_datetime_prop = (
4750
not_required_nullable_datetime_prop.isoformat() if not_required_nullable_datetime_prop else None
4851
)
@@ -54,25 +57,25 @@ def _get_kwargs(
5457
)
5558

5659
json_date_prop: Union[Unset, str] = UNSET
57-
if not isinstance(date_prop, Unset):
60+
if not isinstance(date_prop, Unset) and date_prop is not None:
5861
json_date_prop = date_prop.isoformat()
5962

6063
json_list_prop: Union[Unset, List[str]] = UNSET
61-
if not isinstance(list_prop, Unset):
64+
if not isinstance(list_prop, Unset) and list_prop is not None:
6265
json_list_prop = []
6366
for list_prop_item_data in list_prop:
6467
list_prop_item = list_prop_item_data.value
6568

6669
json_list_prop.append(list_prop_item)
6770

6871
json_union_prop: Union[Unset, float, str]
69-
if isinstance(union_prop, Unset):
72+
if isinstance(union_prop, Unset) or union_prop is None:
7073
json_union_prop = UNSET
7174
else:
7275
json_union_prop = union_prop
7376

7477
json_union_prop_with_ref: Union[Unset, float, str]
75-
if isinstance(union_prop_with_ref, Unset):
78+
if isinstance(union_prop_with_ref, Unset) or union_prop_with_ref is None:
7679
json_union_prop_with_ref = UNSET
7780
elif isinstance(union_prop_with_ref, AnEnum):
7881
json_union_prop_with_ref = UNSET
@@ -83,17 +86,17 @@ def _get_kwargs(
8386
json_union_prop_with_ref = union_prop_with_ref
8487

8588
json_enum_prop: Union[Unset, str] = UNSET
86-
if not isinstance(enum_prop, Unset):
89+
if not isinstance(enum_prop, Unset) and enum_prop is not None:
8790
json_enum_prop = enum_prop.value
8891

8992
json_model_prop: Union[Unset, Dict[str, Any]] = UNSET
90-
if not isinstance(model_prop, Unset):
93+
if not isinstance(model_prop, Unset) and model_prop is not None:
9194
json_model_prop = model_prop.to_dict()
9295

9396
json_required_model_prop = required_model_prop.to_dict()
9497

9598
json_nullable_model_prop: Union[Unset, None, Dict[str, Any]] = UNSET
96-
if not isinstance(nullable_model_prop, Unset):
99+
if not isinstance(nullable_model_prop, Unset) and nullable_model_prop is not None:
97100
json_nullable_model_prop = nullable_model_prop.to_dict() if nullable_model_prop else None
98101

99102
json_nullable_required_model_prop = nullable_required_model_prop.to_dict() if nullable_required_model_prop else None

Diff for: end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _get_kwargs(
1818
cookies: Dict[str, Any] = client.get_cookies()
1919

2020
json_query_param: Union[Unset, List[str]] = UNSET
21-
if not isinstance(query_param, Unset):
21+
if not isinstance(query_param, Unset) and query_param is not None:
2222
json_query_param = query_param
2323

2424
params: Dict[str, Any] = {

Diff for: openapi_python_client/templates/endpoint_macros.py.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if {{ parameter.python_name }} is not UNSET:
3131
{% set destination = "json_" + property.python_name %}
3232
{% if property.template %}
3333
{% from "property_templates/" + property.template import transform %}
34-
{{ transform(property, property.python_name, destination) }}
34+
{{ transform(property, property.python_name, destination, query_param=True) }}
3535
{% endif %}
3636
{% endfor %}
3737
params: Dict[str, Any] = {

Diff for: openapi_python_client/templates/property_templates/date_property.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ isoparse({{ source }}).date()
1010

1111
{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, str){% endmacro %}
1212

13-
{% macro transform(property, source, destination, declare_type=True) %}
13+
{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
1414
{% if property.required %}
1515
{{ destination }} = {{ source }}.isoformat() {% if property.nullable %}if {{ source }} else None {%endif%}
1616
{% else %}
1717
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
18-
if not isinstance({{ source }}, Unset):
18+
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
1919
{% if property.nullable %}
2020
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
2121
{% else %}

Diff for: openapi_python_client/templates/property_templates/datetime_property.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ isoparse({{ source }})
1010

1111
{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, str){% endmacro %}
1212

13-
{% macro transform(property, source, destination, declare_type=True) %}
13+
{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
1414
{% if property.required %}
1515
{% if property.nullable %}
1616
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
@@ -19,7 +19,7 @@ isoparse({{ source }})
1919
{% endif %}
2020
{% else %}
2121
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
22-
if not isinstance({{ source }}, Unset):
22+
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
2323
{% if property.nullable %}
2424
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
2525
{% else %}

Diff for: openapi_python_client/templates/property_templates/enum_property.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, {{ property.value_type.__name__ }}){% endmacro %}
1212

13-
{% macro transform(property, source, destination, declare_type=True) %}
13+
{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
1414
{% if property.required %}
1515
{% if property.nullable %}
1616
{{ destination }} = {{ source }}.value if {{ source }} else None
@@ -19,7 +19,7 @@
1919
{% endif %}
2020
{% else %}
2121
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
22-
if not isinstance({{ source }}, Unset):
22+
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
2323
{% if property.nullable %}
2424
{{ destination }} = {{ source }}.value if {{ source }} else None
2525
{% else %}

Diff for: openapi_python_client/templates/property_templates/file_property.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ File(
1212

1313
{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, bytes){% endmacro %}
1414

15-
{% macro transform(property, source, destination, declare_type=True) %}
15+
{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
1616
{% if property.required %}
1717
{% if property.nullable %}
1818
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
@@ -21,7 +21,7 @@ File(
2121
{% endif %}
2222
{% else %}
2323
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
24-
if not isinstance({{ source }}, Unset):
24+
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
2525
{% if property.nullable %}
2626
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
2727
{% else %}

Diff for: openapi_python_client/templates/property_templates/list_property.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ for {{ inner_source }} in {{ source }}:
3333

3434
{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, list){% endmacro %}
3535

36-
{% macro transform(property, source, destination, declare_type=True) %}
36+
{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
3737
{% set inner_property = property.inner_property %}
3838
{% if property.required %}
3939
{% if property.nullable %}
@@ -46,7 +46,7 @@ else:
4646
{% endif %}
4747
{% else %}
4848
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
49-
if not isinstance({{ source }}, Unset):
49+
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
5050
{% if property.nullable %}
5151
if {{ source }} is None:
5252
{{ destination }} = None

Diff for: openapi_python_client/templates/property_templates/model_property.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
{% macro check_type_for_construct(property, source) %}isinstance({{ source }}, dict){% endmacro %}
1212

13-
{% macro transform(property, source, destination, declare_type=True) %}
13+
{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
1414
{% if property.required %}
1515
{% if property.nullable %}
1616
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
@@ -19,7 +19,7 @@
1919
{% endif %}
2020
{% else %}
2121
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %} = UNSET
22-
if not isinstance({{ source }}, Unset):
22+
if not isinstance({{ source }}, Unset){% if query_param %} and {{ source }} is not None{% endif %}:
2323
{% if property.nullable %}
2424
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
2525
{% else %}

Diff for: openapi_python_client/templates/property_templates/none_property.py.jinja

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
{% macro check_type_for_construct(property, source) %}{{ source }} is None{% endmacro %}
66

7-
{% macro transform(property, source, destination, declare_type=True) %}
7+
{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
88
{{ destination }} = None
99
{% endmacro %}

Diff for: openapi_python_client/templates/property_templates/union_property.py.jinja

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ def _parse_{{ property.python_name }}(data: object) -> {{ property.get_type_stri
3939
{# For now we assume there will be no unions of unions #}
4040
{% macro check_type_for_construct(property, source) %}True{% endmacro %}
4141

42-
{% macro transform(property, source, destination, declare_type=True) %}
42+
{% macro transform(property, source, destination, declare_type=True, query_param=False) %}
4343
{% if not property.required or property.nullable %}
4444
{{ destination }}{% if declare_type %}: {{ property.get_type_string(json=True) }}{% endif %}
4545

4646
{% if not property.required %}
47-
if isinstance({{ source }}, Unset):
47+
if isinstance({{ source }}, Unset){% if query_param %} or {{ source }} is None{% endif %}:
4848
{{ destination }} = UNSET
4949
{% endif %}
5050
{% endif %}

0 commit comments

Comments
 (0)