feat(python): add flatten_union_request_bodies config flag for Stripe-style request kwargs#15498
feat(python): add flatten_union_request_bodies config flag for Stripe-style request kwargs#15498patrickthornton wants to merge 14 commits intomainfrom
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
🌱 Seed Test SelectorSelect languages to run seed tests for:
How to use: Click the ⋯ menu above → "Edit" → check the boxes you want → click "Update comment". Tests will run automatically and snapshots will be committed to this PR. |
SDK Generation Benchmark ResultsComparing PR branch against median of 5 nightly run(s) on Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
…odies Updates the v1 docstring snippet generator and the v2 dynamic-snippets generator (used by reference.md, wire tests, and dynamic snippet tests) to honor flatten_union_request_bodies. Previously these example paths still emitted `request=<UnionVariant>(...)` even when the function signature accepted flat kwargs, producing examples that would raise `TypeError: unexpected keyword argument 'request'` at call time.
- Drop the local _wire_string helper and reuse get_wire_value from name_resolver. - Unify the destructuring path shared by flatten_union_request_bodies and inline_request_params so example_type_reference.shape.get_as_union() runs once instead of twice. - Note the deliberate single_property no-op so the limitation is explicit.
Summary
flatten_union_request_bodiesconfig flag (defaultfalse). When enabled, endpoints whose referenced request body is a discriminatedoneOf/union expose all variants' fields as flat kwargs — Stripe-style — rather than a singlerequest: Union[...]parameter.connections.create(53-strategyoneOf) — the new spec was technically correct but caused a major DX regression by collapsing the kwargs the customer previously had. Flat flattening restores idiomatic kwargs.Example
Customer config:
Before:
After:
The discriminator becomes
Union[Literal["ad"], Literal["adfs"], ...]. Per-variant fields with the same wire name are merged (conflicting types are unioned). Loss of cross-field type narrowing matches Stripe'sPaymentMethodCreateParamstradeoff.Test plan
unions:flatten-union-request-bodiesexercises the path with the existingShape(circle/square) discriminated union.name=,strategy=,options=, etc.) with norequest=wrapper.🤖 Generated with Claude Code