aspnetcore/diagnostics/aspdepr002.md
WithOpenApi is deprecatedThe 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.
Remove .WithOpenApi() calls from your code.
If you used Microsoft.AspNetCore.OpenApi for document generation, use the AddOpenApiOperationTransformer extension method instead.
Before:
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:
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.
If you must use the deprecated APIs, you can suppress the warning in code or in your project file.
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
// Disable the warning.
#pragma warning disable ASPDEPR002
// Code that uses deprecated API.
// ...
// Re-enable the warning.
#pragma warning restore ASPDEPR002
To suppress all the ASPDEPR002 warnings in your project, add a <NoWarn> property to your project file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<NoWarn>$(NoWarn);ASPDEPR002</NoWarn>
</PropertyGroup>
</Project>