Skip to content

Commit da732f0

Browse files
Add summaries and descriptions
Add summaries and descriptions to all of the API endpoints.
1 parent eb5d992 commit da732f0

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/TodoApp/ApiEndpoints.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,16 @@ public static IEndpointRouteBuilder MapTodoApiRoutes(this IEndpointRouteBuilder
6565
var group = builder.MapGroup("/api/items")
6666
.RequireAuthorization();
6767
{
68-
// Get all Todo items
6968
group.MapGet("/", async (
7069
ITodoService service,
7170
TodoUser user,
7271
CancellationToken cancellationToken) =>
7372
{
7473
return await service.GetListAsync(user, cancellationToken);
75-
});
74+
})
75+
.WithSummary("Get all Todo items")
76+
.WithDescription("Gets all of the current user's todo items.");
7677

77-
// Get a specific Todo item
7878
group.MapGet("/{id}", async Task<Results<Ok<TodoItemModel>, ProblemHttpResult>> (
7979
Guid id,
8080
TodoUser user,
@@ -88,9 +88,10 @@ public static IEndpointRouteBuilder MapTodoApiRoutes(this IEndpointRouteBuilder
8888
_ => TypedResults.Ok(model),
8989
};
9090
})
91-
.ProducesProblem(StatusCodes.Status404NotFound);
91+
.ProducesProblem(StatusCodes.Status404NotFound)
92+
.WithSummary("Get a specific Todo item")
93+
.WithDescription("Gets the todo item with the specified ID.");
9294

93-
// Create a new Todo item
9495
group.MapPost("/", async Task<Results<Created<CreatedTodoItemModel>, ProblemHttpResult>> (
9596
CreateTodoItemModel model,
9697
TodoUser user,
@@ -106,9 +107,10 @@ public static IEndpointRouteBuilder MapTodoApiRoutes(this IEndpointRouteBuilder
106107

107108
return TypedResults.Created($"/api/items/{id}", new CreatedTodoItemModel() { Id = id });
108109
})
109-
.ProducesProblem(StatusCodes.Status400BadRequest);
110+
.ProducesProblem(StatusCodes.Status400BadRequest)
111+
.WithSummary("Create a new Todo item")
112+
.WithDescription("Creates a new todo item for the current user and returns its ID.");
110113

111-
// Mark a Todo item as completed
112114
group.MapPost("/{id}/complete", async Task<Results<NoContent, ProblemHttpResult>> (
113115
Guid id,
114116
TodoUser user,
@@ -125,9 +127,10 @@ public static IEndpointRouteBuilder MapTodoApiRoutes(this IEndpointRouteBuilder
125127
};
126128
})
127129
.ProducesProblem(StatusCodes.Status400BadRequest)
128-
.ProducesProblem(StatusCodes.Status404NotFound);
130+
.ProducesProblem(StatusCodes.Status404NotFound)
131+
.WithSummary("Mark a Todo item as completed")
132+
.WithDescription("Marks the todo item with the specified ID as complete.");
129133

130-
// Delete a Todo item
131134
group.MapDelete("/{id}", async Task<Results<NoContent, ProblemHttpResult>> (
132135
Guid id,
133136
TodoUser user,
@@ -141,7 +144,9 @@ public static IEndpointRouteBuilder MapTodoApiRoutes(this IEndpointRouteBuilder
141144
false => TypedResults.Problem("Item not found.", statusCode: StatusCodes.Status404NotFound),
142145
};
143146
})
144-
.ProducesProblem(StatusCodes.Status404NotFound);
147+
.ProducesProblem(StatusCodes.Status404NotFound)
148+
.WithSummary("Delete a Todo item")
149+
.WithDescription("Deletes the todo item with the specified ID.");
145150
};
146151

147152
// Redirect to Open API/Swagger documentation

0 commit comments

Comments
 (0)