Skip to content

Unable to set request body format to binary in minimal api #45265

Closed
@FranklinWhale

Description

@FranklinWhale

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

requestBody in swagger.json of the code below

app.MapPut("/file", Created (HttpRequest request) => {
    return TypedResults.Created("https://example.org");
})
.Accepts<byte[]>("application/zip")
.Produces(StatusCodes.Status415UnsupportedMediaType)

is

"requestBody": {
  "content": {
    "application/zip": {
      "schema": {
        "type": "string",
        "format": "byte"
      }
    }
  }
}

while .Accepts<Stream>("application/zip")

leads to

"requestBody": {
  "content": {
    "application/zip": {
      "schema": {
        "$ref": "#/components/schemas/Stream"
      }
    }
  }
}

When I want to override requestBody by adding

.WithOpenApi(o => {
    o.RequestBody = new OpenApiRequestBody {
        Content = new Dictionary<string, OpenApiMediaType>() {
            {
                "application/zip",
                new OpenApiMediaType {
                    Schema = new OpenApiSchema {
                        Type = "string",
                        Format = "binary"
                    }
                }
            }
        }
    };
    return o;
});

I find that it has no effect.

How to set format to binary?

.NET Version

7.0.100

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.Status: No Recent Activityold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions