-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Labels
help-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community
Description
I'm using .NET 7.0.4 and Swashbuckle.AspNetCore 6.5.0.
Consider the following endpoints:
app.MapPost("/api/upload", (IFormFile file) =>
{
return TypedResults.Ok(file.FileName);
});
app.MapPost("/api/upload_with_openapi", (IFormFile file) =>
{
return TypedResults.Ok(file.FileName);
})
.WithOpenApi();
The first one generates the following schema:
schema": {
"required": [
"file"
],
"type": "object",
"properties": {
"file": {
"type": "string",
"format": "binary"
}
}
},
While the second, using WithOpenApi, produces this:
"schema": {
"type": "string",
"format": "binary"
},
This causes an exception when calling the /api/upload_with_openapi endpoint:
Microsoft.AspNetCore.Http.BadHttpRequestException: Required parameter "IFormFile file" was not provided from form file.
at lambda_method3(Closure, Object, HttpContext, Object)
at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass92_2.<<HandleRequestBodyAndCompileRequestDelegateForForm>b__2>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
You can find a minimal repro here: https://github.com/marcominerva/FileUploadIssue
Original issue posted at dotnet/aspnetcore#47526
cleftheris, lhyzf, horse315, paolofulgoni, josh-hemphill and 2 morejosh-hemphill
Metadata
Metadata
Assignees
Labels
help-wantedA change up for grabs for contributions from the communityA change up for grabs for contributions from the community