swagger-api / swagger-api/swagger-codegen
[CSHARP-NETCORE] ASPNET Core Endpoint taking List<IFormFile> argument causes CSHARP-NETCORE generated client to contain build errors
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Att: @jimschubert - Thanks for the preliminary discussion on slack!
Description
I have an ASPNET Core WebApi application which exposes an endpoint that takes List<IFormFile> files as argument:
[HttpPost]
public IActionResult PostFiles(List<IFormFile> files)
{
foreach(var file in files)
{
// do stuff
}
return Ok();
}
Swagger-codegen version
Latest
Swagger declaration file content or url
The generated swagger json looks to be correct:
{
"openapi": "3.0.1",
"info": {
"title": "My API",
"version": "v1"
},
"paths": {
"/WeatherForecast": {
"post": {
"tags": [
"WeatherForecast"
],
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"files": {
"type": "array",
"items": {
"type": "string",
"format": "binary"
},
"nullable": true
}
}
},
"encoding": {
"files": {
"style": "form"
}
}
}
}
},
"responses": {
"200": {
"description": "Success"
}
}
}
}
},
"components": { }
}
Command line used for generation
docker run --rm -v c:\TEMP\FormFileBugRepro:/TEMP openapitools/openapi-generator-cli generate -i /TEMP/swagger.json -g csharp-netcore -o /TEMP/Swag
Steps to reproduce
- Create ASPNET Core WebApi
- Add Swagger dependencies and setup properly in Startup
- Create endpoint as specified in description
- Generate
csharp-netcoreclient using the command specified above - Open generated solution and see build errors:

- Even if you fix the build error by doing so:

- Its still going to try to add each file to the FileParameter dictionary under the same key, which throws an error. It seems as FileParameter being a dictionary type prevents implementing correct behavior as it's perfectly legal to attach multiple form files with the same name in a HTTP Request.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided Docker generation command and the csharp-netcore generator. Inspect the generated client’s multipart/form-data handling for the files array and FileParameter dictionary. Done means the generated solution builds and multiple files can be sent under the same form key without an error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100