Swashbuckle parameter descriptions

Slicc picture Slicc · Jun 7, 2016 · Viewed 35.6k times · Source

I'm using SwaggerResponse attributes to decorate my api controller actions, this all works fine, however when I look at the generated documentation the description field for parameters is empty.

Is a there an attribute based approach to describe action parameters (rather than XML comments)?

Answer

Juliën picture Juliën · Feb 3, 2017

With the latest Swashbuckle, or better said at least the Swashbuckle.AspNetCore variant which I'm using, the Description field for parameters can now be displayed correctly as output.

It does require the following conditions to be met:

  • XML comments must be enabled and configured with Swagger
  • Parameters should be explicitly decorated with either [FromRoute], [FromQuery], [FromBody] or [FromUri]
  • The same for the method type (get/post/put etc.), which should be decorated with [Http...]
  • Describe the parameter as usual with a <param ...> xml comment

A full sample looks like this:

/// <summary>
/// Short, descriptive title of the operation
/// </summary>
/// <remarks>
/// More elaborate description
/// </remarks>
/// <param name="id">Here is the description for ID.</param>
[ProducesResponseType(typeof(Bar), (int)HttpStatusCode.OK)]
[HttpGet, Route("{id}", Name = "GetFoo")]
public async Task<IActionResult> Foo([FromRoute] long id)
{
    var response = new Bar();
    return Ok(response);
}

Which produces the following output:

Swagger output with parameter description