Open
Description
Data annotations (validators) are not being validated on objects containing open complex types.
Assemblies affected
OData WebApi 7 Beta 4
Reproduce steps
1- Define an object containing an open complex type and configure it accordingly:
public class PaymentMethod
{
public string Key { get; set; }
public IDictionary<string, object> Properties { get; } = new Dictionary<string, object>();
}
2- Define another object and decorate one of its properties with i.e. DataRange:
public class CreditCard
{
[DataRange(1, 12)]
public int ExpiryMonth { get; set; }
}
3- POST (or PUT) a JSON body that violates the condition:
{
"Key": "xyz",
"Card": {
"@odata.type": "#Namespace.CreditCard",
"ExpiryMonth": 13
}
}
Expected result
Since the provided value (13) violates the DataRange(1, 12) condition, the model state should be invalid.
if (!ModelState.IsValid)
return BadRequest(ModelState);
Actual result
The model state is valid.
Additional detail
Data annotations (validators) are working as expected on the main object, but not on the open complex type objects.
Metadata
Metadata
Assignees
Labels
No labels