aspnetcore/release-notes/aspnetcore-10/includes/ValidationSupportMinAPI.md
Support for validation in Minimal APIs is now available. This feature allows you to request validation of data sent to your API endpoints. Enabling validation allows the ASP.NET Core runtime to perform any validations defined on the:
Validations are defined using attributes in the DataAnnotations namespace. Developers customize the behavior of the validation system by:
[Validation] attribute implementations.IValidatableObject interface for complex validation logic.If validation fails, the runtime returns a 400 Bad Request response with details of the validation errors.
Enable the built-in validation support for Minimal APIs by calling the AddValidation extension method to register the required services in the service container for your application:
builder.Services.AddValidation();
The implementation automatically discovers types that are defined in Minimal API handlers or as base types of types defined in Minimal API handlers. An endpoint filter performs validation on these types and is added for each endpoint.
Validation can be disabled for specific endpoints by using the DisableValidation extension method, as in the following example:
app.MapPost("/products",
([EvenNumber(ErrorMessage = "Product ID must be even")] int productId, [Required] string name)
=> TypedResults.Ok(productId))
.DisableValidation();
[!NOTE] Several small improvements and fixes have been made to the Minimal APIs validation generator introduced in ASP.NET Core for .NET 10. To support future enhancements, the underlying validation resolver APIs are now marked as experimental. The top-level
AddValidationAPIs and the built-in validation filter remain stable and non-experimental.