-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Avoid using invalid content type for ValidationProblemDetails #36617
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
Conversation
/backport to release/6.0-rc2 |
Started backporting to release/6.0-rc2: https://github.com/dotnet/aspnetcore/actions/runs/1242932944 |
/// <returns>A <see cref="DelegateEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns> | ||
public static DelegateEndpointConventionBuilder ProducesValidationProblem(this DelegateEndpointConventionBuilder builder, | ||
int statusCode = StatusCodes.Status400BadRequest, | ||
string? contentType = null) | ||
{ | ||
if (string.IsNullOrEmpty(contentType)) | ||
{ | ||
contentType = "application/validationproblem+json"; | ||
contentType = "application/problem+json"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is MVC also affected by this? Could we also fix it while we're addressing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT, MVC isn't affected by this. The ControllerBase.ValidationProblem
method uses the application/problem+json
content type and the ProducesResponseType
attribute expects that users pass the content type for when they specify a typeof(ValidationProblemDetails)
hence the fix for the test case below.
Closes #36560
Closes #36557.
The OpenAPI extension methods assume an
application/validationproblem+json
content type but the results object represnet a different result.