Repository navigation
[C#] Emit Obsolete attributes for deprecated model properties - #12523
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Deprecation handling leaves unsuppressed warnings in generated inheritance and property-access paths that break warnings-as-errors builds, and lacks compatibility guards for previously published properties.
3 open issues
What changed in this PR
This PR addresses #12522 by carrying property deprecation metadata through the C# emitter and generating [Obsolete(message)] attributes so SDK consumers receive compiler warnings.
Changes:
- Preserve exact deprecation messages through serialization and property generation.
- Cover ordinary and renamed models, handwritten attributes, and non-deprecated properties.
- Update generated samples and suppress intentional deprecated-property references in tests.
| File | Description |
|---|---|
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/tspCodeModel.json |
Records property deprecation messages. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/RenamedModelCustom.Serialization.cs |
Suppresses warnings around deprecated-property serialization. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/RenamedModelCustom.cs |
Adds the attribute and constructor warning suppressions. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/src/Generated/Models/CurrentDetails.cs |
Emits an attribute with an escaped message. |
packages/http-client-csharp/generator/TestProjects/Local/Sample-TypeSpec/Sample-TypeSpec.tsp |
Adds deprecated-property sample declarations. |
packages/http-client-csharp/generator/TestProjects/Local.Tests/CustomizationTests.cs |
Checks emitted messages and unaffected properties. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TypeProviderTests.cs |
Tests metadata, attributes, and customization handling. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/test/Providers/TestData/TypeProviderTests/DeprecatedPropertiesPreserveMessagesAndCustomizations/Custom.cs |
Supplies a renamed model with a handwritten attribute. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator/src/Providers/PropertyProvider.cs |
Adds deprecation attributes to generated properties. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputModelPropertyConverter.cs |
Deserializes property deprecation messages. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/InputModelProperty.cs |
Stores property deprecation metadata. |
packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Sample_TypeSpec/RenamedModelTests.cs |
Suppresses intentional deprecated-property usage in tests. |
packages/http-client-csharp/emitter/test/Unit/model-type.test.ts |
Tests absent, empty, and escaped deprecation messages. |
packages/http-client-csharp/emitter/src/type/input-type.ts |
Extends the property metadata interface. |
packages/http-client-csharp/emitter/src/lib/type-converter.ts |
Reads property deprecation from TypeSpec. |
Review effort: Balanced
commit: |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
No changes needing a change description found. |
There was a problem hiding this comment.
🟡 Changes recommended
Unsuppressed deprecation warnings in generated property forwarding, exploded queries, and paging helpers break warnings-as-errors builds, while lazy attribute filtering can discard unrelated attributes.
4 open issues
3 resolved since last review
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because public API signature changes break source and binary compatibility for supported generator extensions, including runtime failures in previously compiled plugins.
No open issues 🎉
Review effort: Balanced
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Re: the review summary's note about a replaced public overload. Fixed in c8b9fc1. I restored the public --generated by Copilot |
We don't need to retain the public overload for backwards compatibililty. Revert this commit. |
This reverts commit c8b9fc1. The original public overload does not need to be kept for backward compatibility. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Reverted in f698371, so the restored Also fixed the issue in the latest review summary in 2a1a28f. The last-contract check only looked at properties declared directly on the model's last-contract type. Suppose a property was inherited from a base class in the last contract, such as --generated by Copilot |
There was a problem hiding this comment.
🟡 Changes recommended
Replacing the public four-parameter GetPropertyExpression overload breaks existing source callers and compiled generator plugins; it should remain as a forwarding wrapper alongside the new overload.
1 open issue
Review effort: Balanced


Property-level
#deprecatedmessages were dropped during generation, leaving consumers without compiler warnings.[Obsolete(message)]on ordinary and renamed/customized models, reusing existing warning suppressions for generated references.For
#deprecated "Use replacement instead.", emit:[Obsolete]attribute for properties marked with#deprecated#12522