I am using a swagger 4.0 with Asp.net core 2.2 Web Api. I want to tell the swagger UI on post/put method that some of the body content parameters are required. As I know that if the parameter is query parameter then it is required. Done some research https://swagger.io/docs/specification/2-0/describing-request-body/ and found that the body content can be made required
Some of the research from other link
How to mark a property as required in Swagger, without ASP.NET model validation?
How can I tell Swashbuckle that the body content is required?
Controller code
[HttpPost]
public async Task<IActionResult> Create([FromBody]LearningApplication model)
{
if (!ModelState.IsValid) return InvalidModelState(ModelState);
// create the record,no need to provide resource auth as only admin can action this controller
await _learningApplicationManager.CreateAsync(model, LearningApplicationValidator.OnCreateRuleset);
return Created(url, model);
}
Model
public class LearningApplication : BaseAuditableWithLogicalDeleteAggregate<Guid>
{
[Required(AllowEmptyStrings = false, ErrorMessage = "You must enter the name of the course or professional Learning session")]
[DataMember]
public string CourseName { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "You must enter the professional Learning provider: ie. TGS, AGSV, etc")]
[DataMember]
public string Provider { get; set; }
[DataMember]
public string EventWebsite { get; set; }
[DataMember]
public string RegistrationExpenses { get; set; }
[Required(ErrorMessage = "Please provide the Start Date & time")]
[DataMember]
public DateTime? StartDateTime { get; set; }
}
Current Swagger display