Skip to content

unable to customize base type of generated model to a non-generated type #9234

@live1206

Description

@live1206

In mgmt, we have a requirement to mitigate breaking changes regarding base type of a generated model, details

public partial class KeyVaultData : TrackedResourceData

The customized base type is Azure.ResourceManager.Models.TrackedResourceData, which is not generated during the current generation.

But in MTG, we have the check to ensure the custom base type is either from input model or generated model.

// If the custom base type doesn't have a resolved namespace, then try to resolve it from the input model map.
// This will happen if a model is customized to inherit from another generated model, but that generated model
// was not also defined in custom code so Roslyn does not recognize it.
if (string.IsNullOrEmpty(baseType.Namespace))
{
if (CodeModelGenerator.Instance.TypeFactory.InputModelTypeNameMap.TryGetValue(baseType.Name, out var baseInputModel))
{
baseType = CodeModelGenerator.Instance.TypeFactory.CreateCSharpType(baseInputModel);
}
}
if (baseType != null && CodeModelGenerator.Instance.TypeFactory.CSharpTypeMap.TryGetValue(
baseType,
out var customBaseType) &&
customBaseType is ModelProvider customBaseModel)
{
return customBaseModel;
}
}

I think the issue here is, we don't have a provider to represent such kind of type, such as InheritableSystemObjectModelProvider in mgmt.

Metadata

Metadata

Assignees

Labels

emitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions