Bug Report Checklist
Description
When generating a C# client with the generichost library for an endpoint that accepts multiple file uploads (array of binary strings), the generated code is invalid. The generator creates code that attempts to add the entire collection as a single StreamContent instead of iterating through each file and adding them individually to the multipart content.
openapi-generator version
7.13.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: File Upload API
version: 1.0.0
description: A minimal API with file upload functionality
servers:
- url: http://localhost:8080
description: Development server
paths:
/upload:
post:
summary: Upload multiple files
operationId: uploadFiles
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
properties:
files:
type: array
items:
type: string
format: binary
required:
- files
responses:
'200':
description: Files uploaded successfully
content:
application/json:
schema:
type: object
properties:
message:
type: string
fileCount:
type: integer
Generation Details
Using Docker:
docker run --rm -v "${PWD}:/app" openapitools/openapi-generator-cli:v7.13.0 generate \
-i /app/openapi.yaml \
-g csharp \
-o /app/generated \
--additional-properties=targetFramework=net9.0,packageName=FileUploadClient,library=generichost
Or with config file:
{
"generatorName": "csharp",
"outputDir": "./generated",
"inputSpec": "./openapi.yaml",
"additionalProperties": {
"targetFramework": "net9.0",
"packageName": "FileUploadClient",
"library": "generichost",
"nullableReferenceTypes": true,
"useCollection": true,
"useDateTimeOffset": true,
"netCoreProjectFile": true
}
}
Steps to reproduce
- Create the OpenAPI spec file shown above
- Run the generator with the generichost library option
- Examine the generated DefaultApi.cs file around line 255
Related issues/PRs
Similar issues with file upload handling:
Suggest a fix
The issue is in the generated UploadFilesAsync method. The current code generates:
multipartContentLocalVar.Add(new StreamContent(files));
But it should generate:
foreach (var file in files)
{
var streamContent = new StreamContent(file);
streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "\"files\"",
FileName = "\"file\""
};
multipartContentLocalVar.Add(streamContent);
}
The template that needs modification is likely in modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ - specifically the api template that handles multipart form data with array parameters.
Report generated with the help of Claude
Bug Report Checklist
master to confirm the issue still
exists?
Description
When generating a C# client with the
generichostlibrary for an endpoint that accepts multiple file uploads (array of binary strings), the generated code is invalid. The generator creates code that attempts to add the entire collection as a singleStreamContentinstead of iterating through each file and adding them individually to the multipart content.openapi-generator version
7.13.0
OpenAPI declaration file content or url
Generation Details
Using Docker:
docker run --rm -v "${PWD}:/app" openapitools/openapi-generator-cli:v7.13.0 generate \ -i /app/openapi.yaml \ -g csharp \ -o /app/generated \ --additional-properties=targetFramework=net9.0,packageName=FileUploadClient,library=generichostOr with config file:
{ "generatorName": "csharp", "outputDir": "./generated", "inputSpec": "./openapi.yaml", "additionalProperties": { "targetFramework": "net9.0", "packageName": "FileUploadClient", "library": "generichost", "nullableReferenceTypes": true, "useCollection": true, "useDateTimeOffset": true, "netCoreProjectFile": true } }Steps to reproduce
Related issues/PRs
Similar issues with file upload handling:
Suggest a fix
The issue is in the generated UploadFilesAsync method. The current code generates:
But it should generate:
The template that needs modification is likely in
modules/openapi-generator/src/main/resources/csharp/libraries/generichost/- specifically the api template that handles multipart form data with array parameters.Report generated with the help of Claude