asp.net-core – 在Swagger中使用属性XML注释作为参数描述
我使用ASP.NET Core创建了一个Web API,并使用swagger来创建文档.我在API端点上使用
XML注释来提供文档中的其他信息.招摇的配置是:
services.AddSwaggerGen(c => { c.SwaggerDoc("v1",new Info { Title = "My API",Version = "v1" }); // Set the comments path for the Swagger JSON and UI. var basePath = AppContext.BaseDirectory; var xmlPath = Path.Combine(basePath,"MyAPI.xml"); c.IncludeXmlComments(xmlPath); }); 我的一个API端点及其XML注释是: /// <summary> /// Find an existing appointment using the visitor information: First name,last name,email,phone. /// </summary> /// <url>http://apiurl/api/appointments/appointmentsByVisitor</url> /// <param name="criteria">consists of one or more of: Firstname,lastname,phone</param> /// <returns>Existing appointment data in an Appointment object or a business error.</returns> /// <response code="200">Returns the existing appointment event.</response> /// <response code="400">Returns if no parameters are specified.</response> /// <response code="204">Returns if there's no matching appointment.</response> /// <response code="500">Returns if there's an unhandled exception.</response> [Authorize] [HttpGet("appointmentsByVisitor")] [ProducesResponseType(typeof(Appointment),200)] [ProducesResponseType(typeof(BusinessError),404)] public IActionResult AppointmentsByVisitor([FromQuery] VisitorSearchCriteria criteria) {} VisitorSearchCriteria是一个单独的类,它是API端点所期望的参数的包装器. public class VisitorSearchCriteria { /// <summary> /// Visitor first name. /// </summary> public string FirstName { get; set; } /// <summary> /// Visitor last name. /// </summary> public string LastName { get; set; } // several other properties.... } 此API端点的swagger文档将VisitorSearchCriteria的所有属性显示为参数,但它不会选择XML注释.请参见下面的截图. 如您所见,缺少参数的描述.如何告诉swagger使用该外部类的XML注释来创建参数描述? 解决方法
http://wmpratt.com/swagger-and-asp-net-web-api-part-1/
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – MVC导航到不同的控制器视图
- asp.net-core – ASPNetCore – 通过REST上传文件
- asp.net – Azure服务架构与Docker一样吗?
- asp.net-mvc-3 – 偶数和奇数表行与Razor
- asp.net – 导致StackOverflowException的Sitecore控制器渲
- asp.net-mvc – 在WebApi的ActionFilterAttribute的OnActio
- asp.net-core – AppSettings.*.json文件未在ASP.NET CORE
- 在ASP.NET中使用querystring的最佳做法?
- asp.net – 让Visual Studios使用子域名?
- asp.net中的GridView分页问题
- asp.net-mvc-4 – 如何在ASP.NET MVC 4中从数据库
- ASP.Net Core下Authorization的几种方式
- asp.net-mvc – 如何从ASP.NET MVC 3中的授权过滤
- 白话ASP.NET MVC之三:Controller是如何解析出来
- 如何在ASP.NET Core MVC 6中强制执行小写路由?
- asp.net – 从.net应用程序下载4GB文件
- asp.net-mvc-4 – MVC 4 DropDownListFor错误 –
- ASP.NET MVC – 如何处理发送电子邮件?
- asp.net-mvc – 加载符号时Visual Studio调试痛苦
- asp.net-mvc – 从单个Web服务器迁移到多个Web服