dotnet / dotnet/aspnetcore

Automatically set OpenAPI endpoint metadata for minimal APIs

Open
#34,544 11 comments 7 reactions 0 assignees View on GitHub
area-minimal feature-minimal-actions Needs: Design Priority:1
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

Rather than having to manually specify the endpoint metadata associated with describing the response types a minimal API produces, it would be preferable to have these details automatically added based on what the minimal API actually does (its implemention) and/or by some convention based on how it's declared.

- For anonymous delegates, the name could be automatically set via a convention based on which HTTP verb it responds to, the path it's mapped to, and the parameters it accepts from the request, e.g. `app.MapGet("/hello/{name}", (string name) => $"Hello {name}");` might get an auto-generated name of `GetHelloByName`.
- For `IResult` returning endpoint delegates, the status codes, content types, and response types the endpoint returns could be determined by analyzing the method body implementation and detecting the return paths and determining the specific details of what the `IResult` does when executed, e.g. by annotations on the `IResult`-implementing type itself, or some other mechanism
- The discovered details could be written to a source-generated manifest that is embedded in the project assembly and discovered at application startup automatically (e.g. via an `IHostingStartup` & `IStartupFilter` ) and is then used to match the details with the registered endpoints.

This is scoped to post-.NET 6 at this time, but could potentially be delivered before .NET 7 if it only involves an update in the tooling/SDK rather than an update in the ASP.NET Core shared framework.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.