-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG][aspnetcore] FileParameters should be refactor to multimap and support content-type #11132
Comments
I tried out the fix, in addition to the above Multimap<string, Stream> RequestOptions class fix I applied the following fix to ApiClient, which seemed to do the trick:
|
Please submit a PR with the suggested fix and we'll review accordingly. |
@saarivirtajCGI In my opinion thats it, is the same code I had on on my side to make the workaround. One not so simple is about the contentType. I've created an util method to get the content-type of the file based on the name but its not safe at all. My code is the following: if (options.FileParameters != null)
{
foreach (var fileParam in options.FileParameters)
{
foreach (var file in fileParam.Value)
{
var bytes = ClientUtils.ReadAsBytes(file);
var fileStream = file as FileStream;
if (fileStream != null)
request.Files.Add(FileParameter.Create(fileParam.Key, bytes, System.IO.Path.GetFileName(fileStream.Name), this.GetContentTypeForFile(fileStream.Name)));
else
request.Files.Add(FileParameter.Create(fileParam.Key, bytes, "no_file_name_provided"));
}
}
} |
…Tools#11132) Make FileParamerts a Multimap to enable sending more than one file with the same key.
@wing328 PR submited |
Bug Report Checklist
Description
Build fails for a request with multipart-form-data when there is multiple files for the same field.
The client receives a List but this can't be handled by RequestOptions because it only accepts a single file for the same key.
The API consumed requires the content-type for the file sent (e.g. application/pdf, image/png).
There is no way to achieve this with the actual generator.
openapi-generator version
openapi-generator-cli-5.3.0.jar
OpenAPI declaration file content or url
Generation Details
java -jar openapi-generator-cli-5.3.0.jar generate -i swagger.json -g csharp-netcore -o testNew
Steps to reproduce
generate the code
build the code
it fails with
Error CS1503 Argument 2: cannot convert from 'System.Collections.Generic.List<System.IO.Stream>' to 'System.IO.Stream'
Suggest a fix
Change on RequestOptions class the field FileParameters from Dictionary<string, Stream> to Multimap<string, Stream> would fix the issue as follows:
This fix also requires a change at ApiClient to iterate the multiples files under the same key.

Code block:
FileParameters should support the defintion of a ContentType or the code could infer from the file extension (but it can be tricky not for the common types like pdf but for some ambiguous types).
It's already supported by aspnetcore httpClient and RestSharp when creating file as follows:
The text was updated successfully, but these errors were encountered: