Model:
public class ClientSetupDto
{
public byte Status { get; set; } = 0;
public string ClientName { get; set; }
public string ClientId { get; set; }
}
API Request:
[HttpPost]
[ProducesResponseType(200)]
[ProducesResponseType(400)]
public async Task<ActionResult<BaseCommandResponse>> Post([FromBody] ClientSetupDto entity)
{
... some code here ...
}
Accepted API Request - No problem here
{
"status": 0,
"clientName": "string",
"clientId": "string",
}
Not Accepted.
{
"status": "",
"clientName": "string",
"clientId": "string",
}
I do understand the Status property is of byte type in DTO and can not accept string or null values. In this case
ClientSetupDto entity
returns null and API throws a null value exception.
I want to achieve one of below:
1-Disable DTO model validation at API level. I have exception handling at a later stage
2-ClientSetupDto return whatever values passed into it and does not return null.
What I have tried:
In program.cs I implemented below but it does not work:
builder.Services.Configure<ApiBehaviorOptions>(opt => {
opt.SuppressModelStateInvalidFilter = true;
});