microsoft / microsoft/kiota

Kiota falls back to MultipartBody for valid flat multipart file upload schema

Open
#8,080 0 comments 0 reactions 0 assignees View on GitHub
Csharp status:waiting-for-triage type:bug
Dominant language
C#
Stars
3.8k
Forks
333
Avg merge
16h 29m
Merged PRs (30d)
116

Description

### What are you generating using Kiota, clients or plugins?

API Client/SDK

### In what context or format are you using Kiota?

Nuget tool

### Client library/SDK language

Csharp

### Describe the bug

Kiota generates a typed multipart request body for an**allOf** schema, but falls back to generic MultipartBody for the equivalent valid flat schema.

The scenario is a multipart request with one file field and one multiple-file field.

### Expected behavior

Kiota should generate a typed request body for the valid multipart schema, for example:

```
public async Task PostAsync(
UploadFilesRequestBody body,
Action>? requestConfiguration = default,
CancellationToken cancellationToken = default)
```

With generated model like:

```
public partial class UploadFilesRequestBody
{
public byte[]? Resume { get; set; }

public List? Files { get; set; }
}
```

The generated request method should accept this typed model instead of falling back to the generic MultipartBody type.

### How to reproduce

Generate a C# client from the OpenAPI document below.

### Open API description file

```
{
"openapi": "3.0.4",
"info": {
"title": "Multipart API",
"version": "1.0.0"
},
"paths": {
"/forms/form-file-multiple": {
"post": {
"operationId": "uploadFiles",
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"required": [
"resume",
"files"
],
"properties": {
"resume": {
"type": "string",
"format": "binary"
},
"files": {
"type": "array",
"items": {
"type": "string",
"format": "binary"
}
}
}
}
}
}
},
"responses": {
"204": {
"description": "No Content"
}
}
}
}
}
}
```

### Kiota Version

1.34.1

### Latest Kiota version known to work for scenario above?(Not required)

_No response_

### Known Workarounds

_No response_

### Configuration

_No response_

### Debug output

### Other information

This is relevant to [issue](https://github.com/dotnet/aspnetcore/issues/68147) we would like to fix in aspnetcore.

Contributor guide

Open the contributing guide

Research direction

Start by running the NuGet tool with the OpenAPI document in the issue and inspect the generated C# request body and uploadFiles method. Compare the flat schema with the equivalent allOf case to find where multipart schema detection diverges. Done means the flat schema generates UploadFilesRequestBody with resume and files instead of generic MultipartBody.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
67/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.