Skip to content

Add Api Parameter Description to Api Description to represent the request body #35421

@rafikiassumani-msft

Description

@rafikiassumani-msft

Background and Motivation

1. Minimal APIs should be able to add their own ConsumesRequestTypeAttribute to their endpoint metadata, either by decorating the method/lambda with the ConsumesRequestTypeAttribute, or via new Accepts(string contentType) or Accepts<TRequest>(string contentType) methods on MinimalActionEndpointConventionBuilder. This should override any consumes metadata that was added via the 1st proposal (i.e. the 1st proposal is likely implemented as fallback logic in the endpoint builder).

  1. ApiExplorer should be updated to add a ApiParameterDescription to the ApiDescription to represent the incoming request body based on the details in the endpoint's IApiRequestMetadataProvider metadata if present.

Proposed API

 namespace Microsoft.AspNetCore.Http
{
    public static class OpenApiEndpointConventionBuilderExtensions
    {
+        public static DelegateEndpointConventionBuilder Accepts<TRequest>(this DelegateEndpointConventionBuilder 
+        builder,  string contentType, params string[] additionalContentTypes) where TRequest : notnull
  }
}

Usage Examples

app.MapPost("/create-todo", (Todo todo) => $"{todo.Name}").Accepts<Todo>("application/xml");

Risks

very low.

Metadata

Metadata

Labels

api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions