Hello, I use NSwag to generate C# Web API controller code from swagger document. and It looks like required field of path/query param is not "translated" into "System.ComponentModel.DataAnnotations.Required"
For instance: here's apart of my swagger path definition file
"/myroute": {
"get": {
"parameters": [
{
"name": "type",
"type": "string",
"in": "query",
"required": true // <--- required parameters
}
]
}
}
I would want the code generated to be
[Microsoft.AspNetCore.Mvc.HttpGet, Microsoft.AspNetCore.Mvc.Route("myroute")]
public Task<string> GetMethod([System.ComponentModel.DataAnnotations.Required] string type) // <-- The attribute Required was added
{
return type;
}
What is you opinion ?
I think the only thing needed is to modify the template Controller.liquid by adding
something like this :
{% if parameter.IsRequired %}[System.ComponentModel.DataAnnotations.Required]{% endif %}
In ASP.NET Core we need to use BindRequiredAttribute and not the data annotation's RequiredAttribute