Tono Nam
Tono Nam

Reputation: 36058

How to add method description in Swagger UI when using minimal APIs using dotnet 6.0?

This link has amazing documentation on how to add documentation into swagger UI.

The problem with that link is that it does not show how to do so using minimal APIs. There are a lot of places on the internet that show how to add documentation to swagger UI such as this other question from stack overflow but I have not been able to do so using minimal apis.

  1. This video shows how to create a simple project using minimal apis:

  2. This video shows how to make it unit testable

  3. This last video shows how to add validation, authorization and authentication

Has anyone managed to add custom documentation into swagger UI using minimal APIs?

Upvotes: 4

Views: 2348

Answers (1)

Mateusz D
Mateusz D

Reputation: 348

According to Microsoft documentation there is support for minimal api.

app.MapGet("/api/todoitems/{id}", async (int id, TodoDb db) =>
         await db.Todos.FindAsync(id) 
         is Todo todo
         ? Results.Ok(todo) 
         : Results.NotFound())
   .Produces<Todo>(StatusCodes.Status200OK)
   .Produces(StatusCodes.Status404NotFound);

More info you can find here:

https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis?view=aspnetcore-6.0#openapi

Upvotes: 4

Related Questions