OpenAPITools / OpenAPITools/openapi-generator

[BUG][C#][unityWebRequest] Multipart/form-data request does not attach file and sets Content-Type without boundary

Open
#21,739 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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 (unityWebRequest library), the generated code should call WWWForm.AddBinaryData(...) for type: string, format: binary properties.
  • The Content-Type header should not be set manually — WWWForm should 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-Type header is set manually without a boundary → server throws Multipart: Boundary not found.

Expected behavior

  • File should be added using:
    form.AddBinaryData(fieldName, fileBytes, fileName, contentType);
    
    for Unity.
  • Content-Type should be omitted so that WWWForm generates it with a correct boundary.

Additional context

  • Works correctly with --library httpclient (file is attached via FileParameters.Add).
  • The issue is specific to --library unityWebRequest.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.