Fix MRW JSON write core override for custom bases#11098
Open
live1206 wants to merge 1 commit into
Open
Conversation
commit: |
Contributor
|
No changes needing a change description found. |
60f496e to
fe42ffe
Compare
Detect overridable JsonModelWriteCore methods on custom and framework base types so derived model serialization emits override instead of hiding the base member. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fe42ffe to
d0c358f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes MRW JSON serialization generation when a serialization provider is constructed before its model's
BaseModelProvideris available.MrwSerializationTypeDefinitionpreviously cached the JSON override decision in the constructor. In customization/visitor scenarios, the model can later resolve to aSystemObjectModelProviderbase. One example is an Azure management model customized to inherit fromTrackedResourceData: the generated model declaration can correctly inherit from the system base, but the serialization provider still uses the stale constructor-time decision and emitsprotected virtual JsonModelWriteCore(...), hiding the inherited base method.This keeps the existing
BaseModelProvider != nullbehavior and evaluates it when JSON serialization methods are built, after the delayed base provider can be resolved. It also makes the JSON/Persistable serialization interfaceCSharpTypes lazy so the constructor does not force_model.Typeand cache a type before the delayed base is available.The XML path intentionally keeps its existing constructor-scoped behavior instead of broadly late-emitting
internal override XmlModelWriteCore(...)for external/system bases, where that XML core method may not exist or be accessible.Validation
dotnet test /home/huwe/src/typespec/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj --filter JsonModelWriteCore_IsOverride_WhenBaseProviderIsResolvedAfterSerialization --no-restoredotnet test /home/huwe/src/typespec/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj --filter "SystemObjectModelSerializationTests|XmlSerializationTests|XmlSerializationCustomizationTests" --no-restoredotnet test eng/packages/http-client-csharp-mgmt/generator/Azure.Generator.Management/test/Azure.Generator.Mgmt.Tests.csproj --filter ResourceDataModelWithCustomTrackedResourceBaseOverridesSerialization