I have below Endpoint in ASP.Net Core 2.1
with EF Core 2.1
public class CustomerController
{
public IActionResult Post([FromBody]CustomerTO customer)
{
}
public IActionResult Get(int id)
{
var customer = _dal.GetCustomer(id);
return Ok(customer);
}
}
CustomerTO looks as
public class CustomerTO
{
public int CustomerId { get; set; }
public string CustomerName { get; set; }
//others
}
Now the issue is in Swagger docs, the request payload for POST includes CustomerId: 0
(however optional)
So the consumer of the API passes CustomerId = someInt in the POST request, as its an Identity property in EF Core Dal, it throws the error
Cannot insert value on Identity column...
This error is quite obvious & acceptable,
what is my requirement how do I make Swagger aware that CustomerId is not part of request payload in POST request?
Creating a separate DTO for Get & Post seems an overhead.
Thanks!!