-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
EpicGroups multiple user stories. Can be grouped under a theme.Groups multiple user stories. Can be grouped under a theme.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routing
Milestone
Description
This issue covers the desired experience for minimal APIs integration with OpenAPI via metadata and ApiExplorer observing libraries like Swashbuckle and nSwag.
Issues (ASP.NET Core)
Priority One
- Improve OpenAPI/Swagger response metadata for returned IResults #33924
- Add IgnoreApi() extension method for IEndpointConventionBuilder #34068
- Add support for setting ApiDescriptor.GroupName for minimal APIs #34443
- Allow setting
EndpointNameMetadatafor minimal APIs via a first-class extension method #34538 - Add
EndpointNameAttributeto enable setting endpoint name declaratively #34539 - Endpoint name metadata should be set automatically to the method name when
Mapoverload is called passing aMethodGroup#34540 - Allow setting a group name for endpoints and have it be used to populate ApiDescription.GroupName in ApiExplorer for minimal APIs #34541
- Update
ProducesResponseTypeAttributeto support setting content types for the defined response #34542 - Update the version of Swashbuckle.AspNetCore in the webapi template #34558
Other
Issues (Swashbuckle)
- DefaultOperationIdSelector should be updated to fallback to EndpointName if AttributeRouteInfo isn't populated domaindrivendev/Swashbuckle.AspNetCore#2165
- Add Content-Type Parameter to [SwaggerResponse] domaindrivendev/Swashbuckle.AspNetCore#1691
- This issue covers the scenario but the work will involve updating Swashbuckle to properly respect the response types declared in the metadata (i.e. status code, content type(s), schema)
- Update default inclusion logic to consider any new metadata added to ASP.NET Core as part of Add IgnoreApi() extension method for IEndpointConventionBuilder #34068 regarding whether an endpoint should be excluded from document generation (example)
- PR for adding HostFactoryResolver to detect new app patterns Added HostFactoryResolver to detect new application patterns domaindrivendev/Swashbuckle.AspNetCore#2147
- Swashbuckle CLI #34593 external issue on Swashbuckle
Additional context
The goal is to allow for minimal APIs to support having metadata specified (manually in .NET 6, either imperatively via extension methods or declaratively via attributes, potentially automatically based on endpoint implementation and/or convention in a release after .NET 6) that enables the following to be satisfied by default when an OpenAPI library is also configured (i.e. without the OpenAPI library requiring further manual configuration):
- Endpoint name that maps to
operationIdin generated OpenAPI documents.- Note the endpoint name is also used when using
LinkGeneratorto generate URL/links for endpoints
- Note the endpoint name is also used when using
- Endpoint group name that maps to the document name in generated OpenAPI documents (typically used for versioning, e.g. "v1", "v2")
- Metadata indicating that the API should be excluded/ignored from OpenAPI document generation
- Metadata indicating what response types a method produces, where each response is the combination of:
- One status code
- One or more content types, e.g. "application/json"
- An optional schema per content type
Examples
Example of what specifying the metadata imperatively could look like:
app.MapGet("/admin", () => "For admins only")
.WithName("AdminDetails")
.RequiresAuthorization("Admins")
.ExcludeFromApiExplorer();
app.MapPost("/todos", async (Todo todo, TodoDb db) =>
{
if (!MinimalValidation.TryValidate(todo, out var errors))
return Results.ValidationProblem(errors);
db.Todos.Add(todo);
await db.SaveChangesAsync();
return Results.CreatedAtRoute("GetTodoById", new { todo.Id }, todo);
})
.WithName("AddTodo")
.WithGroupName("v1")
.ProducesValidationProblem()
.Produces<Todo>(StatusCodes.Status201Created);Example of what specifying the metadata declaratively could look like:
app.MapGet("/admin", AdminDetails);
app.MapPost("/todos-attr-desc", AddTodo);
[Authorized(Policy = "Admins")]
[ExcludeFromApiExplorer]
string AdminDetails()
{
return "For admins only";
}
[EndpointGroupName("v1")]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest, "application/problem+json")]
[ProducesResponseType(typeof(Todo), StatusCodes.Status201Created)]
async Task<IResult> AddTodo(Todo todo, TodoDb db)
{
if (!MinimalValidation.TryValidate(todo, out var errors))
return Results.ValidationProblem(errors);
db.Todos.Add(todo);
await db.SaveChangesAsync();
return Results.Created($"/todos/{todo.Id}", todo);
}SommerEngineeringSommerEngineering
Metadata
Metadata
Assignees
Labels
EpicGroups multiple user stories. Can be grouped under a theme.Groups multiple user stories. Can be grouped under a theme.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routing