If an ASP.NET Core Web API uses Swagger, the API documentation will be generated based on the input/output types
of the controller actions, as well as the attributes annotating the actions. If an action returns IActionResult or IResult, Swagger cannot infer the type of the response. From
the consumer’s perspective, this can be confusing and lead to unexpected results and bugs in the long run without the API provider’s awareness.
This rule raises an issue on a controller action when:
- The action returns a value in the happy path. This can be either:
- There is no
[ProducesResponseType]
attribute containing the return type, either at controller or action level.
- There is no
[SwaggerResponse]
attribute containing the return type, either at controller or action level.
- The controller is annotated with the
[ApiController]
attribute.
- The controller action returns either IActionResult or IResult.
- The application has enabled the Swagger
middleware.