Skip to content

RequestDelegate-based handlers do not surface in OpenAPI descriptions #44970

@YataoFeng

Description

@YataoFeng

Is there an existing issue for this?

  • I have searched the existing issues

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

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.MapGroup("/connect").MapConnect();

app.Run();

File:Connect.cs

public static class Connect
{
    public static RouteGroupBuilder MapConnect(this RouteGroupBuilder group)
    {
        group.MapGet("/authorize", AuthorizeAsync);
        group.MapGet("/GoodMinimalApi", GoodMinimalApi);
        return group;
    }
    public static async Task<IResult> GoodMinimalApi() // not HttpContext
    {
        await Task.CompletedTask;
        return TypedResults.Ok();
    }
    public static async Task<IResult> AuthorizeAsync(HttpContext context)
    {
        await Task.CompletedTask;
        return TypedResults.Ok();
    }
}

End result

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions