-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed as duplicate of#61219
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIsIssues related to model validation in minimal and controller-based APIs
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I'm trying the new validation support that comes with .NET 10 Preview 3. Validation errors aren't returned as ProblemDetails response.
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Http.Validation;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddValidation();
builder.Services.AddProblemDetails();
builder.Services.AddOpenApi();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseExceptionHandler();
app.UseStatusCodePages();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/openapi/v1.json", app.Environment.ApplicationName);
});
}
app.MapPost("/api/todo", (Todo todo) =>
{
return TypedResults.Ok();
});
app.Run();
[ValidatableType]
public class Todo
{
[Required]
[Range(1, 10)]
public int Id { get; set; }
[StringLength(10)]
public required string Title { get; set; }
}If I try to make a POST request with Id = 0, I get this error:
{
"title": "One or more validation errors occurred.",
"errors": {
"Id": [
"The field Id must be between 1 and 10."
]
}
}And the Content-Type of the response is application/json, while it should be application/problem+json.
Expected Behavior
The validation error should use ProblemDetails service and return the application/problem+json Content Type.
Steps To Reproduce
Minimal repro at https://github.com/marcominerva/OpenApi10
.NET Version
10.0.100-preview.3.25201.16
Metadata
Metadata
Assignees
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIsIssues related to model validation in minimal and controller-based APIs