Below is my request body for POST call to my web API.
{
"region" : "us-east-2",
"namespaceName" : "com.xyx.demo.test",
"tags": {
"description": "Test Namespace",
"purpose": "To store demo objects",
....
}
}
Here is the class that I am using to bind this request.
public class Input
{
public string Region { get; set; }
public string NamespaceName { get; set; }
[Description("A set of key value pairs that define custom tags.")]
public Dictionary<string, string> Tags { get; set; }
}
I want to restrict my Tags Dictionary to create only 10 keys and each key's value should have not more than 256 characters.
So my ModelState
should be invalid if more than 10 keys are provided or value contains more than 256 characters.
How can I do this using Data annotations ?