Azure / Azure/azure-functions-openapi-extension
Arrays of strings and multipart/form-data
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
I'm writing a function with **multipart/form-data**, with this signature:
```csharp
[Function("UploadFile")]
[OpenApiOperation("UploadFile")]
[OpenApiRequestBody(bodyType: typeof(UploadFileRequest), contentType: "multipart/form-data")]
[OpenApiResponseWithBody(bodyType: typeof(UploadFileResponse), contentType: "application/json")]
public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest httpRequest)
```
receiving multipart/form data that contains a file and **one array of strings**.
```csharp
public class UploadFileRequest
{
public byte[] File { get; set; } = [];
public List Metadata { get; set; } = [];
}
```
swagger.json describes `metadata` as
```
{
"name": "metadata",
"description": "",
"type": "array",
"items": {
"type": "string"
},
"in": "formData"
}
```
Swagger UI allows to enter strings, e.g.

## Problem
On the service side, `metadata` is received **as a single value**.
For instance, swagger UI suggested `curl` is:
```
curl -X POST ... -H ... -F "metadata=a=1,b=2" -F "file=@test.png;type=image/png"
```
but the request should be:
```
curl -X POST ... -H ... -F "metadata=a=1" -F "metadata=b=2" -F "file=@test.png;type=image/png"
```
## Questions
* Is there a way to say that a list of strings is sent as multiple and separate entries?
* if not - Is there a way to say strings must be encoded and separated with a special char (the special char must be encoded if part of a value)?
Contributor guide
Research direction
Start with the Run entry point and UploadFileRequest model shown in the issue, then reproduce the generated swagger.json and the two curl requests for multipart/form-data. The work is done when the OpenAPI description and Swagger UI produce separate metadata entries for the List, or clearly support an encoded delimiter format.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100