-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Support all error's status codes ProblemDetail types for generating swagger docs in MinimalApi #47705
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
Comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API Review Notes:
We encourage using var hasUnauthorizedProblemsGroup = endpoints.MapGroup("");
hasUnauthorizedProblemsGroup.MapPost("/products",
Results<ProblemHttpResult, Ok<ProductDto>>(ProductDto product) =>
{
if ( some condition )
return TypedResults.Problem(statusCode: 401);
return TypedResults.Ok(product);
});
hasUnauthorizedProblemGroup.ProducesProblem(401); You can also use endpoints.MapPost("/products", ...).ProducesProblem(401); Thanks for submitting the API proposal, but we have decided to reject it. |
@halter73 Thanks for your review. |
Background and Motivation
If we want to create an api with multiple result types with using TypedResults, .net core 7 only supports
ValidationProblem
for auto generating swagger metadata andProblemHttpResult
type doesn't generate any swagger metadata (because it doesn't implementIEndpointMetadataProvider
). Maybe we need to declare dedicated problem types likeValidationProblem
for others error status codes, likeInternalProbelm
,UnAuthorizedProblem
,NotFoundProblem
...There is an issue #47623 already for this proposal.
Proposed API
This is an example for
UnAuthorized
problem, but it is the same for other error status codes:Usage Examples
Alternative Designs
N/A
Risks
None that I am aware of.
The text was updated successfully, but these errors were encountered: