Dr Schizo
Dr Schizo

Reputation: 4386

Swashbuckle SwaggerResponse not showing response model

I am using the latest version of Swashbuckle 5.1.3 and noticed there is a new attribute SwaggerResponse which allows you to document a response type for each response code. For example:

(https://github.com/domaindrivendev/Swashbuckle/issues/175 < might prove useful).

/// <summary>
/// Lovely.
/// </summary>
/// <param name="blah">Blah blah blah.</param>
/// <returns>Something special.</returns>
/// <response code="200">OK very nice.</response>
/// <response code="400">Invalid request.</response>
[SwaggerResponse(HttpStatusCode.OK, "A", typeof(Foo))]
[SwaggerResponse(HttpStatusCode.BadRequest, "B", typeof(Bar))]
public IHttpActionResult Get(string blah)
{
    // Some code
}

The initial response class is documented fine but further down where it shows a table of "Response Messages", the response model is empty (for 400 Bad Request). Can't see anywhere on screen where the other response type is documented.

Upvotes: 7

Views: 5396

Answers (1)

Calvin
Calvin

Reputation: 1163

The xml <response> and [SwaggerResponse] are not used at the same time. <response> tag will suppress your [SwaggerResponse]. Try remove all tag and you should see the model in swagger ui.

Upvotes: 5

Related Questions