Azure / Azure/azure-functions-openapi-extension

OpenApiRequestBody attribute with a "multipart/form-data" contentType throws exception when requesting swagger.json

Open
#437 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
388
Forks
202
PR merge metrics
No merged PRs in 30d

Description

There is an issue when trying to add the OpenApiRequestBody attribute with a "multipart/form-data" contentType. Trying to request the swagger.json returns an exception: "An item with the same key has already been added. Key: multiPartFormDataModel." Here is a sample of my code:

```
[Function(nameof(Upload))]
[OpenApiOperation(
operationId: "Upload",
Visibility = OpenApiVisibilityType.Important)]
[OpenApiRequestBody(
contentType: "multipart/form-data",
bodyType: typeof(MultiPartFormDataModel),
Required = true)]
public async Task Upload([HttpTrigger(AuthorizationLevel.Function, "post", Route = "form/multipart")] HttpRequestData req, ILogger log)
{
}

public class MultiPartFormDataModel
{
public byte[] File { get; set; }
}
```

I pulled the repo to try to reproduce and this issue seems to be fixed in the main branch. Only present in v1.3.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.