Tag: asp.net mvc apiexplorer

WebAPI帮助页面 – 返回或参数模型/类属性的文档

我正在使用Web API帮助页面与Web API 2(5.0) – 两个最新的Nuget包。 我想帮助文档显示属性的注释,这些类是参数或在HttpResponseMessage的主体中返回。 例如,我有一个像这样的控制器方法: public HttpResponseMessage Post([FromBody] MyClassType1 myClass) { // Business logic removed for clarity return Request.CreateResponse(HttpStatusCode.OK, new MyClassType2()); } 我希望MyClassType1和MyClassType2上的XML注释显示在上述post操作的帮助页面上。 我看过的所有地方,到目前为止看来还没有支持。 但是,我想知道是否有人能通过扩展ApiExplorer,添加到XmlDocumentationProvider等来实现这一点? 我知道注释和属性包含在生成的XML文件中,所以我可以尝试手动解析(所有参数和返回类型都在MyAssemblyName.Models命名空间中,所以我的想法是我可以查找XML具有以该命名空间开头的成员名称的节点。但是,我知道内置的Web API帮助页面具有一些缓存function,所以我更喜欢以某种方式将其与现有function相结合(只需添加它)。 我已经设法通过更新Parameters.cshtml模板来显示参数的类型(仅向下一层): @using System.Reflection @using System.Threading @using System.Web.Http.Description @using Regency.API.Services.Areas.HelpPage @model System.Collections.ObjectModel.Collection NamePropertiesDescriptionAdditional information @foreach (ApiParameterDescription parameter in Model) { string parameterDocumentation = parameter.Documentation ?? “No […]

ASP.NET Web API从模型 – 帮助页面生成所有参数

我正忙着创建Web API(在asp mvc4应用程序中)。 我正在使用asp.net网站上建议的库来生成文档( http://www.asp.net/web-api/overview/creating-web-apis/creating-api-help-pages )。 我的问题是,如果我的参数是模型,那么我无法在生成的帮助页面中指定模型包含的属性。 这是一个例子: 模型: public class TestModel { property String FirstName {get;set;} property String Surname {get; set;} property Boolean Active {get;set;} } 行动: /// /// This is a test action /// /// this is the model <– this works /// This is the first name <– doesn't work /// This […]

ASP.Net Web Api – ApiExplorer不包含任何ApiDescriptions

我正在尝试在我的Web服务的控制器中实现一个Options方法,该方法将返回一个消息,其中包含与控制器关联的URI端点的有效HTTP方法。 我的Options方法看起来像这样: public HttpResponseMessage Options() { var resp = new HttpResponseMessage(); resp.Content = new StringContent(“”); var apiExplorer = GlobalConfiguration.Configuration.Services .GetApiExplorer(); foreach (ApiDescription api in apiExplorer.ApiDescriptions) { resp.Content.Headers.Add(“Allow”, api.HttpMethod.Method); } return resp; } 我在具有Get,Post和Delete方法的控制器内部的全新Web Api项目(暗示:未改变的路由)中尝试了上述方法。 正如预期的那样,返回带有“Allow:GET,POST,DELETE”的响应。 但是,我遇到了麻烦,将其添加到我正在处理的更大的项目中。 在较大的项目中,ApiExplorer中的ApiDescriptions列表不包含任何元素。 为什么是这样? 我怀疑这是由于已经实现的自定义路由,尽管怀疑的唯一依据是以下链接: http://forums.asp.net/t/1821651.aspx/1 有没有其他人经历过这个空的ApiDescription列表? 如果是这样,你找到了补救措施吗? 注意:我使用的是MCV 4 RC