Skip to content

fix: wrapper types for intersection types should not be serialized as objects#97

Merged
baywet merged 9 commits into
microsoft:mainfrom
ricardoboss:fixes/nested-intersection-type-serialization
Mar 7, 2025
Merged

fix: wrapper types for intersection types should not be serialized as objects#97
baywet merged 9 commits into
microsoft:mainfrom
ricardoboss:fixes/nested-intersection-type-serialization

Conversation

@ricardoboss

Copy link
Copy Markdown
Contributor

This fixes an edge case I have seen with the OpenAI API spec.

Some models have an intersection type property. This causes a wrapper type to be generated that holds a property for each possible type in the intersection.

Currently, the serializer writes this wrapper type as its own object. The correct serialization would "flatten" this type, so only its value remains.

@ricardoboss ricardoboss requested a review from a team as a code owner March 5, 2025 00:37
Comment thread packages/microsoft_kiota_serialization_json/CHANGELOG.md Outdated
@ricardoboss

ricardoboss commented Mar 5, 2025

Copy link
Copy Markdown
Contributor Author

I also think this is related to #95. @wisamidris77 can you check if the changes in this branch also fix your issue?

@ricardoboss ricardoboss force-pushed the fixes/nested-intersection-type-serialization branch from c1a33c3 to f4d9a33 Compare March 5, 2025 19:39
@ricardoboss

Copy link
Copy Markdown
Contributor Author

baywet
baywet previously approved these changes Mar 7, 2025

@baywet baywet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for providing more context. After doing a comparison with dotnet I think you're implementation is correct.
We don't need the marker interface since it's empty and would not provide much here.
And we can rely on the shape of the serialized value to know whether we need to unwrap a scalar value instead.

@baywet baywet enabled auto-merge (squash) March 7, 2025 17:58
baywet
baywet previously approved these changes Mar 7, 2025
@baywet baywet merged commit 41a5df9 into microsoft:main Mar 7, 2025
@release-please release-please Bot mentioned this pull request Mar 7, 2025
@ricardoboss ricardoboss deleted the fixes/nested-intersection-type-serialization branch March 9, 2025 19:10
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.

2 participants