Back to Aspnetcore

Breaking change: Deprecation of WithOpenApi extension method

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

latest3.0 KB
Original Source

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.

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.

Remove .WithOpenApi() calls from your code.

Affected APIs