[英]Swashbuckle 5.4.0 with ASP.NET MVC WebApi - No documentation is shown inside the swagger webpage
[英]Swashbuckle 5.4.0 and Xml Documentation
我已经将Swashbuckle 5.4.0与WebApi 2.2一起安装,并托管了IIS。 我基本的草签文档显示没有任何问题,但是我指向的XML文档中没有任何内容呈现在UI中,在JSON中也不可见。 因此,我所看到的只是没有注释,摘要等的方法。
我知道已找到XML文档,因为我没有收到任何错误(当我将路径更改为不存在的文件时,会出现错误),但是由于某种原因,它只是不包含文件中的任何内容。 我尝试为Swashbuckle和WebApi重新安装nuget软件包,尝试生成并重新生成XML,甚至尝试重建XML的基本版本以进行测试,但到目前为止还算运气。
对这里可能出什么问题的任何想法,或者我可以尝试的任何建议?
下面的代码段:
控制器:
[RoutePrefix("rest/v1/helloworld")]
public class HelloWorldController : ApiController
{
/// <summary>
/// Hello World
/// </summary>
/// <remarks>Hello World basic test</remarks>
/// <response code="401">Unauthorized</response>
[HttpGet]
[Route("")]
public HttpResponseMessage Get()
{
HttpActionContext aC = this.ActionContext;
return aC.Request.CreateResponse(HttpStatusCode.OK, "Hello World");
}
}
Xml文档:
<?xml version="1.0"?>
<doc>
<assembly>
<name>SwaggerApi</name>
</assembly>
<members>
<member name="M:HelloWorldController.Get">
<summary>Hello World</summary>
<remarks>Hello World basic test</remarks>
<response code="401">Unauthorized</response>
</member>
</members>
</doc>
SwaggerConfig.cs代码段:
EnableSwagger(c =>
{
c.SingleApiVersion("v1", "ASP");
c.IncludeXmlComments(string.Format(@"{0}\bin\SwaggerApi.xml",System.AppDomain.CurrentDomain.BaseDirectory));
})
找到了答案。 强制执行命名空间,这意味着存在于命名空间之外的任何对象都将具有xpath,其中包含以开头的方法名称。 (例如M:.HelloWorldController.Get),而创建的xml的成员名称为M:HelloWorldController.Get,因此找不到该节点。 这不仅会影响方法,还会影响参数,因此在没有命名空间的情况下定义的任何自定义对象也将导致无法找到该方法的成员节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.