RicoSuter/NSwag
View on GitHubGenerating ASP.NET Core Controllers, FileParameter vs. IFormFile
Open
#2,075 opened on Apr 3, 2019
help wantedproject: NSwag.CodeGeneration.CSharp (Controllers)
Repository metrics
- Stars
- (6,291 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
In my OpenAPI 2.0 specification, I have the following portion of code for having a file upload available:
consumes:
- multipart/form-data
parameters:
- in: formData
name: someFile
type: file
required: true
description: Some file
The generated ASP.NET Core code for the controller contains the definition of a class "FileParameter" that is also passed in to the controller method as an argument. There two problems:
- The given definition of the FileParameter class does not contain a parameterless constructor, which causes the model binding of ASP.NET to fail. If I add such a constructor:
- The model binding does not seem to function properly in this case, the method receives a FileParameter object. However, its fields are initialized with null.
Changing the FileParameter class manually to IFormFile fixes these issues. Is there some other way to make this work? Or is it unsupported currently?