dotnet/aspnetcore

Incorrect OpenAPI definition when using FromForm with IEnumerable parameters

Open

#62 328 ouverte le 12 juin 2025

Voir sur GitHub
 (1 commentaire) (5 réactions) (0 assignés)C# (10 653 forks)batch import
area-minimalfeature-openapihelp wanted

Métriques du dépôt

Stars
 (37 933 stars)
Métriques de merge PR
 (Merge moyen 16j 9h) (258 PRs mergées en 30 j)

Description

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

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

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

I get the following definition:

"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:

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

The OpenAPI definition becomes:

"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

Guide contributeur