Skip to content

Commit b1b7dba

Browse files
Fix type errors
1 parent ddc512c commit b1b7dba

File tree

6 files changed

+48
-34
lines changed

6 files changed

+48
-34
lines changed

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/defaults_tests_defaults_post.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,32 +122,38 @@ def httpx_request(
122122
params: Dict[str, Any] = {
123123
"required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop,
124124
}
125-
if string_prop is not UNSET and string_prop is not None:
125+
if not isinstance(string_prop, Unset) and string_prop is not None:
126126
params["string_prop"] = string_prop
127-
if not_required_not_nullable_datetime_prop is not UNSET and not_required_not_nullable_datetime_prop is not None:
127+
if (
128+
not isinstance(json_not_required_not_nullable_datetime_prop, Unset)
129+
and json_not_required_not_nullable_datetime_prop is not None
130+
):
128131
params["not_required_not_nullable_datetime_prop"] = json_not_required_not_nullable_datetime_prop
129-
if not_required_nullable_datetime_prop is not UNSET and not_required_nullable_datetime_prop is not None:
132+
if (
133+
not isinstance(json_not_required_nullable_datetime_prop, Unset)
134+
and json_not_required_nullable_datetime_prop is not None
135+
):
130136
params["not_required_nullable_datetime_prop"] = json_not_required_nullable_datetime_prop
131-
if required_nullable_datetime_prop is not None:
137+
if json_required_nullable_datetime_prop is not None:
132138
params["required_nullable_datetime_prop"] = json_required_nullable_datetime_prop
133-
if date_prop is not UNSET and date_prop is not None:
139+
if not isinstance(json_date_prop, Unset) and json_date_prop is not None:
134140
params["date_prop"] = json_date_prop
135-
if float_prop is not UNSET and float_prop is not None:
141+
if not isinstance(float_prop, Unset) and float_prop is not None:
136142
params["float_prop"] = float_prop
137-
if int_prop is not UNSET and int_prop is not None:
143+
if not isinstance(int_prop, Unset) and int_prop is not None:
138144
params["int_prop"] = int_prop
139-
if boolean_prop is not UNSET and boolean_prop is not None:
145+
if not isinstance(boolean_prop, Unset) and boolean_prop is not None:
140146
params["boolean_prop"] = boolean_prop
141-
if list_prop is not UNSET and list_prop is not None:
147+
if not isinstance(json_list_prop, Unset) and json_list_prop is not None:
142148
params["list_prop"] = json_list_prop
143-
if union_prop is not UNSET and union_prop is not None:
149+
if not isinstance(json_union_prop, Unset) and json_union_prop is not None:
144150
params["union_prop"] = json_union_prop
145-
if union_prop_with_ref is not UNSET and union_prop_with_ref is not None:
151+
if not isinstance(json_union_prop_with_ref, Unset) and json_union_prop_with_ref is not None:
146152
params["union_prop_with_ref"] = json_union_prop_with_ref
147-
if enum_prop is not UNSET and enum_prop is not None:
153+
if not isinstance(json_enum_prop, Unset) and json_enum_prop is not None:
148154
params["enum_prop"] = json_enum_prop
149-
if model_prop is not UNSET and model_prop is not None:
150-
params["model_prop"] = json_model_prop
155+
if not isinstance(json_model_prop, Unset) and json_model_prop is not None:
156+
params.update(json_model_prop)
151157

152158
response = client.request(
153159
"post",

end_to_end_tests/golden-record-custom/custom_e2e/api/tests/optional_value_tests_optional_query_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def httpx_request(
4747
json_query_param = query_param
4848

4949
params: Dict[str, Any] = {}
50-
if query_param is not UNSET and query_param is not None:
50+
if not isinstance(json_query_param, Unset) and json_query_param is not None:
5151
params["query_param"] = json_query_param
5252

5353
response = client.request(

end_to_end_tests/golden-record/my_test_api_client/api/tests/defaults_tests_defaults_post.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,32 +98,38 @@ def _get_kwargs(
9898
params: Dict[str, Any] = {
9999
"required_not_nullable_datetime_prop": json_required_not_nullable_datetime_prop,
100100
}
101-
if string_prop is not UNSET and string_prop is not None:
101+
if not isinstance(string_prop, Unset) and string_prop is not None:
102102
params["string_prop"] = string_prop
103-
if not_required_not_nullable_datetime_prop is not UNSET and not_required_not_nullable_datetime_prop is not None:
103+
if (
104+
not isinstance(json_not_required_not_nullable_datetime_prop, Unset)
105+
and json_not_required_not_nullable_datetime_prop is not None
106+
):
104107
params["not_required_not_nullable_datetime_prop"] = json_not_required_not_nullable_datetime_prop
105-
if not_required_nullable_datetime_prop is not UNSET and not_required_nullable_datetime_prop is not None:
108+
if (
109+
not isinstance(json_not_required_nullable_datetime_prop, Unset)
110+
and json_not_required_nullable_datetime_prop is not None
111+
):
106112
params["not_required_nullable_datetime_prop"] = json_not_required_nullable_datetime_prop
107-
if required_nullable_datetime_prop is not None:
113+
if json_required_nullable_datetime_prop is not None:
108114
params["required_nullable_datetime_prop"] = json_required_nullable_datetime_prop
109-
if date_prop is not UNSET and date_prop is not None:
115+
if not isinstance(json_date_prop, Unset) and json_date_prop is not None:
110116
params["date_prop"] = json_date_prop
111-
if float_prop is not UNSET and float_prop is not None:
117+
if not isinstance(float_prop, Unset) and float_prop is not None:
112118
params["float_prop"] = float_prop
113-
if int_prop is not UNSET and int_prop is not None:
119+
if not isinstance(int_prop, Unset) and int_prop is not None:
114120
params["int_prop"] = int_prop
115-
if boolean_prop is not UNSET and boolean_prop is not None:
121+
if not isinstance(boolean_prop, Unset) and boolean_prop is not None:
116122
params["boolean_prop"] = boolean_prop
117-
if list_prop is not UNSET and list_prop is not None:
123+
if not isinstance(json_list_prop, Unset) and json_list_prop is not None:
118124
params["list_prop"] = json_list_prop
119-
if union_prop is not UNSET and union_prop is not None:
125+
if not isinstance(json_union_prop, Unset) and json_union_prop is not None:
120126
params["union_prop"] = json_union_prop
121-
if union_prop_with_ref is not UNSET and union_prop_with_ref is not None:
127+
if not isinstance(json_union_prop_with_ref, Unset) and json_union_prop_with_ref is not None:
122128
params["union_prop_with_ref"] = json_union_prop_with_ref
123-
if enum_prop is not UNSET and enum_prop is not None:
129+
if not isinstance(json_enum_prop, Unset) and json_enum_prop is not None:
124130
params["enum_prop"] = json_enum_prop
125-
if model_prop is not UNSET and model_prop is not None:
126-
params["model_prop"] = json_model_prop
131+
if not isinstance(json_model_prop, Unset) and json_model_prop is not None:
132+
params.update(json_model_prop)
127133

128134
return {
129135
"url": url,

end_to_end_tests/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def _get_kwargs(
2424
json_query_param = query_param
2525

2626
params: Dict[str, Any] = {}
27-
if query_param is not UNSET and query_param is not None:
27+
if not isinstance(json_query_param, Unset) and json_query_param is not None:
2828
params["query_param"] = json_query_param
2929

3030
return {

openapi_python_client/parser/properties/model_property.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ModelProperty(Property):
2020
_json_type_string: ClassVar[str] = "Dict[str, Any]"
2121

2222
template: ClassVar[str] = "model_property.pyi"
23+
is_dict: ClassVar[bool] = True
2324

2425
def get_base_type_string(self) -> str:
2526
return self.reference.class_name

openapi_python_client/templates/endpoint_macros.pyi

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ params: Dict[str, Any] = {
3333
}
3434
{% for property in endpoint.query_parameters %}
3535
{% if not property.required or property.nullable %}
36-
if {% if not property.required %}{{ property.python_name }} is not UNSET and {% endif %}{{ property.python_name }} is not None:
37-
{% if property.template %}
38-
params["{{ property.name }}"] = {{ "json_" + property.python_name }}
36+
{% set property_name = "json_" + property.python_name if property.template else property.python_name %}
37+
if {% if not property.required %}not isinstance({{ property_name }}, Unset) and {% endif %}{{ property_name }} is not None:
38+
{% if property.is_dict %}
39+
params.update({{ property_name }})
3940
{% else %}
40-
params["{{ property.name }}"] = {{ property.python_name }}
41+
params["{{ property.name }}"] = {{ property_name }}
4142
{% endif %}
4243
{% endif %}
4344
{% endfor %}

0 commit comments

Comments
 (0)