Open
Description
Describe the bug
API analyzers should flag an undeclared 200 status code, and provide an option to fix it.
To Reproduce
Steps to reproduce the behavior:
- Using ASP.NET Core 3.0 with analyzers enabled
<PropertyGroup>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
</PropertyGroup>
- Run this code (adapted from this sample with the ProducesResponseType attribute removed)
// GET api/contacts/{guid}
[HttpGet("{id}", Name = "GetById")]
public IActionResult Get(string id)
{
var contact = _contacts.Get(id);
if (contact == null)
{
return NotFound();
}
return Ok(contact);
}
- The API analyzer flags the NotFound using a warning (this is expected).
- The API analyzer does not flag the return Ok(...); (not expected)
Expected behavior
- The API analyzer does flag the return Ok(...) using a warning.
- An option to fix this warning is provided, choosing it adds the following attribute
[ProducesResponseType(typeof(Contact),
StatusCodes.Status200OK)]
Why I think this is a bug
From the docs:
The analyzers package notifies you of any controller action that:
- Returns an undeclared status code.
- Returns an undeclared success result.
Additional context
Follow up to dotnet/AspNetCore.Docs#15269 (comment)
.NET Core SDK: 3.0.100
.NET Core runtimes installed:
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Metadata
Metadata
Assignees
Labels
Work that is nice to haveThis issue impacts only small number of customersIndicates an issue which is related to analyzer experienceIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesThis issue represents an ask for new feature or an enhancement to an existing oneThis label is used by an internal tool