-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
Priority:3Work that is nice to haveWork that is nice to haveaffected-fewThis issue impacts only small number of customersThis issue impacts only small number of customersanalyzerIndicates an issue which is related to analyzer experienceIndicates an issue which is related to analyzer experiencearea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-openapiseverity-blockingThis label is used by an internal toolThis label is used by an internal tool
Milestone
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]
kjkrum
Metadata
Metadata
Assignees
Labels
Priority:3Work that is nice to haveWork that is nice to haveaffected-fewThis issue impacts only small number of customersThis issue impacts only small number of customersanalyzerIndicates an issue which is related to analyzer experienceIndicates an issue which is related to analyzer experiencearea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-openapiseverity-blockingThis label is used by an internal toolThis label is used by an internal tool