Why this matters
Without ProducesResponseTypeAttribute, Swagger cannot infer the response type of an action returning IActionResult, making API documentation unclear and unreliable.
Without ProducesResponseTypeAttribute, Swagger cannot infer the response type of an action returning IActionResult, making API documentation unclear and unreliable.
Without ProducesResponseTypeAttribute, Swagger cannot infer the response type of an action returning IActionResult, making API documentation unclear and unreliable.
Side-by-side examples engineers can pattern-match during review.
[HttpGet("foo")]
// Noncompliant: Use the ProducesResponseType overload containing the return type for succesful responses.
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult MagicNumber() => Ok(42);[HttpGet("foo")]
[ProducesResponseType<int>(StatusCodes.Status200OK)]
public IActionResult MagicNumber() => Ok(42);[HttpGet("foo")]
// Noncompliant: Use the ProducesResponseType overload containing the return type for succesful responses.
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult MagicNumber() => Ok(42);[HttpGet("foo")]
[ProducesResponseType<int>(StatusCodes.Status200OK)]
public IActionResult MagicNumber() => Ok(42);From the same buckets as this rule.