ConfigureApiBehaviorOptions customizes the conventions applied to ASP.NET Core API controllers. Call it on the IMvcBuilder returned by AddControllers in Program.cs when the defaults do not fit your API, such as an existing specification. The default conventions usually reduce boilerplate by binding request bodies automatically, returning 400 responses for invalid models, and producing ProblemDetails responses. section 20.4 section 20.7
Disable automatic validation responses
builder.Services.AddControllers() .ConfigureApiBehaviorOptions(options => { options.SuppressModelStateInvalidFilter = true; }); This leaves invalid-model handling to controller code instead of automatically returning a 400 Bad Request response. Keep the defaults unless custom behavior is genuinely needed. section 20.4
Listing 20.12 Customizing [ApiAttribute] behaviors
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
.ConfigureApiBehaviorOptions(options => #1
{
options.SuppressModelStateInvalidFilter = true; #2
});
// ...
Inspect the complete service-registration example showing where the configuration lambda belongs and which option disables the automatic invalid-model filter. section 20.4
