Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -561,7 +561,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