繁体   English   中英

包含<returns> Swagger Swashbuckle C# 中的 XML 文档块

[英]Including <returns> XML documentation block in Swagger Swashbuckle C#

如果我创建一个方法如下:

    /// <summary>
    /// Summary here
    /// </summary>
    /// <returns>THIS DOES NOT SHOW ANYWHERE</returns>
    /// <remarks>Remarks here</remarks>
    public async Task<string> MyMethod()
    {
        return "Hello World";
    }

我已经安装并设置了 Swashbuckle.AspNetCore,然后正确生成了文档,除了<returns>块中的值不会生成到 json 中的任何内容中:

"/api/v1.0/Exhibits/TestMethod1": {
      "get": {
        "tags": [
          "Blah"
        ],
        "summary": "Summary here",
        "description": "Remarks here",
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "string"
                }
              },
              "application/json": {
                "schema": {
                  "type": "string"
                }
              },
              "text/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },

我如何说服它将此导出到相关领域,或者这是不可能的?

响应文档(端点的返回)由定义完整记录
每个状态代码的描述、内容类型、架构等

所以返回描述是不同的,取决于每个响应中的状态代码。 所以你需要为每个状态代码指定什么是描述。

Swagger 使用一个或多个<response code="xxx">而不是单个<returns>

你的文件应该是这样的

/// <summary>
/// Retrieves a specific product by unique id
/// </summary>
/// <remarks>Awesomeness!</remarks>
/// <response code="200">Product created</response>
/// <response code="400">Product has missing/invalid values</response>
/// <response code="500">Oops! Can't create your product right now</response>
[HttpGet("{id}")]
[ProducesResponseType(typeof(Product), 200)]
[ProducesResponseType(typeof(IDictionary<string, string>), 400)]
[ProducesResponseType(500)]
public Product GetById(int id)

阅读如何在 WebAPI 应用程序中的 Swagger UI 中添加方法描述以了解更多信息

暂无
暂无

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

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