Skip to content

Commit 6cf2451

Browse files
Copilotgewarren
andcommitted
Document WithOpenApi deprecation breaking change for .NET 10 Preview 7
Co-authored-by: gewarren <[email protected]>
1 parent 1e6346f commit 6cf2451

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
1515
> [!NOTE]
1616
> This article is a work in progress. It's not a complete list of breaking changes in .NET 10.
1717
18+
## ASP.NET Core
19+
20+
| Title | Type of change | Introduced version |
21+
|-------|-------------------|--------------------|
22+
| [Deprecation of WithOpenApi extension method](aspnet-core/10.0/withopenapi-deprecated.md) | Behavioral change | Preview 7 |
23+
1824
## Containers
1925

2026
| Title | Type of change | Introduced version |
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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: 12/17/2024
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 `WithOpenApi` extension methods in `Microsoft.AspNetCore.OpenApi.OpenApiEndpointConventionBuilderExtensions` have been deprecated in .NET 10. Invoking these methods now produces the compile-time diagnostic **ASPDEPR002** and a standard `[Obsolete]` warning.
12+
13+
## Version introduced
14+
15+
.NET 10 Preview 7
16+
17+
## Previous behavior
18+
19+
Previously, you could use the `WithOpenApi` extension method without any warnings:
20+
21+
```csharp
22+
app.MapGet("/weather", () => ...)
23+
.WithOpenApi(); // no warnings
24+
```
25+
26+
## New behavior
27+
28+
Starting in .NET 10 Preview 7, using the `WithOpenApi` extension method produces a compiler warning:
29+
30+
```csharp
31+
app.MapGet("/weather", () => ...)
32+
.WithOpenApi(); // warning ASPDEPR002: WithOpenApi is deprecated and will be removed in a future release. For more information, visit https://aka.ms/aspnet/deprecate/002.
33+
```
34+
35+
The call still compiles and executes, but the build now emits the new deprecation warning.
36+
37+
## Type of breaking change
38+
39+
This is a [behavioral change](../../categories.md#behavioral-change).
40+
41+
## Reason for change
42+
43+
`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.
44+
45+
## Recommended action
46+
47+
Remove `.WithOpenApi()` calls from your code.
48+
49+
- If using `Microsoft.AspNetCore.OpenApi` for document generation, use the `AddOpenApiOperationTransformer` extension method.
50+
51+
**Before**
52+
53+
```csharp
54+
using Microsoft.AspNetCore.OpenApi;
55+
56+
var builder = WebApplication.CreateBuilder();
57+
var app = builder.Build();
58+
59+
app.MapGet("/weather", () => ...)
60+
.WithOpenApi(operation =>
61+
{
62+
// Per-endpoint tweaks
63+
operation.Summary = "Gets the current weather report.";
64+
operation.Description = "Returns a short description and emoji.";
65+
return operation;
66+
});
67+
68+
app.Run();
69+
```
70+
71+
**After**
72+
73+
```csharp
74+
using Microsoft.AspNetCore.OpenApi;
75+
76+
var builder = WebApplication.CreateBuilder();
77+
var app = builder.Build();
78+
79+
app.MapGet("/weather", () => ...)
80+
.AddOpenApiOperationTransformer((operation, context, ct) =>
81+
{
82+
// Per-endpoint tweaks
83+
operation.Summary = "Gets the current weather report.";
84+
operation.Description = "Returns a short description and emoji.";
85+
return Task.CompletedTask;
86+
});
87+
88+
app.Run();
89+
```
90+
91+
- If using `Swashbuckle` for document generation, use the `IOperationFilter` API.
92+
- If using `NSwag` for document generation, use the `IOperationProcessor` API.
93+
94+
## Affected APIs
95+
96+
- <xref:Microsoft.AspNetCore.OpenApi.OpenApiEndpointConventionBuilderExtensions.WithOpenApi%2A?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ items:
88
items:
99
- name: Overview
1010
href: 10.0.md
11+
- name: ASP.NET Core
12+
items:
13+
- name: Deprecation of WithOpenApi extension method
14+
href: aspnet-core/10.0/withopenapi-deprecated.md
1115
- name: Containers
1216
items:
1317
- name: Default .NET images use Ubuntu

0 commit comments

Comments
 (0)