Skip to content

Commit 4a965d2

Browse files
authored
Document .NET 10 Preview 7 breaking change: Deprecation of WithOpenApi extension method (#47890)
1 parent e8669c1 commit 4a965d2

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
1919

2020
| Title | Type of change | Introduced version |
2121
|-------|-------------------|--------------------|
22+
| [Deprecation of WithOpenApi extension method](aspnet-core/10/withopenapi-deprecated.md) | Source incompatible | Preview 7 |
2223
| [IActionContextAccessor and ActionContextAccessor are obsolete](aspnet-core/10/iactioncontextaccessor-obsolete.md) | Source incompatible/behavioral change | Preview 7 |
2324
| [IncludeOpenAPIAnalyzers property and MVC API analyzers are deprecated](aspnet-core/10/openapi-analyzers-deprecated.md) | Source incompatible | Preview 7 |
2425
| [Microsoft.Extensions.ApiDescription.Client package deprecated](aspnet-core/10/apidescription-client-deprecated.md) | Source incompatible | Preview 7 |
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: "Breaking change: Deprecation of WithOpenApi extension method"
3+
description: "Learn about the breaking change in ASP.NET Core 10 where WithOpenApi extension methods have been deprecated and produce a compiler warning."
4+
ms.date: 08/07/2025
5+
ai-usage: ai-assisted
6+
ms.custom: https://github.com/aspnet/Announcements/issues/519
7+
---
8+
9+
# Deprecation of WithOpenApi extension method
10+
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:
12+
13+
> WithOpenApi is deprecated and will be removed in a future release. For more information, visit <https://aka.ms/aspnet/deprecate/002>.
14+
15+
## Version introduced
16+
17+
.NET 10 Preview 7
18+
19+
## Previous behavior
20+
21+
Previously, you could use the `WithOpenApi` extension method without any warnings:
22+
23+
```csharp
24+
app.MapGet("/weather", () => ...)
25+
.WithOpenApi(); // No warnings.
26+
```
27+
28+
## New behavior
29+
30+
Starting in .NET 10, using the `WithOpenApi` extension method produces a compiler warning:
31+
32+
```csharp
33+
app.MapGet("/weather", () => ...)
34+
.WithOpenApi(); // Warning ASPDEPR002: WithOpenApi is deprecated...
35+
```
36+
37+
However, the call still compiles and executes.
38+
39+
## Type of breaking change
40+
41+
This change can affect [source compatibility](../../categories.md#source-compatibility).
42+
43+
## Reason for change
44+
45+
<xref:Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.WithOpenApi*> duplicated functionality now provided by the built-in OpenAPI document generation pipeline. Deprecating it simplifies the API surface and prepares for its eventual removal.
46+
47+
## Recommended action
48+
49+
Remove `.WithOpenApi()` calls from your code.
50+
51+
- If you used `Microsoft.AspNetCore.OpenApi` for document generation, use the <xref:Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.AddOpenApiOperationTransformer``1(``0,System.Func{Microsoft.OpenApi.OpenApiOperation,Microsoft.AspNetCore.OpenApi.OpenApiOperationTransformerContext,System.Threading.CancellationToken,System.Threading.Tasks.Task})> extension method.
52+
53+
Before:
54+
55+
```csharp
56+
using Microsoft.AspNetCore.OpenApi;
57+
58+
var builder = WebApplication.CreateBuilder();
59+
var app = builder.Build();
60+
61+
app.MapGet("/weather", () => ...)
62+
.WithOpenApi(operation =>
63+
{
64+
// Per-endpoint tweaks
65+
operation.Summary = "Gets the current weather report.";
66+
operation.Description = "Returns a short description and emoji.";
67+
return operation;
68+
});
69+
70+
app.Run();
71+
```
72+
73+
After:
74+
75+
```csharp
76+
using Microsoft.AspNetCore.OpenApi;
77+
78+
var builder = WebApplication.CreateBuilder();
79+
var app = builder.Build();
80+
81+
app.MapGet("/weather", () => ...)
82+
.AddOpenApiOperationTransformer((operation, context, ct) =>
83+
{
84+
// Per-endpoint tweaks
85+
operation.Summary = "Gets the current weather report.";
86+
operation.Description = "Returns a short description and emoji.";
87+
return Task.CompletedTask;
88+
});
89+
90+
app.Run();
91+
```
92+
93+
- If you used `Swashbuckle` for document generation, use the `IOperationFilter` API.
94+
- If you used `NSwag` for document generation, use the `IOperationProcessor` API.
95+
96+
## Affected APIs
97+
98+
- <xref:Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.WithOpenApi%2A?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ items:
1010
href: 10.0.md
1111
- name: ASP.NET Core
1212
items:
13+
- name: Deprecation of WithOpenApi extension method
14+
href: aspnet-core/10/withopenapi-deprecated.md
1315
- name: IActionContextAccessor and ActionContextAccessor are obsolete
1416
href: aspnet-core/10/iactioncontextaccessor-obsolete.md
1517
- name: IncludeOpenAPIAnalyzers property and MVC API analyzers are deprecated

0 commit comments

Comments
 (0)