In my code I use endpoint:
[Authorize]
[HttpPost("UploadAlbum")]
public async Task<ResponseHolderModel<UploadAlbumResponseModel>> UploadAlbum([FromForm]List<FileHolderModel> files)
This is FileHolderModel
class:
public class FileHolderModel
{
public IFormFile? File { get; set; }
public float Price { get; set; }
}
My problem Is that I want to be abble to use this endpoint by swagger UI and post files with prices easily using UI. I tried to force swagger to recognize files to append filepicker by:
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
var fileUploadMime = "multipart/form-data";
if (operation.RequestBody == null || !operation.RequestBody.Content.Any(x => x.Key.Equals(fileUploadMime, StringComparison.InvariantCultureIgnoreCase)))
return;
var fileParams = context.MethodInfo.GetParameters().Where(p => p.ParameterType == typeof(List<FileHolderModel>));
operation.RequestBody.Content[fileUploadMime].Schema.Properties =
fileParams.ToDictionary(k => k.Name, v => new OpenApiSchema()
{
Type = "string",
Format = "binary"
});
}
Unfortunately I am lost in OpenApiSchema. Could you help me how to write this piece of code to fit List<FoleHolderModel
where File
should be selectable by filepicker? If you know some other and better way how to do it write an answer please.