Does Swashbuckle.AspNetCore support documentation when route has parameter?

你离开我真会死。 提交于 2019-12-12 03:48:52

问题


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?

来源:https://stackoverflow.com/questions/43320416/does-swashbuckle-aspnetcore-support-documentation-when-route-has-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!