-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Deprecate WithOpenApi extension methods with ASPDEPR002 diagnostic code #62779
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
Conversation
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
@@ -1,6 +1,7 @@ | |||
#if (GenerateApi) | |||
using System.Net.Http; | |||
#endif | |||
#pragma warning disable ASPDEPR002 // WithOpenApi is deprecated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Instead of #pragma warning disable here, remove the .WithOpenApi
call in this template.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the .WithOpenApi()
call from the template and the pragma warning disable directive. Templates should not include deprecated methods. f0200ea
WithOpenApi
extension methodsCo-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
@@ -29,6 +29,7 @@ public static class OpenApiEndpointConventionBuilderExtensions | |||
/// </remarks> | |||
/// <param name="builder">The <see cref="IEndpointConventionBuilder"/>.</param> | |||
/// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns> | |||
[Obsolete("WithOpenApi is deprecated and will be removed in a future release. For more information, visit https://aka.ms/aspnet/deprecate/002.", DiagnosticId = "ASPDEPR002")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this warning or the linked page mention using MapOpenApi
?
This PR deprecates the
WithOpenApi
extension methods inMicrosoft.AspNetCore.OpenApi
with diagnostic codeASPDEPR002
, as outlined in the issue discussion.Changes Made
1. Added Obsolete Attributes
Added
[Obsolete]
attributes withDiagnosticId = "ASPDEPR002"
to bothWithOpenApi
method overloads:WithOpenApi<TBuilder>(this TBuilder builder)
WithOpenApi<TBuilder>(this TBuilder builder, Func<OpenApiOperation, OpenApiOperation> configureOperation)
Obsoletion message:
2. Warning Suppression
Added
#pragma warning disable ASPDEPR002
directives to files that legitimately use these deprecated methods:OpenApiRouteHandlerBuilderExtensionTests.cs
Program.MinimalAPIs.OrgOrIndividualB2CAuth.cs
3. Verification
Confirmed that:
ASPDEPR002
diagnosticExample Warning Output
When developers use these methods without suppressing warnings, they will see:
Migration Path
Users should migrate from
WithOpenApi()
to either:Microsoft.AspNetCore.OpenApi
OperationFilter
feature supported by Swashbuckle.AspNetCoreFixes #62778.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.