Skip to content

fix(sdk-generator): deserialize ref-or-object union responses in Python - #124

Merged
calvin-archastro merged 1 commit into
mainfrom
fix/python-union-response-shape
Nov 1, 2026
Merged

calvin-archastro merged 1 commit into
mainfrom
fix/python-union-response-shape

Conversation

@calvin-archastro

Copy link
Copy Markdown
Contributor

Problem

Regenerating archastro-python from the refreshed platform spec (#121) fails: GET /api/v1/orgs/{org}/task_epics returns a union of an inline summary object and a $ref collection (chosen by the representation query param). pythonResponseShape deliberately throws for refs buried in unions, so Python generation aborts.

Change

  • New model_union shape for unions that mix at least one $ref and at least one plain object. The runtime validates against Model | dict[str, Any] (refs first); contract tests assert BaseModel or dict.
  • Go and Swift wrappers map model_union to untyped (JSON value), unchanged in behavior for them.
  • Pure $ref | $ref unions still fail generation (existing test untouched).

Scope / risk / testing

Generator only; Python/Go/Swift backends read the shared classifier. Low-medium risk. New unit test for the shape and the response_type expression. Local npm run build, npm run lint, npm test pass. Verified end to end: regenerated archastro-python with this build; ruff clean, unit tests pass, 3564 contract tests pass.

🤖 Generated with Claude Code

Python generation threw for GET /orgs/{org}/task_epics, whose 200 is a
union of an inline summary object and a $ref collection (selected by the
representation query param). Add a model_union response shape validated as
`Model | dict[str, Any]`; Go and Swift keep treating it as untyped JSON.
Pure $ref unions still fail generation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@calvin-archastro
calvin-archastro merged commit 25b6af5 into main Nov 1, 2026
2 checks passed
@calvin-archastro
calvin-archastro deleted the fix/python-union-response-shape branch November 1, 2026 12:19
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.

1 participant