RicoSuter/NSwag

Generating ASP.NET Core Controllers, FileParameter vs. IFormFile

Open

#2,075 opened on Apr 3, 2019

View on GitHub
 (11 comments) (3 reactions) (0 assignees)C# (1,189 forks)batch import
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:

  1. 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:
  2. 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?

Contributor guide