Swashbuckle.aspnetcore: SwaggerResponse attribute and xml comments with response codes are not honored in the UI

Created on 13 Jul 2016  路  1Comment  路  Source: domaindrivendev/Swashbuckle.AspNetCore

I've decoreated an action method of a controller with the SwaggerResponse attribute like that:
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(SomeType))]

But in UI I'm still getting:
swashbuckle swaggerresponse attribute is not honored

Neither the xml comments do the job:

    /// <response code="400">Bad request</response>
    /// <response code="500">Internal Server Error</response>

Most helpful comment

In the latest version (6.0.0-beta902), SwaggerResponseAttribute has been replaced in favor of AspNet Core's built-in ProducesResponseTypeAttribute. Using a combination of this and the XML comments you should be able to get the results you need:

/// <summary>
/// Creates an order 
/// </summary>
/// <param name="order"></param>
/// <response code="201">Order created</response>
/// <response code="400">Order invalid</response>
[HttpPost]
[ProducesResponseType(typeof(int), 201)]
[ProducesResponseType(typeof(IDictionary<string, string>), 400)]
public IActionResult Create([FromBody, Required]Order order)
{
    return new CreatedResult("/orders/1", 1);
}

>All comments

In the latest version (6.0.0-beta902), SwaggerResponseAttribute has been replaced in favor of AspNet Core's built-in ProducesResponseTypeAttribute. Using a combination of this and the XML comments you should be able to get the results you need:

/// <summary>
/// Creates an order 
/// </summary>
/// <param name="order"></param>
/// <response code="201">Order created</response>
/// <response code="400">Order invalid</response>
[HttpPost]
[ProducesResponseType(typeof(int), 201)]
[ProducesResponseType(typeof(IDictionary<string, string>), 400)]
public IActionResult Create([FromBody, Required]Order order)
{
    return new CreatedResult("/orders/1", 1);
}
Was this page helpful?
0 / 5 - 0 ratings