dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.25k stars 9.96k forks source link

Encoding field of multipart/form-data body is incorrect #57083

Closed mikekistler closed 1 month ago

mikekistler commented 2 months ago

Is there an existing issue for this?

Describe the bug

The operation in the generated OpenAPI for an endpoint that accepts a "binary" FromForm parameter (e.g. byte[]) has a requestBody that includes an encoding field with incorrect contents. The encoding field is generated as:

      "encoding": {
        "multipart/form-data": {
          "style": "form",
          "explode": true
        }
      }

But the OpenAPI specifcation says that encoding is:

A map between a property name and its encoding information. The key, being the property name, MUST exist in the schema as a property.

The encoding object shown above is incorrect because "multipart/form-data" is not a property name in the associated schema.

Expected Behavior

I'm not really sure what information this encoding is intended to convey. It might be possible to simply delete it. But if it is important for some reason then the key must be a property name in the schema.

Steps To Reproduce

This branch https://github.com/mikekistler/aspnet-openapi-examples/tree/bug-57082 contains a recreate for this problem in the FormBodiesApi.cs file.

Exceptions (if any)

No response

.NET Version

9.0.100-rc.1.24380.1

Anything else?

No response

captainsafia commented 1 month ago

Via offline discussion, we concluded that the default encoding values that OpenAPI assumes correctly match the behavior of the implementation so we can remove these settings from being explicitly set in the document.