fix(json): Fix composed type (oneOf) serialization returning empty object #503
+27
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



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.