Generated OpenAPI docs overrides [Consumes] attribute through [FromForm]
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
When creating a form that is expecting an image to be uploaded via `[Consumes("multipart/form-data")],` the generated OpenAPI document will define the expected value as `application/x-www-form-urlencoded`.
Controller:
```csharp
[HttpPost]
[Consumes("multipart/form-data")]
public async Task> ImageToData(
[FromForm] IFormFile image)
{
...
```
Generated OpenAPI document:
```
...
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
...
```
### Expected Behavior
I expect the generated OpenAPI docs to correctly annotate the endpoint as a
"multipart/form-data"
endpoint, as opposed to an
"application/x-www-form-urlencoded"
endpoint.
### Steps To Reproduce
1. Create an AspNetCore API with generated OpenAPI documentation.
2. On a controller, add an endpoint with the [Consumes] attribute and a [FromForm] parameter.
3. Browse the generated OpenAPI document (e.g http://localhost:5211/openapi/v1.json)
4. Note the discrepancy between the Consumes attribute and the generated documentation.
### Exceptions (if any)
_No response_
### .NET Version
9.0.200
### Anything else?
ASP.NET Core: 9.0.2
`dotnet --info`
.NET SDK:
Version: 9.0.200
Commit: 90e8b202f2
Workload version: 9.0.200-manifests.b4a8049f
MSBuild version: 17.13.8+cbc39bea8
Runtime Environment:
OS Name: ubuntu
OS Version: 24.04
OS Platform: Linux
RID: linux-x64
Base Path: /home/a46039/.asdf/installs/dotnet/9.0.200/sdk/9.0.200/
.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.2
Architecture: x64
Commit: 80aa709f5d
.NET SDKs installed:
9.0.200 [/home/a46039/.asdf/installs/dotnet/9.0.200/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.2 [/home/a46039/.asdf/installs/dotnet/9.0.200/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.2 [/home/a46039/.asdf/installs/dotnet/9.0.200/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Contributor guide
Assessment
This issue has not been assessed yet.