-
-
Notifications
You must be signed in to change notification settings - Fork 228
Generated code lacks import of typing.cast for required const properties #1150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
benweint
added a commit
to benweint/openapi-python-client
that referenced
this issue
Oct 28, 2024
benweint
added a commit
to benweint/openapi-python-client
that referenced
this issue
Oct 28, 2024
github-merge-queue bot
pushed a commit
that referenced
this issue
Oct 28, 2024
…e template (#1153) The [template](https://github.com/openapi-generators/openapi-python-client/blob/main/openapi_python_client/templates/property_templates/const_property.py.jinja#L2) for `const` properties uses `cast` unconditionally, but the import for `cast` in `ConstProperty.get_imports` was conditioned on whether the property was required or not, leading to broken generated code for required const properties. I'd be happy to add a test for this if desired! A cursory glance suggests that maybe the end_to_end tests would be the right place? Resolves #1150
micha91
pushed a commit
to micha91/openapi-python-client
that referenced
this issue
May 13, 2025
…e template (openapi-generators#1153) The [template](https://github.com/openapi-generators/openapi-python-client/blob/main/openapi_python_client/templates/property_templates/const_property.py.jinja#L2) for `const` properties uses `cast` unconditionally, but the import for `cast` in `ConstProperty.get_imports` was conditioned on whether the property was required or not, leading to broken generated code for required const properties. I'd be happy to add a test for this if desired! A cursory glance suggests that maybe the end_to_end tests would be the right place? Resolves openapi-generators#1150
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
When an input schema has a required
const
property, the generated code does makes calls totyping.cast
, but does not import it, leading to failures when trying to runruff
over the generated code.OpenAPI Spec File
Desktop (please complete the following information):
main
(also present in latest release, 0.21.6)Additional context
Removing
type
from therequired
field list in the example above makes the problem disappear - in this case,cast
is still used, but is properly imported.The text was updated successfully, but these errors were encountered: