swagger 4.0 Asp.net core 2.2需要的主体参数

时间:2019-02-12 23:56:13

标签: c# asp.net-core swagger

我正在使用带有Asp.net核心2.2 Web Api的swagger 4.0。我想告诉有关post / put方法的大方用户界面,某些身体内容参数是必需的。据我所知,如果参数是查询参数,那么它是必需的。做过一些研究https://swagger.io/docs/specification/2-0/describing-request-body/,发现可以要求提供身体内容

swagger document

一些来自其他链接的研究

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?

控制器代码

[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);
        }

模型

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; }
}

当前Swagger显示

current swagger

0 个答案:

没有答案