Skip to content

Incorrect OpenAPI definition for multipart/form-data endpoint #63991

@craemy

Description

@craemy

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

An endpoint which consumes application/form-data is not is mapped to application/x-www-form-urlencoded in the OpenAPI spec:

[HttpPost]
[Consumes("multipart/form-data")]
public IEnumerable<WeatherForecast> Post([FromForm] string name, [FromForm] IFormFile file)
{
    ...
}

becomes

  "paths": {
    "/WeatherForecast": {
      "post": {
        "tags": [
          "WeatherForecast"
        ],
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "allOf": [
                  {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      }
                    }
                  },...

Expected Behavior

  "paths": {
    "/WeatherForecast": {
      "post": {
        "tags": [
          "WeatherForecast"
        ],
        "requestBody": {
          "content": {
            "application/form-data": {
              "schema": {
                "type": "object",
                "allOf": [
                  {
                    "type": "object",
                    "properties": {
                      "name": {
                        "type": "string"
                      }
                    }
                  },...

Steps To Reproduce

  • Create a new Web-API project
  • Add an endpoint in the WeatherForecastController according to the problem description
  • Run the app in debug config
  • open localhost:<port>/openapi/v1.json

Exceptions (if any)

No response

.NET Version

9.0

Anything else?

Microsoft.AspNetCore.OpenApi Version 9.0.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-area-labelUsed by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions