Skip to content

fix: avoid orphan else in optional union JSON body transform - #1521

Open
EnesKartal wants to merge 1 commit into
openapi-generators:mainfrom
EnesKartal:fix/1520-anyof-required-only-body
Open

EnesKartal wants to merge 1 commit into
openapi-generators:mainfrom
EnesKartal:fix/1520-anyof-required-only-body

Conversation

@EnesKartal

Copy link
Copy Markdown

Fixes #1520.

Summary

  • In union_property.py.jinja (transform macro), initialize ns.contains_modified_properties as not property.required and not skip_unset so that when skip_unset=True skips the if isinstance(..., Unset): branch (as in endpoint_macros.py.jinja json_body), no orphan else: is emitted when all union members lack a transform macro.
  • When not property.required and skip_unset is true, guard fallback and trailing branches with if not isinstance(..., Unset): / elif not isinstance(..., Unset): / elif isinstance(..., ...): instead of falling into an unconditional assignment or else:.
  • Add regression tests in tests/test_templates/test_endpoint_macros.py.
  • Verified locally with pytest tests, end_to_end_tests/test_end_to_end.py (all 5 snapshots passing), ruff check, ruff format --check, and mypy openapi_python_client.

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.

anyOf of required-only members in a request body generates unparsable code ("ruff failed")

1 participant