Skip to content

Automatically set OpenAPI endpoint metadata for minimal APIs #34544

@DamianEdwards

Description

@DamianEdwards

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: DesignThis issue requires design work before implementating.Priority:1Work that is critical for the release, but we could probably ship withoutarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routing

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions