Skip to content

Conversation

@eli-bl
Copy link
Collaborator

@eli-bl eli-bl commented Jan 7, 2025

Resolves #1188.

The change is simply to store a list, rather than a generator expression.

The new models_init.py.jinja template in the end-to-end tests shows that this now works. Without the fix in openapi.py, this template is rendered with nothing under the Using "openapi.models" and Using "openapi.enums" headings.

This fix is somewhat important for our use case, because we need to put some code in models/__init__.py that is aware of what the model class names and modules are. Without the fix, the only way to get this would be to iterate over imports, which gives you strings like from .module_name import ClassName, and then parse those strings, which is workable but pretty clunky.

@eli-bl eli-bl requested a review from dbanty January 7, 2025 00:34
@eli-bl eli-bl force-pushed the issue1188-models-enums-iterable branch from f0c8b78 to 6b34737 Compare January 7, 2025 00:51
@chassing
Copy link

@dbanty, could you please review this PR? I also discovered this bug. 🙇

@dbanty dbanty added this pull request to the merge queue Mar 22, 2025
Merged via the queue into openapi-generators:main with commit 1177cf7 Mar 22, 2025
22 checks passed
micha91 pushed a commit to micha91/openapi-python-client that referenced this pull request May 13, 2025
…i-generators#1189)

Resolves openapi-generators#1188.

The change is simply to store a list, rather than a generator
expression.

The new `models_init.py.jinja` template in the end-to-end tests shows
that this now works. Without the fix in `openapi.py`, this template is
rendered with nothing under the `Using "openapi.models"` and `Using
"openapi.enums"` headings.

This fix is somewhat important for our use case, because we need to put
some code in `models/__init__.py` that is aware of what the model class
names and modules are. Without the fix, the only way to get this would
be to iterate over `imports`, which gives you strings like `from
.module_name import ClassName`, and then parse those strings, which is
workable but pretty clunky.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"openapi.models" and "openapi.enums" aren't usable in custom templates

3 participants