Does Swashbuckle.AspNetCore support documentation

2019-09-14 13:14发布

问题:

I follow the instructions by https://github.com/domaindrivendev/Swashbuckle.AspNetCore

  1. create a new asp.net core web api project
  2. add nugget package Swashbuckle.AspNetCore
  3. Add code for swagger
services.AddSwaggerGen(options =>
    {
        options.SwaggerDoc("v1", new Info
        {
            Version = "v1",
            Title = "API (version 1.0)",
            Description = "A RESTFUL API"
        });
        options.IncludeXmlComments(xmlDocPath);                
    });


app.UseSwagger();

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "API");
});
  1. Add code for controller
//[Route("{abc}/v1/Values")]
[Route("v1/Values")]
public class ValuesController : Controller
{
    // GET api/values
    /// <summary>
    /// aaaaaaaaaaaaaaaaaaaaaa
    /// </summary>
    /// <returns></returns>

    [HttpGet]
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // POST api/values
    /// <summary>
    /// bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    /// </summary>
    /// <param name="value"></param>
    [HttpPost]
    public void Post([FromBody]string value)
    {
    }
}

Run it, the api service works fine, and the swagger works fine with documentation.

If I change the Route from [Route("v1/Values")] to [Route("{abc}/v1/Values")], the api service works fine, but the swagger shows 500 error.

If I change Route from [Route("v1/Values")] to [Route("{abc}/v1/Values")] and remove the documentation, comment following code options.IncludeXmlComments(xmlDocPath) the api service works fine, and the swagger works fine without documentation.

Based on above, seems Swashbuckle.AspNetCore doesn’t support documentation when route has parameter, is it true? If no, does anyone know how to address it?