dotnet / dotnet/aspnetcore

Incorrect OpenAPI definition when using FromForm with IEnumerable parameters

Open
#62,328 1 comment 5 reactions 0 assignees View on GitHub
area-minimal feature-openapi help wanted
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

I'm using .NET 9 OpenAPI support. With the following endpoint:

```csharp
app.MapPost("/api/documents", ([FromForm] int[] values) =>
{
return TypedResults.Ok();
});
```

I get the following definition:

```json
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
}
}
}
},
"application/x-www-form-urlencoded": {
"schema": {
"type": "object",
"properties": {
"values": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
}
}
}
}
},
"required": true
}
```

If, instead, I change the type to `IEnumerable`:

```csharp
app.MapPost("/api/documents", ([FromForm] IEnumerable values) =>
{
return TypedResults.Ok();
});
```

The OpenAPI definition becomes:

```json
"requestBody": {
"content": {
"multipart/form-data": {
"schema": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
}
},
"application/x-www-form-urlencoded": {
"schema": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
}
}
},
"required": true
},
```

### .NET Version

9.0.301

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.