ApiExplorer not aware of HttpNoContentOutputFormatter
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Describe the bug
When a controller method returns `null`, the `HttpNoContentOutputFormatter` transforms the status code into a `204 - No Content` instead of a `200 - Ok`.
However, API explorer does not document this possibility of 204.
### To Reproduce
Create a MVC project with a controller.
Create a method that can return a nullable reference type, for example:
```cs
public string? Index()
```
If that method returns `null`, the status code will be 204, which I assume is expected.
Inspect ApiExplorer's metadata : The 204 status code is not documented.
[Minimal diff](https://github.com/jeremyVignelles/repro-aspnetcore/commit/3529e09d263e8f46e9c2c57cd57046fac2a24585)
[Full code](https://github.com/jeremyVignelles/repro-aspnetcore/tree/repro/204-not-documented)
Expected result: 200 and 204 should show up
Actual result : Only 200 is displayed.
### Further technical details
- ASP.NET Core version tested on 2.2 through 5.0
- Include the output of `dotnet --info`
```
$ dotnet --info
SDK .NET (reflétant tous les fichiers global.json) :
Version: 5.0.100
Commit: 5044b93829
Environnement d'exécution :
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.100\
Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7
.NET SDKs installed:
2.1.802 [C:\Program Files\dotnet\sdk]
3.1.302 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
```
- The IDE (VS / VS Code/ VS4Mac) you're running on, and it's version : VS community 2019 version 16.8.2
Contributor guide
Assessment
This issue has not been assessed yet.