包括XML注释 - Swashbuckle

时间:2017-01-11 01:21:51

标签: asp.net-mvc asp.net-web-api

Xml评论未显示

我正在效仿: https://github.com/domaindrivendev/Swashbuckle

我的代码如下所示:

var baseDirectory = System.String.Format(@"{0}bin\", AppDomain.CurrentDomain.BaseDirectory);
var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML";
var commentsFile = Path.Combine(baseDirectory, commentsFileName);
c.SingleApiVersion("v1", "Documentação web Api");

在我的DefaultController中 enter image description here

[RoutePrefix("api")]
public class DefaultController : ApiController
{
    /// <summary>
    /// Register a new user on application
    /// </summary>
    /// <param name="user">New user to register</param>
    /// <remarks>Adds new user to application and grant access</remarks>
    /// <response code="400">Bad Request</response>
    /// <response code="500">Internal Server Error</response>

    [HttpGet]
    [Route("consulta/BuscaProduto")]
    //localhost:50907/api/consulta/BuscaProduto
    public HttpResponseMessage BuscaProduto()
    {
        try
        {
            var tTabela = new ProdutoAplicacao();
            var listar = tTabela.ListaTodos();
            return Request.CreateResponse(HttpStatusCode.OK, listar, Configuration.Formatters.JsonFormatter);
        }
        catch (Exception ex)
        {

            return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
        }
    }

}

enter image description here

1 个答案:

答案 0 :(得分:1)

我最近一直在努力解决这个问题:)

如果明确指定了任何响应,Swashbuckle将不会自动生成200个成功响应,其中包含模型和示例值。

在您的情况下,因为您指定了&#34; 400&#34;和&#34; 500&#34;回复,Swashbuckle希望你也指定&#34; 200&#34;响应。我认为你有两个选择:

  1. 在指定其他响应的每个端点的XML注释中指定200响应
  2. Add the 200 responses programmatically在SwaggerConfig中使用操作过滤器