Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epic: Minimal API - OpenAPI features #34514

Closed
15 tasks done
Tracked by #27883
rafikiassumani-msft opened this issue Jul 19, 2021 · 3 comments
Closed
15 tasks done
Tracked by #27883

Epic: Minimal API - OpenAPI features #34514

rafikiassumani-msft opened this issue Jul 19, 2021 · 3 comments
Assignees
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc Epic Groups multiple user stories. Can be grouped under a theme. feature-minimal-actions Controller-like actions for endpoint routing
Milestone

Comments

@rafikiassumani-msft
Copy link
Contributor

rafikiassumani-msft commented Jul 19, 2021

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


Other

Issues (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 operationId in generated OpenAPI documents.
    • Note the endpoint name is also used when using LinkGenerator to generate URL/links for endpoints
  • 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);
}
@rafikiassumani-msft rafikiassumani-msft added Epic Groups multiple user stories. Can be grouped under a theme. feature-minimal-actions Controller-like actions for endpoint routing labels Jul 19, 2021
@rafikiassumani-msft rafikiassumani-msft added this to the 6.0.0 milestone Jul 19, 2021
@DamianEdwards DamianEdwards changed the title Epic: Minimal API - Open API features Epic: Minimal API - OpenAPI features Jul 20, 2021
@davidfowl
Copy link
Member

cc @martincostello

@davidfowl
Copy link
Member

davidfowl commented Jul 20, 2021

I guess we need to understand how this affects MVC routes as well? I assume it will conflict. We need to figure out what happens when somebody does:

app.MapControlles().WithName("DontDoThis").ProducesValidationProblem();

@rafikiassumani-msft
Copy link
Contributor Author

I am closing this issue as I moved the unfinished items to the following issue for .NET7 Planning: #37098

@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc Epic Groups multiple user stories. Can be grouped under a theme. feature-minimal-actions Controller-like actions for endpoint routing
Projects
None yet
Development

No branches or pull requests

6 participants