I'm developing an API using ASP.NET 4.6 and Web API 2. So far, I've been using DTO's and DataAnnotations, which look like the following:
public class CustomerDTO
{
...
[Required]
public string Name { get; set; }
[StringLength(20, ErrorMessageResourceName = "Error", ErrorMessageResourceType = typeof(Resources), MinimumLength = 6)]
public string DocumentNumber { get; set; }
...
}
And I'd use my DTO's like this:
[ResponseType(typeof(CustomerDTO))]
public IHttpActionResult PostCustomer(CustomerDTO customer)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
...
}
Now I've been asked to release a first version of the API's documentation. After doing some research I discovered Swagger, so I got Swashbuckle from NuGet and started playing with it. Amazing, by the way.
But I do need the users of my API to know which is the max length for certain parameters, which ones are required, and so on. How do I get Swagger to show this information?