-
Notifications
You must be signed in to change notification settings - Fork 5k
Add ability to proxy the reading and writing of models #50024
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?
Conversation
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.
Pull Request Overview
This PR adds the ability to inject custom proxy implementations for model serialization and deserialization, allowing callers to override default behaviors. Key modifications include:
- Integrating proxy resolution in deserialization and serialization methods across multiple model types.
- Updating tests and samples to validate proxy behavior for both simple and nested models.
- Enhancing the ModelReaderWriterOptions API to support proxy registration and lookup.
Reviewed Changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
ResourceProviderData.Serialization.cs | Uses proxy resolution during deserialization of ProviderResourceType elements. |
AvailabilitySetData.cs | Adds a new field and constructor parameter for additional raw data. |
AvailabilitySetData.Serialization.cs | Updates constructor call to include the new raw data dictionary. |
ResourceProviderDataProxy.cs | Implements a custom proxy for ResourceProviderData with modified serialization (omitting the "id" property). |
ProviderResourceTypeProxy.cs | Renames a property ("resourceType" to "resourceTypex") for proxy serialization. |
AvailabilitySetDataProxy.cs | Custom proxy for AvailabilitySetData that adds an extra property during serialization. |
ModelReaderWriterExtensions.cs | Modifies WriteObjectValue to resolve proxies via the provided options. |
ModelReaderWriterOptions.cs | Introduces proxy registration/resolution API to support custom model serialization behaviors. |
ModelWriterOfT.cs | Replaces direct model.Write with proxy resolution before writing. |
ModelReaderWriter.cs | Adjusts serialization and deserialization flows to resolve proxies appropriately. |
JsonModelConverter.cs, JsonCollectionWriter.cs, JsonCollectionReader.cs | Updated to call proxy resolution when reading/writing JSON models. |
sdk/core/System.ClientModel/src/ModelReaderWriter/ModelReaderWriterOptions.cs
Show resolved
Hide resolved
sdk/core/System.ClientModel/src/ModelReaderWriter/ModelReaderWriterOptions.cs
Show resolved
Hide resolved
sdk/core/System.ClientModel/src/ModelReaderWriter/ModelReaderWriterOptions.cs
Show resolved
Hide resolved
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
sdk/core/System.ClientModel/src/ModelReaderWriter/ModelReaderWriterOptions.cs
Outdated
Show resolved
Hide resolved
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.
LGTM
Reviving #45715
API Proposal: dotnet/runtime#115664
Add the ability to inject a proxy implementation for reading and writing a model type. This will replace the default implementation that lives on the model itself allowing a caller external to the library to adjust how things are written in some advanced scenarios.
Specific service need is AOAI wants the ability to control which properties of the OAI models it shares are serialized when sending to azure service. To do this they need to replace that implementation with their own custom implementation: