Summary
The C# generator should preserve the original parameter names in static ModelFactory methods even when the underlying property is renamed (for any reason — @@clientName, spec rename, generator naming-rule change, etc.). Renaming a parameter is source-breaking for callers using named arguments and is not flagged by ApiCompat / binary-compat tooling.
Background
When a flattened (or otherwise surfaced) property changes its public C# name, the generated ModelFactory parameter today changes accordingly (camelCase of the new property name). For example, a property renamed from ProfileType to CertificateProfileType causes the factory parameter to change from profileType to certificateProfileType. Existing source code such as:
ArmFooModelFactory.FooData(profileType: CertificateProfileType.PublicTrust);
stops compiling, even though no behavior changed.
This is independent of where the C# generator is consumed (Azure data-plane, Azure mgmt, unbranded). The behavior originates in the base http-client-csharp generator.
Proposal
The generator should retain the previously emitted parameter name when the same logical parameter exists in both old and new versions. Approaches to consider:
- Option A (preferred): Track previously emitted parameter names (e.g., from the existing api/*.cs surface or an api-baseline) and reuse them when the parameter still exists.
- Option B: Provide an explicit opt-in decorator/attribute to override the parameter name on the factory method.
- Option C: Make parameter-name preservation part of the broader backward-compat feature already used for property renames.
Workaround today
For each factory whose parameter name needs to be preserved, hand-copy the generated factory method into a partial class with the desired parameter name. The generator's CustomCodeView correctly suppresses the duplicate when the signatures differ only by parameter name. No [CodeGenSuppress] is needed.
Example (real, in Azure mgmt SDK): sdk/artifactsigning/Azure.ResourceManager.ArtifactSigning/src/Custom/ArmArtifactSigningModelFactory.cs in azure-sdk-for-net.
Acceptance
- The generator preserves the original parameter name on
ModelFactory methods when only the name has changed.
- Existing custom workarounds for parameter-name preservation can be deleted.
- Regression test under
packages/http-client-csharp covers the scenario.
Notes
Originally filed as Azure/azure-sdk-for-net#58533. Refiled here because the feature belongs to the base C# generator.
Summary
The C# generator should preserve the original parameter names in static
ModelFactorymethods even when the underlying property is renamed (for any reason —@@clientName, spec rename, generator naming-rule change, etc.). Renaming a parameter is source-breaking for callers using named arguments and is not flagged by ApiCompat / binary-compat tooling.Background
When a flattened (or otherwise surfaced) property changes its public C# name, the generated
ModelFactoryparameter today changes accordingly (camelCase of the new property name). For example, a property renamed fromProfileTypetoCertificateProfileTypecauses the factory parameter to change fromprofileTypetocertificateProfileType. Existing source code such as:stops compiling, even though no behavior changed.
This is independent of where the C# generator is consumed (Azure data-plane, Azure mgmt, unbranded). The behavior originates in the base
http-client-csharpgenerator.Proposal
The generator should retain the previously emitted parameter name when the same logical parameter exists in both old and new versions. Approaches to consider:
Workaround today
For each factory whose parameter name needs to be preserved, hand-copy the generated factory method into a partial class with the desired parameter name. The generator's CustomCodeView correctly suppresses the duplicate when the signatures differ only by parameter name. No
[CodeGenSuppress]is needed.Example (real, in Azure mgmt SDK):
sdk/artifactsigning/Azure.ResourceManager.ArtifactSigning/src/Custom/ArmArtifactSigningModelFactory.csin azure-sdk-for-net.Acceptance
ModelFactorymethods when only the name has changed.packages/http-client-csharpcovers the scenario.Notes
Originally filed as Azure/azure-sdk-for-net#58533. Refiled here because the feature belongs to the base C# generator.