简体   繁体   中英

Swashbuckle 5.4.0 and Xml Documentation

I've got Swashbuckle 5.4.0 installed with WebApi 2.2, IIS hosted. 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. 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. 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.

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 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:

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 . (eg M:.HelloWorldController.Get) whereas the xml created has a member name of M:HelloWorldController.Get, therefore the node is not found. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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