C#C
C#10mo ago
Nexen

FromForm list of classes issue

Hello, i have trouble with swagger and also the generated openapi spec.

This is the endpoint i have:
group.MapPost("endpoint", async Task<List<Guid>> (
                [FromForm] List<MRequest> operations,
                HttpContext context,
                IMessageBus bus,
                CancellationToken token) =>
            {
                return await bus.InvokeAsync<List<Guid>>(operations, token);
            })
            .WithMetadata(new ConsumesAttribute("multipart/form-data"))
            .WithOpenApi(x => new OpenApiOperation(x)
            {
                Summary = "Endpoint summary",
                Description =
                    "Endpoint desc"
            })
            .WithName("Endpoint")
            .WithGroupName(ApiDefinition.API_V1)
            .Produces<List<Guid>>(contentType: "application/json");


This is the model:
public record MRequest
{

    [Required] public Identifier Identifier { get; set; }

    [Required] public Type Type { get; set; }

    [Required] public DateTime Timestamp { get; set; }

    public IFormFile? File { get; set; }

    public List<BulkFile>? Files { get; set; }
}

public record BulkFile
{
    [Required] public IFormFile File { get; set; } = null!;
    [Required] public int Position { get; set; }
}


in swagger i see list of jsons.

What can i do to actually have proper input fields and test the file uploads?

For context: i cant use postman. The openapi spec is used to generate clients.
image.png
Was this page helpful?