Skip to content
2 changes: 2 additions & 0 deletions aspnetcore/release-notes/aspnetcore-10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ This section describes new features for minimal APIs.

[!INCLUDE[](~/release-notes/aspnetcore-10/includes/MinApiEmptyStringInFormPost.md)]

[!INCLUDE[](~/release-notes/aspnetcore-10/includes/ValidationSupportMinAPI.md)]

## OpenAPI

This section describes new features for OpenAPI.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
### Validation support in Minimal APIs

<!-- https://github.com/captainsafia/minapi-validation-support -->

Support for validation in Minimal APIs is now available. This feature allows you to request validation of data
sent to your API endpoints. When validation is enabled, the ASP.NET Core runtime will perform any validations
defined on query, header, and route parameters, as well as on the request body.
Validations can be defined using attributes in the `System.ComponentModel.DataAnnotations` namespace.
sent to your API endpoints.

When validation is enabled, the ASP.NET Core runtime will perform any validations
defined on the:

* Query
* Header
* Request body

Validations can be defined using attributes in the [`DataAnnotations`](xref:System.ComponentModel.DataAnnotations) namespace.
Developers can customize the behavior of the validation system by:

- creating custom [ValidationAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.validationattribute?view=net-9.0) implementations
- implement the [IValidatableObject](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.dataannotations.ivalidatableobject?view=net-9.0) interface for complex validation logic
* Creating custom [`[Validation]`](xref:System.ComponentModel.DataAnnotations.ValidationAttribute) attribute implementations.
* Implementing the [`IValidatableObject`](xref:System.ComponentModel.DataAnnotations.IValidatableObject) interface for complex validation logic.

When validation fails, the runtime will return a 400 Bad Request response with
details of the validation errors.

#### Enable built-in validation support for minimal APIs

To enable built-in validation support for minimal APIs, call the `AddValidation` extension method to register
the required services into the service container for your application.
the required services in the service container for your application.

```csharp
builder.Services.AddValidation();
Expand All @@ -30,4 +37,4 @@ app.MapPost("/products",
([EvenNumber(ErrorMessage = "Product ID must be even")] int productId, [Required] string name)
=> TypedResults.Ok(productId))
.DisableValidation();
```
```