-
Notifications
You must be signed in to change notification settings - Fork 10.3k
RequestDelegate
-based handlers do not surface in OpenAPI descriptions
#44970
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
Comments
This is a problem with Swashbuckle.AspNetCore |
3q |
Does updating group.MapGet("/authorize", AuthorizeAsync); to group.MapGet("/authorize", (Delegate)AuthorizeAsync); fix your issue? It looks like you're getting the This didn't get added in time for the .NET 7 release though. Is this something we could backport to the .NET 7 SDK in a servicing release? I think there could be false positives, so that might be risky. We wanted to just make this work (see see #40235), but this caused issues for trimming and AOT. Using source generators, we might be able to just make this work once a gain but in a way that's trim friendly. |
Also, if you want to get the best swagger output for TypedResults, you want to include the specific TypedResult in the return type. So you should prefer public static async Task<Ok> GoodMinimalApi() over public static async Task<IResult> GoodMinimalApi() You can read more about |
This issue actually starts in ASP.NET Core. Our OpenAPI infrastructure relies on In .NET 7 RC1, we actually enabled adding On solution we discussed was making it so that calling Does that seem like a sensible solution? cc: @martincostello for thoughts as well |
I like the idea of making it opt-in via something like My main concern (and how I found #44005) was that third party code might start exposing unintended endpoints that are difficult to suppress from the OpenAPI document (if you notice them even appear) if you can't update the source of the endpoint to mark it has hidden. |
Thanks for the feedback! Yeah, I'm thinking that by leveraging |
RequestDelegate
-based handlers do not surface in OpenAPI descriptions
Thanks for contacting us. We're moving this issue to the |
I started working on a PR for this (#47346) and ran into a little snafu when defining the OpenAPI operation, specifically around how the Ultimately, I decided that by default, an This means that when testing with the Swagger UI, you'll only be able to send parameter-less and body-less requests to the endpoint for testing. This restriction makes sense to me. Thoughts? |
Ignoring |
I am using the Delegate overload of MapGet but my issue is slightly different: I have a response dto being returned by the delegate whose display title I would like to customize in Swagger. While using controllers, decorating the response model with a [SwaggerSchema(Title = "ResponseNameToShowInSwagger", Description = "I expect to see this description is swagger.")]
public class MyResponse
{
} However, this no longer seems to be respected by minimal APIs. I just want to know whether the issue being tracked here will solve my problem as well or could there a different cause of my issue? Will appreciate any heads up on this. |
@syedsuhaib Can you file a separate issue for this? I can provide guidance there... |
Workaround: private static IEndpointConventionBuilder MapGetWithOpenAPI(this IEndpointRouteBuilder builder, [StringSyntax("Route")] string path, RequestDelegate requestDelegate)
{
return builder.MapGet(path, requestDelegate).WithMetadata(requestDelegate.Method);
} See: #44005 (comment) |
Is there an existing issue for this?
Describe the bug
hi I found that the minimal Api TypedResults method does not automatically inject HttpContext.
The httpcontext principle is here in the reference
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-7.0#binding-precedence
Expected Behavior
The TypedResults method can automatically inject HttpContext.
Steps To Reproduce
File:Program.cs
File:Connect.cs
End result
Exceptions (if any)
No response
.NET Version
dotnet 7.0
Anything else?
Microsoft Visual Studio Enterprise 2022 (64 位) - Current版本 17.4.0
ASP.NET Core 7
Minimal Api
The text was updated successfully, but these errors were encountered: