-
Notifications
You must be signed in to change notification settings - Fork 24
fix(json): Fix composed type (oneOf) serialization returning empty object #503
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
base: main
Are you sure you want to change the base?
fix(json): Fix composed type (oneOf) serialization returning empty object #503
Conversation
…ject
When serializing composed types (oneOf wrappers/union types) using
write_object_value(None, value), the method was incorrectly using
temp_writer.writer (which is empty for composed types) instead of
temp_writer.value (which contains the serialized content).
The fix checks if temp_writer.value is available (for composed types)
and falls back to temp_writer.writer (for regular objects with properties).
This bug caused oneOf discriminated unions to serialize as {} instead of
the actual object content, breaking API requests that use composed types.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@sh3r4rd please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
|



Summary
This PR fixes a bug where composed types (oneOf/union types) would serialize to
{}instead of the actual object content when usingwrite_object_value(None, value).Problem
When serializing composed types (oneOf wrappers/union types), the
write_object_valuemethod was incorrectly usingtemp_writer.writer(which is empty for composed types) instead oftemp_writer.value(which contains the serialized content).Example of the bug
Given a composed type like:
When serializing, the output would be
{}instead of the actual variant content like{"kind": "question", "header": "...", ...}.Root cause
In
write_object_value, whenvalue.serialize(temp_writer)is called:temp_writer.writer(a dict with keys)write_object_value(None, inner_value), data is written totemp_writer.valueThe original code always used
temp_writer.writer:Solution
Check if
temp_writer.valueis available (for composed types) and fall back totemp_writer.writer(for regular objects):Testing
test_write_composed_type_with_no_keythat verifies composed types serialize correctlyImpact
This bug affects any API that uses oneOf discriminated unions in request bodies. Without this fix, the serialized JSON is empty (
{}), causing API validation errors.