Open cremor opened 5 years ago
Thanks for contacting us, @cremor. @glennc what needs to be done here?
Since #8855 is now both closed and locked, please don't forget it when working on this issue. As per comment from @pranavkm:
The most likely solution we would go with would be to create a separate convention and have users explicitly opt in. If you'd like we could use #9375 to consider fixing both of these using this approach.
We've moved this issue to the Backlog milestone. This means that it is not going to happen for the coming release. We will reassess the backlog following the current release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.
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: aa79b139a8 Laufzeitumgebung: 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