Nswag: Generating ASP.NET Core Controllers, FileParameter vs. IFormFile

Created on 3 Apr 2019  路  5Comments  路  Source: RicoSuter/NSwag

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?

help wanted NSwag.CodeGeneration.CSharp (Controllers)

Most helpful comment

Good morning everyone.
I encountered this issue today and came across this outstanding PR.

I figure everyone is extremely busy, but wanted to check in and see if the PR that Samuel created might be reviewed or merged anytime soon.

Thanks!
-Brian

All 5 comments

Probably not supported correctly

I can submit a pull request for this if that's ok. I've just run into the same issue here, and I've got the fix sitting in my fork.

Please create a pr and ill review it

Good morning everyone.
I encountered this issue today and came across this outstanding PR.

I figure everyone is extremely busy, but wanted to check in and see if the PR that Samuel created might be reviewed or merged anytime soon.

Thanks!
-Brian

We maybe are having the same issue. Any idea when this will be merged and released? Thanks in advance.

Was this page helpful?
0 / 5 - 0 ratings