OpenAPITools / OpenAPITools/openapi-generator
[BUG][C#][unityWebRequest] Multipart/form-data request does not attach file and sets Content-Type without boundary
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When generating a C# client with --library unityWebRequest for an endpoint that accepts multipart/form-data (string + binary file), the generated code does not attach the file to the request and manually sets Content-Type: multipart/form-data without a boundary. This causes the server (Fastify/busboy) to return:
Multipart: Boundary not found
Expected behavior
- For Unity (
unityWebRequestlibrary), the generated code should callWWWForm.AddBinaryData(...)fortype: string, format: binaryproperties. - The
Content-Typeheader should not be set manually —WWWFormshould generate it automatically with the correct boundary.
OpenAPI Spec snippet to reproduce
openapi: 3.0.3
info:
title: Test API
version: 1.0.0
paths:
/upload:
post:
operationId: uploadFile
requestBody:
required: true
content:
multipart/form-data:
schema:
type: object
required:
- raceId
- file
properties:
raceId:
type: string
file:
type: string
format: binary
responses:
'200':
description: OK
Command used for generation
openapi-generator-cli generate -i swagger.json -g csharp --library unityWebRequest -o sdk-unity/ --skip-validate-spec --global-property modelTests=false,apiTests=false,modelDocs=false,apiDocs=false,validatable=false --additional-properties packageName=BX.Rest
openapi-generator-cli version
openapi-generator-cli version
# e.g. 7.14.0
Actual generated code (excerpt)
string[] _contentTypes = new string[] { "multipart/form-data" };
var localVarContentType = ClientUtils.SelectHeaderContentType(_contentTypes);
if (localVarContentType != null)
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
localVarRequestOptions.FormParameters.Add("raceId", ClientUtils.ParameterToString(raceId));
// No call to FileParameters.Add(...) or WWWForm.AddBinaryData(...)
Actual behavior
- File is never added to the multipart request.
Content-Typeheader is set manually without a boundary → server throwsMultipart: Boundary not found.
Expected behavior
- File should be added using:
for Unity.form.AddBinaryData(fieldName, fileBytes, fileName, contentType); Content-Typeshould be omitted so thatWWWFormgenerates it with a correctboundary.
Additional context
- Works correctly with
--library httpclient(file is attached viaFileParameters.Add). - The issue is specific to
--library unityWebRequest.
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
Reproduce the issue with the supplied OpenAPI spec and the unityWebRequest generation command, then trace the generated multipart request handling and its form/header setup. Done means binary properties are included in the Unity form and the manually supplied Content-Type is omitted so the boundary is generated automatically.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100