Skip to content

Commit 013eddb

Browse files
authored
fix: Sort lazy imports to increase stability of generated code (#1378)
Lazy imports of models aren't sorted, which causes them to be unstable and change from run to run. This is distracting in situations where you have a CI action automatically generating an API client and passing it as a PR to another repo. This PR fixes this.
1 parent 7c037bb commit 013eddb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

openapi_python_client/templates/model.py.jinja

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ from ..types import UNSET, Unset
1616
{{ relative }}
1717
{% endfor %}
1818

19-
{% for lazy_import in model.lazy_imports %}
19+
{% for lazy_import in model.lazy_imports | sort %}
2020
{% if loop.first %}
2121
if TYPE_CHECKING:
2222
{% endif %}
@@ -173,7 +173,7 @@ return field_dict
173173

174174
@classmethod
175175
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
176-
{% for lazy_import in model.lazy_imports %}
176+
{% for lazy_import in model.lazy_imports | sort %}
177177
{{ lazy_import }}
178178
{% endfor %}
179179
{% if (model.required_properties or model.optional_properties or model.additional_properties) %}

0 commit comments

Comments
 (0)