C
C#7d 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");
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; }
}
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.
No description
2 Replies
glhays
glhays7d ago
Where are you talking about having proper input fields? Postman?
Nexen
NexenOP7d ago
in swagger, i saw that it could be a bug, that it shows this way, but maybe im doing something wrong. But more important is the client generation. I have multiple [FromForm] endpoints, but with just one class and in dart its generated as MultipartFile (correct), but this particular usecase generates file property as Uint8List, but it should be MultipartFile. Edit: For the sake of getting this working, i removed the files list, so just the one file needs to be fixed.

Did you find this page helpful?