Skip to content

Commit d922a72

Browse files
WN v10prev4: Min API Validation supports record types (#35448)
* WN v10prev4: Min API Validation supports record types * Added link to bring in include * Update aspnetcore/release-notes/aspnetcore-10/includes/MinimalAPIValidationRecordTypes.md Co-authored-by: Luke Latham <[email protected]> * Update aspnetcore/release-notes/aspnetcore-10/includes/MinimalAPIValidationRecordTypes.md Co-authored-by: Luke Latham <[email protected]> * Update aspnetcore-10.0.md Update to latest on main plus the link for this new subtopic --------- Co-authored-by: Luke Latham <[email protected]>
1 parent b0073fd commit d922a72

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

aspnetcore/release-notes/aspnetcore-10.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ This section describes new features for minimal APIs.
3939

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

42+
[!INCLUDE[](~/release-notes/aspnetcore-10/includes/MinimalAPIValidationRecordTypes.md)]
43+
4244
[!INCLUDE[](~/release-notes/aspnetcore-10/includes/sse.md)]
4345

4446
## OpenAPI
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
### Improvements to Minimal APIs Validation
2-
1+
#### Validation with record types
32
<!-- https://github.com/dotnet/aspnetcore/pull/61193 -->
43
<!-- https://github.com/dotnet/aspnetcore/pull/61402 -->
5-
Beginning in Preview 4, ASP.NET Core supports validation on record types. With this enhancement,
6-
inputs to API endpoints defined using `record` types are now validated automatically, in the same way as
7-
class types.
4+
5+
Minimal APIs also support validation with C# record types. Record types can be validated using attributes from the <xref:System.ComponentModel.DataAnnotations?displayProperty=fullName> namespace, similar to classes. For example:
6+
7+
```csharp
8+
public record Product(
9+
[Required] string Name,
10+
[Range(1, 1000)] int Quantity);
11+
```
12+
13+
When using record types as parameters in Minimal API endpoints, validation attributes are automatically applied in the same way as class types:
14+
15+
```csharp
16+
app.MapPost("/products", (Product product) =>
17+
{
18+
// Endpoint logic here
19+
return TypedResults.Ok(product);
20+
});
21+
```

0 commit comments

Comments
 (0)