'Including <returns> XML documentation block in Swagger Swashbuckle C#

If I create a method as follows:

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

And I have Swashbuckle.AspNetCore installed and setup, then the documentation is generated correctly, except the value in the <returns> block does not get generated into anything in the 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"
                }
              }
            }
          }
        }
      }
    },

How can I persuade it to export this to a relevant field, or is this not possible?



Solution 1:[1]

The return description is different, depend on status code in each response. so you need to specify what is description for each status code.

Swagger use one or more <response code="xxx"> instead of single <returns>

your document should be look like this

/// <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)

read How to add method description in Swagger UI in WebAPI Application for more

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1