Skip to content

Generated OpenAPI docs overrides [Consumes] attribute through [FromForm] #60867

Open
@Zylvian

Description

@Zylvian

Is there an existing issue for this?

  • 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:

[HttpPost]
[Consumes("multipart/form-data")]
public async Task<ActionResult<SomeDto>> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions