Skip to content

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

Merged
merged 3 commits into from
Jul 17, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 17, 2025

This PR deprecates the WithOpenApi extension methods in Microsoft.AspNetCore.OpenApi with diagnostic code ASPDEPR002, as outlined in the issue discussion.

Changes Made

1. Added Obsolete Attributes

Added [Obsolete] attributes with DiagnosticId = "ASPDEPR002" to both WithOpenApi method overloads:

  • WithOpenApi<TBuilder>(this TBuilder builder)
  • WithOpenApi<TBuilder>(this TBuilder builder, Func<OpenApiOperation, OpenApiOperation> configureOperation)

Obsoletion message:

"WithOpenApi is deprecated and will be removed in a future release. For more information, visit https://aka.ms/aspnet/deprecate/002."

2. Warning Suppression

Added #pragma warning disable ASPDEPR002 directives to files that legitimately use these deprecated methods:

  • Test files: OpenApiRouteHandlerBuilderExtensionTests.cs
  • Project templates: Program.MinimalAPIs.OrgOrIndividualB2CAuth.cs

3. Verification

Confirmed that:

  • All existing tests pass (547 passed, 5 skipped)
  • Build succeeds without errors or warnings
  • Deprecation warnings are correctly generated when methods are used without suppression
  • Both method overloads produce the expected ASPDEPR002 diagnostic

Example Warning Output

When developers use these methods without suppressing warnings, they will see:

warning ASPDEPR002: 'OpenApiEndpointConventionBuilderExtensions.WithOpenApi<TBuilder>(TBuilder)' is obsolete: 'WithOpenApi is deprecated and will be removed in a future release. For more information, visit https://aka.ms/aspnet/deprecate/002.'

Migration Path

Users should migrate from WithOpenApi() to either:

  • Built-in OpenAPI document generation in Microsoft.AspNetCore.OpenApi
  • OperationFilter feature supported by Swashbuckle.AspNetCore

Fixes #62778.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

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
Copy link
Member

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.

Copy link
Contributor Author

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

@Copilot Copilot AI changed the title [WIP] Deprecate WithOpenApi extension methods Deprecate WithOpenApi extension methods with ASPDEPR002 diagnostic code Jul 17, 2025
Copilot finished work on behalf of captainsafia July 17, 2025 16:24
@Copilot Copilot AI requested a review from captainsafia July 17, 2025 16:24
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copilot finished work on behalf of captainsafia July 17, 2025 16:32
@captainsafia captainsafia marked this pull request as ready for review July 17, 2025 16:50
@captainsafia captainsafia requested a review from a team as a code owner July 17, 2025 16:50
@@ -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")]
Copy link
Member

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?

@captainsafia captainsafia enabled auto-merge (squash) July 17, 2025 19:02
@captainsafia captainsafia merged commit 0b2da29 into main Jul 17, 2025
28 of 29 checks passed
@captainsafia captainsafia deleted the copilot/fix-62778 branch July 17, 2025 20:16
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview7 milestone Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate WithOpenApi extension methods
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy