简体   繁体   English

Swashbuckle 5.4.0和Xml文档

[英]Swashbuckle 5.4.0 and Xml Documentation

I've got Swashbuckle 5.4.0 installed with WebApi 2.2, IIS hosted. 我已经将Swashbuckle 5.4.0与WebApi 2.2一起安装,并托管了IIS。 My basic swagger documents display without any issues, however nothing in the XML document I am pointing to is being rendered within the UI, nor is it visible in the JSON. 我基本的草签文档显示没有任何问题,但是我指向的XML文档中没有任何内容呈现在UI中,在JSON中也不可见。 So all I see are the methods with no remarks, summary, etc. 因此,我所看到的只是没有注释,摘要等的方法。

I know the XML document has been found as I don't get any errors (and when I change the path to a non existent file, an error appears) but for some reason it's just not including anything from within the file. 我知道已找到XML文档,因为我没有收到任何错误(当我将路径更改为不存在的文件时,会出现错误),但是由于某种原因,它只是不包含文件中的任何内容。 I've tried reinstalling the nuget packages for Swashbuckle and WebApi, I've tried generating and regenerating the XML, even tried rebuilding a basic version of the XML just to test, but so far no luck. 我尝试为Swashbuckle和WebApi重新安装nuget软件包,尝试生成并重新生成XML,甚至尝试重建XML的基本版本以进行测试,但到目前为止还算运气。

Any ideas for what could be going wrong here, or any suggestions that I could try? 对这里可能出什么问题的任何想法,或者我可以尝试的任何建议?

Code snippets below: 下面的代码段:

Controller: 控制器:

[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 Documentation: 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 snippet: SwaggerConfig.cs代码段:

EnableSwagger(c =>
{
    c.SingleApiVersion("v1", "ASP");
    c.IncludeXmlComments(string.Format(@"{0}\bin\SwaggerApi.xml",System.AppDomain.CurrentDomain.BaseDirectory));
})

Found the answer, sort of. 找到了答案。 Namespaces are being enforced, which means that any object existing outside of a namespace will have an xpath containing a method name starting with . 强制执行命名空间,这意味着存在于命名空间之外的任何对象都将具有xpath,其中包含以开头的方法名称。 (eg M:.HelloWorldController.Get) whereas the xml created has a member name of M:HelloWorldController.Get, therefore the node is not found. (例如M:.HelloWorldController.Get),而创建的xml的成员名称为M:HelloWorldController.Get,因此找不到该节点。 This doesn't just affect methods, it also affects params, so any custom objects that are defined without a namespace will also cause a failure to find the member node for the method. 这不仅会影响方法,还会影响参数,因此在没有命名空间的情况下定义的任何自定义对象也将导致无法找到该方法的成员节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM