Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 943
GoldieLocks Avatar asked Oct 20 '25 13:10

GoldieLocks


1 Answers

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">return Product with spacific id</response>
/// <response code="400">Product Not found</response>
/// <response code="500">Oops! Can't Found your product right now due to internal error</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

like image 163
Ibram Reda Avatar answered Oct 22 '25 02:10

Ibram Reda