Skip to content

Commit 76734fd

Browse files
Apply suggestions from code review
Added review suggestions by mikekistler. Consolidate. Co-authored-by: Mike Kistler <[email protected]>
1 parent 3b58a3f commit 76734fd

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

aspnetcore/fundamentals/minimal-apis.md

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ Support for validation in Minimal APIs is now available. This feature allows you
7878
* Header
7979
* Request body
8080

81-
Validations are defined using attributes in the [`DataAnnotations`](xref:System.ComponentModel.DataAnnotations) namespace. Developers customize the behavior of the validation system by:
81+
Validations are defined using attributes in the [`DataAnnotations`](xref:System.ComponentModel.DataAnnotations) namespace.
82+
83+
When a parameter to a Minimal API endpoint is a class or record type, validation attributes are automatically applied. For example:
84+
85+
```csharp
86+
public record Product(
87+
[Required] string Name,
88+
[Range(1, 1000)] int Quantity);
8289

8390
* Creating custom [`[Validation]`](xref:System.ComponentModel.DataAnnotations.ValidationAttribute) attribute implementations.
8491
* Implementing the [`IValidatableObject`](xref:System.ComponentModel.DataAnnotations.IValidatableObject) interface for complex validation logic.
@@ -104,28 +111,6 @@ app.MapPost("/products",
104111
.DisableValidation();
105112
```
106113

107-
### Validation with record types
108-
<!-- https://github.com/dotnet/aspnetcore/pull/61193 -->
109-
<!-- https://github.com/dotnet/aspnetcore/pull/61402 -->
110-
111-
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:
112-
113-
```csharp
114-
public record Product(
115-
[Required] string Name,
116-
[Range(1, 1000)] int Quantity);
117-
```
118-
119-
When using record types as parameters in Minimal API endpoints, validation attributes are automatically applied in the same way as class types:
120-
121-
```csharp
122-
app.MapPost("/products", (Product product) =>
123-
{
124-
// Endpoint logic here
125-
return TypedResults.Ok(product);
126-
});
127-
```
128-
129114
## Responses
130115

131116
Route handlers support the following types of return values:

0 commit comments

Comments
 (0)