DefaultApiConventions are missing Status400BadRequest responses for GET requests #9375
Labels
affected-very-few
This issue impacts very few customers
area-mvc
Includes: MVC, Actions and Controllers, Localization, CORS, most templates
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
feature-openapi
severity-nice-to-have
This label is used by an internal tool
Milestone
Describe the bug
The DefaultApiConventions should define a
Status400BadRequest
response forGet
andFind
methods.To Reproduce
Steps to reproduce the behavior:
[ApiConventionType(typeof(DefaultApiConventions))]
attribute to the controller or assembly.ApiExplorer
interfaces (or add Swashbuckle.AspNetCore to quickly see the same data in Swagger-UI).api/values/{id}
methods. Note thatStatus400BadRequest
is not defined as a possible response.api/values/{id}
with a string asid
. Note the response ("400 BadRequest").Expected behavior
Becaues GET can return "400 BadRequest", there should be a
Status400BadRequest
response defined for GET methods, just like there is for all POST, PUT and DELETE.Additional context
I know that these conventions were created after the default scaffolding template "Web API Controller with EF Core context", which doesn't return
BadRequest
inGet
. But neither doesDelete
, which accepts the same parameter asGet
. And thanks to automatic HTTP 400 responses bothGet
andDelete
will return "400 BadRequest" if model binding fails (e.g. if you call the action with a string parameter but your id is an integer).Output of
dotnet --info
:Click to expand
.NET Core SDK (gemäß "global.json"): Version: 2.2.106 Commit: aa79b139a8Laufzeitumgebung:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.106\
Host (useful for support):
Version: 2.2.4
Commit: f95848e524
.NET Core SDKs installed:
2.1.505 [C:\Program Files\dotnet\sdk]
2.2.106 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
The text was updated successfully, but these errors were encountered: