Skip to content

Commit d1b4877

Browse files
authored
Merge pull request #36823 from dotnet/main
Merge to Live
2 parents 95a7358 + 907006e commit d1b4877

File tree

4 files changed

+137
-4
lines changed

4 files changed

+137
-4
lines changed

aspnetcore/breaking-changes/10/withopenapi-deprecated.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.custom: https://github.com/aspnet/Announcements/issues/519
88

99
# Deprecation of WithOpenApi extension method
1010

11-
The <xref:Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.WithOpenApi*> methods have been deprecated in .NET 10. Invoking these methods now produces the compile-time diagnostic `ASPDEPR002` and a standard `Obsolete` warning that states:
11+
The <xref:Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.WithOpenApi*> methods have been deprecated in .NET 10. Invoking these methods now produces the compile-time diagnostic [`ASPDEPR002`](xref:diagnostics/aspdepr002) and a standard `Obsolete` warning that states:
1212

1313
> WithOpenApi is deprecated and will be removed in a future release. For more information, visit <https://aka.ms/aspnet/deprecate/002>.
1414
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
title: ASPDEPR diagnostics overview
3+
ai-usage: ai-assisted
4+
author: tdykstra
5+
description: Overview of ASPDEPR deprecation diagnostics in ASP.NET Core.
6+
monikerRange: '>= aspnetcore-10.0'
7+
ms.author: tdykstra
8+
ms.date: 03/03/2026
9+
uid: diagnostics/aspdepr-ids
10+
---
11+
# ASPDEPR diagnostics overview
12+
13+
ASPDEPR diagnostics are compile-time warnings issued by the .NET compiler when your code uses ASP.NET Core APIs that have been deprecated. Deprecated APIs are still functional but are scheduled for removal in a future release. Addressing these warnings helps keep your code up to date and ensures a smoother upgrade path.
14+
15+
ASPDEPR diagnostics are similar to the [`SYSLIB` obsoletions](/dotnet/fundamentals/syslib-diagnostics/obsoletions-overview) in .NET, but are specific to ASP.NET Core.
16+
17+
> [!NOTE]
18+
> This article is a work-in-progress. It's not a complete list of deprecation diagnostics.
19+
20+
## ASPDEPR diagnostics
21+
22+
The following table lists the `ASPDEPR` deprecation diagnostics for ASP.NET Core:
23+
24+
| Diagnostic ID | Description |
25+
|-------------------------------------------|-----------------------------|
26+
| [ASPDEPR002](xref:diagnostics/aspdepr002) | `WithOpenApi` is deprecated |
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: ASPDEPR002 warning
3+
description: Learn about the obsoletions that generate compile-time warning ASPDEPR002.
4+
ai-usage: ai-assisted
5+
monikerRange: '>= aspnetcore-10.0'
6+
ms.date: 03/03/2026
7+
uid: diagnostics/aspdepr002
8+
ms.author: tdykstra
9+
author: tdykstra
10+
f1_keywords:
11+
- aspdepr002
12+
---
13+
# ASPDEPR002: `WithOpenApi` is deprecated
14+
15+
The <xref:Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.WithOpenApi*> extension methods are deprecated starting in .NET 10. Using these methods produces the `ASPDEPR002` diagnostic at compile time. The functionality they provided is now available through the built-in OpenAPI document generation pipeline.
16+
17+
## Workarounds
18+
19+
Remove `.WithOpenApi()` calls from your code.
20+
21+
- If you used `Microsoft.AspNetCore.OpenApi` for document generation, use the `AddOpenApiOperationTransformer` extension method instead.
22+
23+
Before:
24+
25+
```csharp
26+
using Microsoft.AspNetCore.OpenApi;
27+
28+
var builder = WebApplication.CreateBuilder();
29+
var app = builder.Build();
30+
31+
app.MapGet("/weather", () => ...)
32+
.WithOpenApi(operation =>
33+
{
34+
// Per-endpoint tweaks
35+
operation.Summary = "Gets the current weather report.";
36+
operation.Description = "Returns a short description and emoji.";
37+
return operation;
38+
});
39+
40+
app.Run();
41+
```
42+
43+
After:
44+
45+
```csharp
46+
using Microsoft.AspNetCore.OpenApi;
47+
48+
var builder = WebApplication.CreateBuilder();
49+
var app = builder.Build();
50+
51+
app.MapGet("/weather", () => ...)
52+
.AddOpenApiOperationTransformer((operation, context, ct) =>
53+
{
54+
// Per-endpoint tweaks
55+
operation.Summary = "Gets the current weather report.";
56+
operation.Description = "Returns a short description and emoji.";
57+
return Task.CompletedTask;
58+
});
59+
60+
app.Run();
61+
```
62+
63+
- If you used `Swashbuckle` for document generation, use the `IOperationFilter` API.
64+
- If you used `NSwag` for document generation, use the `IOperationProcessor` API.
65+
66+
## Suppress a warning
67+
68+
If you must use the deprecated APIs, you can suppress the warning in code or in your project file.
69+
70+
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
71+
72+
```csharp
73+
// Disable the warning.
74+
#pragma warning disable ASPDEPR002
75+
76+
// Code that uses deprecated API.
77+
// ...
78+
79+
// Re-enable the warning.
80+
#pragma warning restore ASPDEPR002
81+
```
82+
83+
To suppress all the `ASPDEPR002` warnings in your project, add a `<NoWarn>` property to your project file.
84+
85+
```xml
86+
<Project Sdk="Microsoft.NET.Sdk">
87+
<PropertyGroup>
88+
...
89+
<NoWarn>$(NoWarn);ASPDEPR002</NoWarn>
90+
</PropertyGroup>
91+
</Project>
92+
```
93+
94+
## See also
95+
96+
- [Deprecation of WithOpenApi extension method](../breaking-changes/10/withopenapi-deprecated.md)

aspnetcore/toc.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,8 +1652,10 @@ items:
16521652
- name: Azure and IIS errors reference
16531653
uid: host-and-deploy/azure-iis-errors-reference
16541654
- name: Code analysis
1655-
uid: diagnostics/code-analysis
16561655
items:
1656+
- name: Overview
1657+
displayName: code analysis
1658+
uid: diagnostics/code-analysis
16571659
- name: ASP0000
16581660
uid: diagnostics/asp0000
16591661
- name: ASP0001
@@ -1740,8 +1742,10 @@ items:
17401742
uid: diagnostics/mvc1005
17411743
- name: MVC1006
17421744
uid: diagnostics/mvc1006
1743-
- name: RDG diagnostics
1744-
displayName: aot, RDG diagnostics
1745+
- name: RDG diagnostics
1746+
items:
1747+
- name: Overview
1748+
displayName: aot, rdg diagnostics
17451749
uid: fundamentals/aot/request-delegate-generator/rdg-ids
17461750
- name: RDG002
17471751
uid: fundamentals/aot/request-delegate-generator/diagnostics/rdg002
@@ -1765,6 +1769,13 @@ items:
17651769
uid: fundamentals/aot/request-delegate-generator/diagnostics/rdg012
17661770
- name: RDG013
17671771
uid: fundamentals/aot/request-delegate-generator/diagnostics/rdg013
1772+
- name: ASPDEPR diagnostics
1773+
items:
1774+
- name: Overview
1775+
displayName: aspdepr diagnostics
1776+
uid: diagnostics/aspdepr-ids
1777+
- name: ASPDEPR002
1778+
uid: diagnostics/aspdepr002
17681779
- name: Data access
17691780
items:
17701781
- name: Tutorials

0 commit comments

Comments
 (0)