Repository navigation
Description
Clear and concise description of the problem
When a generated model property had a public setter in the last contract but the current generation emits it without one, the setter removal is a source and binary breaking change (set_X no longer exists). This usually happens for incidental reasons rather than an intentional change to the property's writability, because the generator derives setter presence from model usage and requiredness (PropertyProvider.PropertyHasSetter):
- Usage change: a round-trip model becomes output-only (all setters dropped) or input-only (required properties lose their setters and move to the constructor), e.g. after an operation is removed or a request body is reshaped.
- Requiredness change: an optional property becomes required on an input-only model.
- Collection nullability change: a nullable collection property becomes non-nullable.
- Generator migration: a library moving to this generator can hit different setter rules than the generator that produced its last contract.
Today the only remedies are accepting the break in the ApiCompat baseline or re-declaring the entire property in custom code (see #11804).
Proposal
Use the model's LastContractView to restore a missing property setter, with the same accessibility it had in the last contract, only when it is safe to do so. The last contract is already loaded with full metadata, and NamedTypeSymbolProvider records Body.HasSetter, the setter accessibility, and IsInitOnly for each property, so the required information is available.
⚠️ Safety requirement
A restored setter must never introduce unintended behavior. If assigning through the setter would not behave the way a caller expects — for example, the value would be silently dropped, could produce an invalid request, or the generated code would not compile — the setter must not be restored, and the breaking change should continue to surface through ApiCompat as it does today.
Restore the setter only when all of the following hold:
- The last-contract setter was part of the public API (
publicorprotected). Private/internal setters are also imported from the last contract and must be ignored. - The last-contract setter was not
init. - The property is not read-only in the spec (
InputProperty.IsReadOnly, e.g.@visibility(Lifecycle.Read)). Read-only properties are only serialized whenoptions.Format != "W", so a value assigned through a restored setter would be silently dropped from service requests. - The property is not a required, non-nullable constant/literal. A setter would allow callers to send a value the service does not accept.
- The enclosing type is not a
readonly struct. - The generated serialization correctly handles every value the setter can accept (e.g. a non-nullable collection whose serialization assumes a non-null value).
- The property type matches the last contract (after the existing property type back-compat is applied).
- The property is not already defined in custom code.
- The setter removal has not been accepted in the ApiCompat baseline.
When a setter is restored, emit an informational back-compat diagnostic. When a setter is intentionally not restored because one of the safety checks failed, emit a diagnostic explaining why.
Implementation notes
- Apply the decision where the property body is built (the
PropertyProviderconstructor already resolves the matching last-contract property for name preservation) so that docs ("Gets or sets"), constructors, serialization, the model factory, and base/derived property override handling all observe the same setter state. Properties with exact names also need a last-contract lookup. - Tests should cover a restored setter and each of the skipped cases above.
Checklist
- Follow our Code of Conduct
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
Activity
github-actions commentedon Nov 16, 2026
🎯 Issue Triage
This requests C# client emitter back-compat support that restores removed public or protected model property setters from
LastContractViewonly when assignment remains safe and behaviorally valid.Category: Feature Request
Area:
emitter:client:csharp🔍 Analysis
The affected component is
@typespec/http-client-csharp, particularlyPropertyProvider, last-contract symbol metadata, generated constructors/documentation, model factories, inheritance handling, serialization, diagnostics, and ApiCompat baselines. The setter loss is caused by current-generation usage, requiredness, or nullability rules diverging from the previously shipped contract; the proposal correctly requires preserving the break when restoration could drop values, permit invalid requests, or produce invalid code.No strong duplicate was found. #7241 is the broader parent for back-compat scenarios, while #11804 is related custom-property support rather than the same setter-restoration request.
📝 Suggested next steps
jorgerangel-msft commentedon Nov 17, 2026
Safe to restore