Skip to content

Commit 3244983

Browse files
committed
Fix Swashbuckle 6.9 OpenAPI generation for IFormFile upload endpoint
Swashbuckle 6.9+ requires IFormFile to be wrapped in a class when used with [FromForm] rather than declared as a bare action parameter. Introduce DatabaseImportRequest to satisfy this requirement and unblock the OpenAPI guardrail CI check.
1 parent fa6fb06 commit 3244983

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Taskdeck.Api.Contracts;
2+
3+
/// <summary>
4+
/// Wraps the IFormFile upload for database import. Using a class wrapper is required
5+
/// by Swashbuckle 6.9+ to correctly generate the OpenAPI schema for file uploads.
6+
/// </summary>
7+
public sealed class DatabaseImportRequest
8+
{
9+
public IFormFile? File { get; set; }
10+
}

backend/src/Taskdeck.Api/Controllers/ExportController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text.Json;
22
using Microsoft.AspNetCore.Authorization;
33
using Microsoft.AspNetCore.Mvc;
4+
using Taskdeck.Api.Contracts;
45
using Taskdeck.Api.Extensions;
56
using Taskdeck.Application.DTOs;
67
using Taskdeck.Application.Interfaces;
@@ -83,11 +84,14 @@ public async Task<IActionResult> ExportDatabase()
8384
}
8485

8586
[HttpPost("import/database")]
86-
public async Task<IActionResult> ImportDatabase([FromForm] IFormFile? file)
87+
[Consumes("multipart/form-data")]
88+
public async Task<IActionResult> ImportDatabase([FromForm] DatabaseImportRequest request)
8789
{
8890
if (!TryGetCurrentUserId(out var userId, out var errorResult))
8991
return errorResult!;
9092

93+
var file = request.File;
94+
9195
if (file is null)
9296
{
9397
return Result

0 commit comments

Comments
 (0)