0
Good afternoon!
I have a Web API in . Net Core, where I have the following request class for a POST route:
public class CreateAgentRequest
{
[Required]
public Agent Agent { get; set; }
}
With Annotation Required, if I don’t send a field Agent
, it returns me the error in the following API call structure
However, I have a customized validation model, which are validations that I do not deal with Data Annotations, for example, that this data already exists in the database.
I have the need to customize this return of Data Annotation (first image), to follow the same pattern as the second image. Is there any way to customize the return of Data Annotation validation?
required is a Validationattribute. One option would be to implement your custom attribute, for example Representanteunicoattribute, and use it in the validation pipeline. Example: https://docs.microsoft.com/en-us/aspnet/core/mvc/models/validation?view=aspnetcore-2.2
– OnoSendai