Skip to content

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

Merged
merged 1 commit into from
Sep 16, 2021

Conversation

captainsafia
Copy link
Member

@captainsafia captainsafia commented Sep 16, 2021

Closes #36560
Closes #36557.

The OpenAPI extension methods assume an application/validationproblem+json content type but the results object represnet a different result.

@captainsafia captainsafia added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Sep 16, 2021
@captainsafia captainsafia requested a review from a team September 16, 2021 19:31
@captainsafia
Copy link
Member Author

/backport to release/6.0-rc2

@github-actions
Copy link
Contributor

Started backporting to release/6.0-rc2: https://github.com/dotnet/aspnetcore/actions/runs/1242932944

@captainsafia captainsafia enabled auto-merge (squash) September 16, 2021 19:43
/// <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";
Copy link
Contributor

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?

Copy link
Member Author

@captainsafia captainsafia Sep 16, 2021

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.

@captainsafia captainsafia merged commit a18ae25 into main Sep 16, 2021
@captainsafia captainsafia deleted the safia/validprob-json branch September 16, 2021 20:58
@ghost ghost added this to the 7.0-preview1 milestone Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Projects
None yet
4 participants