You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[http-client-csharp] Emit Obsolete attributes for deprecated APIs - #12394
Emit warning-only Obsolete attributes from TypeSpec #deprecated metadata on models, fixed/extensible enums, and synchronous/asynchronous protocol and convenience methods. Preserve messages, including empty strings and C# escaping.
Preserve the last released GA contract: existing APIs that were not obsolete do not gain the attribute. Apply the same rule after parameter reordering and to compatibility overloads. New APIs and previously experimental APIs can be marked obsolete; already obsolete APIs use the current message.
Respect customization-supplied attributes without duplicating them on partial implementations.
Suppress obsolete-reference diagnostics within generated implementation code while retaining consumer warnings.
Add metadata, provider, output-baseline, customization, compatibility, and generated-library coverage; regenerate the sample and all Spector libraries.
Validation
Package build and API extraction passed; the generator solution, including generated libraries, builds with warnings as errors.
Emitter: 396 passed, 2 skipped (serial run to avoid an existing five-second test timeout under concurrent builds).
Repository/package formatting, emitter type-aware oxlint, and Cop checks passed. The package's existing ESLint script references an unavailable tool, so linting used the repository's configured oxlint instead.
A separate consumer build reported the expected CS0618 diagnostics for the model, both enum forms, and the operation.
Windows validation used temporary drive mappings to avoid existing long-path limitations. Regeneration reported restore/artifact-path warnings for some long Spector paths; the subsequent shortened-path solution build succeeded.
Preserve non-obsolete GA contracts and compatibility overloads while exposing TypeSpec deprecation messages on new APIs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep customization-owned Obsolete attributes on the defining declaration in the shared partial-signature builder, covering non-client methods as well as operation methods.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
If the GA contract contains obsolete Read(int value) and non-obsolete Read(int value, bool added = false), this early filtering removes the current deprecation message, so BackCompatHelper.cs:534–543 strips Obsolete from the restored one-parameter overload. Defer GA filtering to the existing post-overload pass in TypeProvider.cs:1254–1263 so the stable signature stays unchanged while the already-obsolete overload retains the current message.
Suppress all experimental and obsolete diagnostics on generated model registrations. Defer GA method filtering until after compatibility overload restoration so previously obsolete overloads retain the current message.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Fixed the mixed GA-overload case from the latest review in fb5bf95 as well. Deprecation metadata is now retained until compatibility overloads are restored, then the existing final GA pass removes it only from signatures that were previously non-obsolete. An already-obsolete restored overload keeps the current message, while the stable overload remains non-obsolete. Added a sync/async regression covering the mixed contract.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The interacting changes to published-contract preservation, partial-method attributes, and diagnostic suppression warrant final human review despite the extensive regression coverage.
Keep custom Experimental and Obsolete attributes on partial declarations through the shared signature builder. Cover non-client block- and expression-bodied methods, and remove the requested emitter documentation changes.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Released-contract compatibility remains unresolved, and the interactions between attribute caching, visitors, and warning suppression warrant final human review.
If a visitor renames or moves a deprecated type to an existing, non-obsolete GA identity after Attributes has been read, the cached Obsolete attribute survives and introduces consumer warnings on that stable API. ResetMembersBasedOnIdentityChange refreshes LastContractView but leaves _attributes intact (TypeProvider.cs:986–1013). Re-evaluate generated deprecation metadata against the final identity without discarding visitor-supplied attributes, and add a regression that reads attributes before renaming.
Re-evaluate generated obsolete metadata after visitor renames and namespace changes while preserving visitor-added attributes and explicit removals. Prevent stale attribute snapshots from restoring obsolete warnings on non-obsolete GA types.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Fixed the cached-attribute identity issue from the latest review in 96f0a6e. Generated deprecation metadata is now re-evaluated after type updates against the final identity and released contract. Visitor-added attributes, explicit removals, and replacement Obsolete messages are preserved; applying a stale pre-rename attribute list cannot reintroduce a generated warning on a non-obsolete GA type.
Added rename/namespace-change regressions for models and both enum forms, transitions to and from GA identities, customization precedence, visitor overrides, stale attribute snapshots, and final generated output.
A customization such as [Obsolete("Use Current instead.", DiagnosticId = "OBS001")] produces OBS001, not CS0618, but this branch reduces every obsolete attribute to the two default warning codes. Generated serialization references to that customized API therefore still fail warnings-as-errors builds; retain and suppress the attribute's named DiagnosticId, as ModelReaderWriterContextDefinition.cs:667–669 already does for framework types.
Fixed the custom obsolete diagnostic-ID finding from the latest review in 7f98ceb. Generated suppressions now read the named Obsolete.DiagnosticId and preserve it for type references, deserialization, model registrations, and compatibility forwarding instead of reducing it to CS0612/CS0618. Missing, null, and empty IDs retain the existing default behavior.
Added regressions for custom model/enum and collection references, deserialization output, context registration, compatibility overloads, and diagnostic identifier handling. Compiled the generated deserialization with warnings treated as errors and verified a separate consumer still receives OBS001.
BuildPartialSignature removes customization-owned Obsolete attributes from the generated protocol signature (PartialMethodCustomization.cs:209–210), so this lookup misses them. If only the protocol partial declaration is marked [Obsolete(..., DiagnosticId = "OBS001")], its non-obsolete convenience method calls it without suppressing OBS001 and fails a warnings-as-errors build; also inspect the matching custom protocol declaration when collecting these suppressions.
Fixed the custom protocol-declaration suppression gap from the latest review in 86cd139. Convenience methods now collect call-site diagnostics from both the generated protocol signature and its matching custom declaration, including custom obsolete IDs and experimental IDs. Diagnostics already covered by the convenience declaration are not added redundantly, and the convenience API does not gain the attributes from the protocol declaration.
The regression also exposed the protocol-only partial modifier being copied to a non-customized convenience overload; that modifier is now cleared. Added sync/async custom-ID, parameterless-obsolete, experimental, combined, unrelated-overload, and stable controls. A generated sample with protocol-only OBS001/OBS002 declarations builds with warnings treated as errors, and reflection verifies the convenience overloads remain non-obsolete.
Remove mutable type-map keys before name or namespace updates and reinsert owned mappings afterward. Refresh serialization caches so renamed enum helpers retain warning suppressions and final identities.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve name and namespace together so provider reindexing never overwrites an unrelated intermediate identity. Cover models and both enum forms with retained warning lookup.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Interactions among published API compatibility, partial customization, diagnostic suppression, and provider identity updates warrant final human review.
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
auto-mergeAutomatically merge the pull request after all requirements passemitter:client:csharpIssue for the C# client emitter: @typespec/http-client-csharp
2 participants
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.
Fixes #12392.
Changes
Obsoleteattributes from TypeSpec#deprecatedmetadata on models, fixed/extensible enums, and synchronous/asynchronous protocol and convenience methods. Preserve messages, including empty strings and C# escaping.Validation
Windows validation used temporary drive mappings to avoid existing long-path limitations. Regeneration reported restore/artifact-path warnings for some long Spector paths; the subsequent shortened-path solution build succeeded.