-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document .NET 10 Preview 7 breaking change: Deprecation of WithOpenApi extension method #47890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e6346f
Initial plan
Copilot 6cf2451
Document WithOpenApi deprecation breaking change for .NET 10 Preview 7
Copilot 97d2cba
human edits
gewarren 8aaf45f
fix bare url
gewarren 5b6f01e
fix xref
gewarren d0bab19
fix folder name
gewarren b7eaa85
Update docs/core/compatibility/10.0.md
gewarren 2b84a30
Merge branch 'main' into copilot/fix-47448
gewarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
98 changes: 98 additions & 0 deletions
98
docs/core/compatibility/aspnet-core/10/withopenapi-deprecated.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| --- | ||
| title: "Breaking change: Deprecation of WithOpenApi extension method" | ||
| description: "Learn about the breaking change in ASP.NET Core 10 where WithOpenApi extension methods have been deprecated and produce a compiler warning." | ||
| ms.date: 08/07/2025 | ||
| ai-usage: ai-assisted | ||
| ms.custom: https://github.com/aspnet/Announcements/issues/519 | ||
| --- | ||
|
|
||
| # Deprecation of WithOpenApi extension method | ||
|
|
||
| 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: | ||
|
|
||
| > WithOpenApi is deprecated and will be removed in a future release. For more information, visit <https://aka.ms/aspnet/deprecate/002>. | ||
|
|
||
| ## Version introduced | ||
|
|
||
| .NET 10 Preview 7 | ||
|
|
||
| ## Previous behavior | ||
|
|
||
| Previously, you could use the `WithOpenApi` extension method without any warnings: | ||
|
|
||
| ```csharp | ||
| app.MapGet("/weather", () => ...) | ||
| .WithOpenApi(); // No warnings. | ||
| ``` | ||
|
|
||
| ## New behavior | ||
|
|
||
| Starting in .NET 10, using the `WithOpenApi` extension method produces a compiler warning: | ||
|
|
||
| ```csharp | ||
| app.MapGet("/weather", () => ...) | ||
| .WithOpenApi(); // Warning ASPDEPR002: WithOpenApi is deprecated... | ||
| ``` | ||
|
|
||
| However, the call still compiles and executes. | ||
|
|
||
| ## Type of breaking change | ||
|
|
||
| This change can affect [source compatibility](../../categories.md#source-compatibility). | ||
|
|
||
| ## Reason for change | ||
|
|
||
| <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. | ||
|
|
||
| ## Recommended action | ||
|
|
||
| Remove `.WithOpenApi()` calls from your code. | ||
|
|
||
| - 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. | ||
|
|
||
| Before: | ||
|
|
||
| ```csharp | ||
| using Microsoft.AspNetCore.OpenApi; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(); | ||
| var app = builder.Build(); | ||
|
|
||
| app.MapGet("/weather", () => ...) | ||
| .WithOpenApi(operation => | ||
| { | ||
| // Per-endpoint tweaks | ||
| operation.Summary = "Gets the current weather report."; | ||
| operation.Description = "Returns a short description and emoji."; | ||
| return operation; | ||
| }); | ||
|
|
||
| app.Run(); | ||
| ``` | ||
|
|
||
| After: | ||
|
|
||
| ```csharp | ||
| using Microsoft.AspNetCore.OpenApi; | ||
|
|
||
| var builder = WebApplication.CreateBuilder(); | ||
| var app = builder.Build(); | ||
|
|
||
| app.MapGet("/weather", () => ...) | ||
| .AddOpenApiOperationTransformer((operation, context, ct) => | ||
| { | ||
| // Per-endpoint tweaks | ||
| operation.Summary = "Gets the current weather report."; | ||
| operation.Description = "Returns a short description and emoji."; | ||
| return Task.CompletedTask; | ||
| }); | ||
|
|
||
| app.Run(); | ||
| ``` | ||
|
|
||
| - If you used `Swashbuckle` for document generation, use the `IOperationFilter` API. | ||
| - If you used `NSwag` for document generation, use the `IOperationProcessor` API. | ||
|
|
||
| ## Affected APIs | ||
|
|
||
| - <xref:Microsoft.AspNetCore.Builder.OpenApiEndpointConventionBuilderExtensions.WithOpenApi%2A?displayProperty=fullName> |
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
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.
Uh oh!
There was an error while loading. Please reload this page.