-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ProducesDefaultProblem method to RouteHandlerBuilder #64
Introduce a new extension method `ProducesDefaultProblem` for the `RouteHandlerBuilder` class to simplify defining common error responses. Enhance `README.md` with documentation and examples for the new method.
- Loading branch information
1 parent
32201bb
commit 0cf9c70
Showing
5 changed files
with
63 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/MinimalHelpers.OpenApi/RouteHandlerBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace MinimalHelpers.OpenApi; | ||
|
||
/// <summary> | ||
/// Extension methods for <see cref="RouteHandlerBuilder"/>. | ||
/// </summary> | ||
/// <seealso cref="RouteHandlerBuilder"/> | ||
public static class RouteHandlerBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Adds to <see cref="RouteHandlerBuilder"/> the specified list of status codes as <see cref="ProblemDetails"/> responses. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="RouteHandlerBuilder"/>.</param> | ||
/// <param name="statusCodes">The list of status codes to be added as <see cref="ProblemDetails"/> responses.</param> | ||
/// <returns>The <see cref="RouteHandlerBuilder"/> with the new status codes responses.</returns> | ||
public static RouteHandlerBuilder ProducesDefaultProblem(this RouteHandlerBuilder builder, params int[] statusCodes) | ||
{ | ||
foreach (var statusCode in statusCodes) | ||
{ | ||
builder.ProducesProblem(statusCode); | ||
} | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters