Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/OpenApi/src/Services/OpenApiDocumentService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.ComponentModel;
Expand Down Expand Up @@ -665,7 +666,11 @@ private async Task<OpenApiRequestBody> GetFormRequestBody(
}
else
{
if (isComplexType)
// Identify if this is a collection (excluding string)
var isCollection = typeof(IEnumerable).IsAssignableFrom(description.Type) && description.Type != typeof(string);

// Only allow non-collection complex types (POCOs) to take over the root body
if (isComplexType && !isCollection)
{
complexTypeSchema = parameterSchema;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,34 @@ await VerifyOpenApiDocument(action, document =>
});
}

[Fact]
public async Task GetOpenApiRequestBody_HandlesFromFormWithIEnumerable()
{
// Arrange
var builder = CreateBuilder();

// Act
builder.MapPost("/test", ([FromForm] IEnumerable<int> values) => { });

// Assert
await VerifyOpenApiDocument(builder, document =>
{
var paths = Assert.Single(document.Paths.Values);
var operation = paths.Operations[HttpMethod.Post];
Assert.NotNull(operation.RequestBody);
var content = operation.RequestBody.Content;
Assert.Contains("multipart/form-data", content.Keys);
var formSchema = content["multipart/form-data"].Schema;

Assert.Equal(JsonSchemaType.Object, formSchema.Type);
Assert.NotNull(formSchema.Properties);
Assert.Contains("values", formSchema.Properties);
var valuesProperty = formSchema.Properties["values"];
Assert.Equal(JsonSchemaType.Array, valuesProperty.Type);
Assert.Equal(JsonSchemaType.Integer, valuesProperty.Items.Type);
});
}

[Route("/form-mixed-types")]
private void ActionWithMixedFormTypes([FromForm] Todo todo, IFormFile formFile, [FromForm] Guid guid) { }

Expand Down
Loading