-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix: wrapper types for intersection types should not be serialized as objects #97
base: main
Are you sure you want to change the base?
fix: wrapper types for intersection types should not be serialized as objects #97
Conversation
@@ -178,10 +178,15 @@ class JsonSerializationWriter implements SerializationWriter { | |||
} | |||
if (key?.isNotEmpty ?? false) { | |||
final objectContents = {..._contents}; | |||
dynamic value = objectContents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand why we need this here?
If we look at the dotnet implementation (or other languages), it doesn't have such a flattening logic.
To me, it seems that the generated serialization code might be incorrect and not doing the appropriate routing.
Can you please share the schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, see, the dotnet abstractions have an IComposedTypeWrapper
and does serialization logic differently based on that. We don't have that yet, but we can align the Dart implementation with the C# impl if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please go ahead!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked both approaches and, at least to me, this seems to be the best way. Generation looks good, .NET just uses its types to do this kind of "unwrapping". In the end it results in the same JSON, so I think we're good now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like the implementations/generated code to be as aligned as possible between the different languages to ease up troubleshooting and other aspects if you don't mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We gain no benefit from this. Sure we can add the interface as a marker to those types, but it makes no difference in the serialization logic.
I also think this is related to #95. @wisamidris77 can you check if the changes in this branch also fix your issue? |
This reverts commit b717325.
c1a33c3
to
f4d9a33
Compare
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.