FromRequest Attribute
The [FromRequest] attribute lets you combine data from multiple parts of an HTTP request — body, route, and query string — into a single model object. See FromRequest Attribute for full details on how model binding works.
OpenAPI documentation
Section titled “OpenAPI documentation”Without special handling, parameters decorated with [FromRequest] would appear as individual query/route parameters in the API documentation even though they are bound as a single body object at runtime. The FromRequestOperationTransformer and FromRequestSchemaTransformer correct this.
What the transformers do
Section titled “What the transformers do”-
FromRequestOperationTransformer— For each parameter marked[FromRequest]:- Removes the parameter from the
parameterslist of the operation. - Creates a
requestBodyentry using the parameter’s type schema.
- Removes the parameter from the
-
FromRequestSchemaTransformer— Ensures the schema for the request body accurately reflects the model’s properties, excluding any properties that come from route or query binding.
Example
Section titled “Example”public record UpdateCustomerRequest( [property: FromRoute] CustomerId CustomerId, string Name, string Email);
[HttpPut("{customerId}")]public Task UpdateCustomer([FromRequest] UpdateCustomerRequest request) { ... }The generated OpenAPI operation will show:
- Path parameter:
customerId(from the route) - Request body: a JSON schema with
nameandemailproperties
Rather than listing all three as individual query/route parameters.