diff --git a/src/OpenApi/src/Extensions/OpenApiEndpointConventionBuilderExtensions.cs b/src/OpenApi/src/Extensions/OpenApiEndpointConventionBuilderExtensions.cs
index ac4b49ca8306..0f3ed82a2a3e 100644
--- a/src/OpenApi/src/Extensions/OpenApiEndpointConventionBuilderExtensions.cs
+++ b/src/OpenApi/src/Extensions/OpenApiEndpointConventionBuilderExtensions.cs
@@ -29,6 +29,7 @@ public static class OpenApiEndpointConventionBuilderExtensions
///
/// The .
/// A that can be used to further customize the endpoint.
+ [Obsolete("WithOpenApi is deprecated and will be removed in a future release. For more information, visit https://aka.ms/aspnet/deprecate/002.", DiagnosticId = "ASPDEPR002")]
[RequiresDynamicCode(TrimWarningMessage)]
[RequiresUnreferencedCode(TrimWarningMessage)]
public static TBuilder WithOpenApi(this TBuilder builder) where TBuilder : IEndpointConventionBuilder
@@ -48,6 +49,7 @@ public static TBuilder WithOpenApi(this TBuilder builder) where TBuild
/// The .
/// An that returns a new OpenAPI annotation given a generated operation.
/// A that can be used to further customize the endpoint.
+ [Obsolete("WithOpenApi is deprecated and will be removed in a future release. For more information, visit https://aka.ms/aspnet/deprecate/002.", DiagnosticId = "ASPDEPR002")]
[RequiresDynamicCode(TrimWarningMessage)]
[RequiresUnreferencedCode(TrimWarningMessage)]
public static TBuilder WithOpenApi(this TBuilder builder, Func configureOperation)
diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/OpenApiRouteHandlerBuilderExtensionTests.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/OpenApiRouteHandlerBuilderExtensionTests.cs
index 7a518238d616..8c14337a69ed 100644
--- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/OpenApiRouteHandlerBuilderExtensionTests.cs
+++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/OpenApiRouteHandlerBuilderExtensionTests.cs
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+#pragma warning disable ASPDEPR002 // WithOpenApi is deprecated
+
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Program.MinimalAPIs.OrgOrIndividualB2CAuth.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Program.MinimalAPIs.OrgOrIndividualB2CAuth.cs
index 4e502393522f..415dc9b38f31 100644
--- a/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Program.MinimalAPIs.OrgOrIndividualB2CAuth.cs
+++ b/src/ProjectTemplates/Web.ProjectTemplates/content/WebApi-CSharp/Program.MinimalAPIs.OrgOrIndividualB2CAuth.cs
@@ -128,7 +128,6 @@
#if (EnableOpenAPI)
})
.WithName("GetWeatherForecast")
-.WithOpenApi()
.RequireAuthorization();
#else
})