Skip to content

Commit 0e1afa8

Browse files
authored
fix: Generate parameters to generated client without adding None BNCH-22940 (#77)
Upstream generates the client this way, and in a parallel benchling-sdk ticket we'll be doing a conversion to UNSET for None parameters in the service layer. Making this change in the fork in the meantime will keep us in a good state.
1 parent 248d566 commit 0e1afa8

File tree

8 files changed

+8
-12
lines changed

8 files changed

+8
-12
lines changed

openapi_python_client/parser/properties/property.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ def get_type_string(self, no_optional: bool = False, query_parameter: bool = Fal
6262
if self.nullable:
6363
return f"Union[Unset, None, {type_string}]"
6464
else:
65-
if query_parameter:
66-
# For query parameters, None has the same meaning as Unset
67-
return f"Union[Unset, None, {type_string}]"
68-
else:
69-
return f"Union[Unset, {type_string}]"
65+
return f"Union[Unset, {type_string}]"
7066

7167
def get_instance_type_string(self) -> str:
7268
"""Get a string representation of runtime type that should be used for `isinstance` checks"""

openapi_python_client/templates/property_templates/date_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if _{{ property.python_name }} is not None:
1717
{% else %}
1818
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET
1919
if not isinstance({{ source }}, Unset):
20-
{% if property.nullable or query_parameter %}
20+
{% if property.nullable %}
2121
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
2222
{% else %}
2323
{{ destination }} = {{ source }}.isoformat()

openapi_python_client/templates/property_templates/datetime_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if _{{ property.python_name }} is not None:
2626
{% else %}
2727
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET
2828
if not isinstance({{ source }}, Unset):
29-
{% if property.nullable or query_parameter %}
29+
{% if property.nullable %}
3030
{{ destination }} = {{ source }}.isoformat() if {{ source }} else None
3131
{% else %}
3232
{{ destination }} = {{ source }}.isoformat()

openapi_python_client/templates/property_templates/enum_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if _{{ property.python_name }} is not None and _{{ property.python_name }} is no
2121
{% else %}
2222
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET
2323
if not isinstance({{ source }}, Unset):
24-
{% if property.nullable or query_parameter %}
24+
{% if property.nullable %}
2525
{{ destination }} = {{ source }}.value if {{ source }} else None
2626
{% else %}
2727
{{ destination }} = {{ source }}.value

openapi_python_client/templates/property_templates/file_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{% else %}
1717
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET
1818
if not isinstance({{ source }}, Unset):
19-
{% if property.nullable or query_parameter %}
19+
{% if property.nullable %}
2020
{{ destination }} = {{ source }}.to_tuple() if {{ source }} else None
2121
{% else %}
2222
{{ destination }} = {{ source }}.to_tuple()

openapi_python_client/templates/property_templates/list_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ else:
4848
{% else %}
4949
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET
5050
if not isinstance({{ source }}, Unset):
51-
{% if property.nullable or query_parameter %}
51+
{% if property.nullable %}
5252
if {{ source }} is None:
5353
{{ destination }} = None
5454
else:

openapi_python_client/templates/property_templates/model_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if {% if property.nullable %}_{{ property.python_name }} is not None{% endif %}{
2727
{% else %}
2828
{{ destination }}{% if declare_type %}: {{ property.get_type_string(query_parameter=query_parameter, json=True) }}{% endif %} = UNSET
2929
if not isinstance({{ source }}, Unset):
30-
{% if property.nullable or query_parameter %}
30+
{% if property.nullable %}
3131
{{ destination }} = {{ source }}.to_dict() if {{ source }} else None
3232
{% else %}
3333
{{ destination }} = {{ source }}.to_dict()

openapi_python_client/templates/property_templates/union_property.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _parse_{{ property.python_name }}(data: {{ property.get_type_string(json=Tru
4545
if isinstance({{ source }}, Unset):
4646
{{ destination }} = UNSET
4747
{% endif %}
48-
{% if property.nullable or (query_parameter and not property.required) %}
48+
{% if property.nullable %}
4949
{% if property.required %}
5050
if {{ source }} is None:
5151
{% else %}{# There's an if UNSET statement before this #}

0 commit comments

Comments
 (0)