An operation with a required IFormFile is not treated as non-nullable parameter
Author: frabe1579Created Oct 10, 2022Updated Jul 28, 2026
Labelstype: bug
An operation with a required IFormFile is not treated as non-nullable parameter
Requirements:
Asp.Net Core 6.0.9 NSwagStudio v13.16.1.0 Important: Nullable Refeence Types enabled on client.
How to reproduce:
On server side, (asp.net core 6), add a controller action like this:
[HttpPost]
public ActionResult CreateFile([BindRequired] IFormFile file) {
return Ok();
}When generating client code via NSwagStudio, a method like this is generated:
Task Post(FileParameter file = null);I have enabled Nullable Reference Types, so this warning is generated: warning CS8625: Cannot convert null literal to non-nullable reference type.
Expected result
With Nullable Reference Types enabled, no default value for file parameter is expected, because it is required. This is not a problem with other normal actions, where Required/BindRequired parameters or models are treated as non-nullable non-default correctly.
Source: RicoSuter/NSwag