Skip to content

Commit

Permalink
Avoid using invalid content type for ValidationProblemDetails (dotnet…
Browse files Browse the repository at this point in the history
  • Loading branch information
captainsafia authored Sep 16, 2021
1 parent 068797e commit a18ae25
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public static DelegateEndpointConventionBuilder ProducesProblem(this DelegateEnd
/// </summary>
/// <param name="builder">The <see cref="DelegateEndpointConventionBuilder"/>.</param>
/// <param name="statusCode">The response status code. Defaults to StatusCodes.Status400BadRequest.</param>
/// <param name="contentType">The response content type. Defaults to "application/validationproblem+json".</param>
/// <param name="contentType">The response content type. Defaults to "application/problem+json".</param>
/// <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";
}

return Produces<HttpValidationProblemDetails>(builder, statusCode, contentType);
Expand Down
4 changes: 2 additions & 2 deletions src/Mvc/Mvc.ApiExplorer/test/ApiResponseTypeProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ public void GetApiResponseTypes_HandlesActionWithMultipleContentTypesAndProduces
// Arrange
var actionDescriptor = GetControllerActionDescriptor(typeof(TestController), nameof(TestController.GetUser));
actionDescriptor.FilterDescriptors.Add(new FilterDescriptor(new ProducesAttribute("text/xml") { Type = typeof(BaseModel) }, FilterScope.Action));
actionDescriptor.FilterDescriptors.Add(new FilterDescriptor(new ProducesResponseTypeAttribute(typeof(ValidationProblemDetails), 400, "application/validationproblem+json"), FilterScope.Action));
actionDescriptor.FilterDescriptors.Add(new FilterDescriptor(new ProducesResponseTypeAttribute(typeof(ValidationProblemDetails), 400, "application/problem+json"), FilterScope.Action));
actionDescriptor.FilterDescriptors.Add(new FilterDescriptor(new ProducesResponseTypeAttribute(typeof(ProblemDetails), 404, "application/problem+json"), FilterScope.Action));
actionDescriptor.FilterDescriptors.Add(new FilterDescriptor(new ProducesResponseTypeAttribute(409), FilterScope.Action));

Expand All @@ -738,7 +738,7 @@ public void GetApiResponseTypes_HandlesActionWithMultipleContentTypesAndProduces
{
Assert.Equal(typeof(ValidationProblemDetails), responseType.Type);
Assert.Equal(400, responseType.StatusCode);
Assert.Equal(new[] { "application/validationproblem+json" }, GetSortedMediaTypes(responseType));
Assert.Equal(new[] { "application/problem+json" }, GetSortedMediaTypes(responseType));
},
responseType =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ public void HandlesProducesWithProducesProblem()
{
Assert.Equal(typeof(HttpValidationProblemDetails), responseType.Type);
Assert.Equal(400, responseType.StatusCode);
Assert.Equal(new[] { "application/validationproblem+json" }, GetSortedMediaTypes(responseType));
Assert.Equal(new[] { "application/problem+json" }, GetSortedMediaTypes(responseType));
},
responseType =>
{
Expand Down

0 comments on commit a18ae25

Please sign in to comment.