Skip to content

Commit 1814703

Browse files
sfowldbanty
authored andcommitted
fix: Indent of generated code for non-required lists. Thanks @sfowl! (openapi-generators#1050)
The `_transform` macro is called at three different places in this file, but one location was not similarly indented as the other two. This caused errors in the ruff post_hook like: ``` error: Failed to parse foo/models/foo_request.py:125:9: Expected an indented block after `if` statement ``` The generated code without the indent fix looks like: ``` if not isinstance(self.foo, Unset): _temp_foo = [] # <-- incorrect indent for foo_item_data in self.foo: foo_item: Union[None, int] foo_item = foo_item_data _temp_foo.append(foo_item) foo = (None, json.dumps(_temp_foo).encode(), 'application/json') ``` --------- Co-authored-by: Dylan Anthony <[email protected]>
1 parent f9dd79e commit 1814703

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

end_to_end_tests/baseline_openapi_3.0.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,14 @@
19611961
"title": "Some Required Number",
19621962
"type": "number"
19631963
},
1964+
"some_int_array": {
1965+
"title": "Some Integer Array",
1966+
"type": "array",
1967+
"items": {
1968+
"type": "integer",
1969+
"nullable": true
1970+
}
1971+
},
19641972
"some_array": {
19651973
"title": "Some Array",
19661974
"nullable": true,

end_to_end_tests/baseline_openapi_3.1.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,6 +1970,13 @@ info:
19701970
"title": "Some Number",
19711971
"type": "number"
19721972
},
1973+
"some_int_array": {
1974+
"title": "Some Integer Array",
1975+
"type": "array",
1976+
"items": {
1977+
"type": ["integer", "null"]
1978+
}
1979+
},
19731980
"some_array": {
19741981
"title": "Some Array",
19751982
"type": [ "array", "null" ],

openapi_python_client/templates/property_templates/list_property.py.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if not isinstance({{ source }}, Unset):
6060
{% else %}
6161
{{ destination }}: {{ type_string }} = UNSET
6262
if not isinstance({{ source }}, Unset):
63-
{{ _transform(property, source, destination, True, "to_dict") | indent(4)}}
63+
{{ _transform(property, source, destination, True, "to_dict") | indent(4)}}
6464
{% endif %}
6565
{% endmacro %}
6666

0 commit comments

Comments
 (0)