Skip to content

WithOpenAPI Generates Empty requestBody.content #54189

Closed
@LouisTrinczek

Description

@LouisTrinczek

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am facing the same issues with Microsoft.AspNetCore.OpenAPI 8.0.2 as mentioned in this issue #47644. Apparently this has been fixed, but we are encountering the same issues on the most recent version as well.
The only difference is, that we are injecting a Service using [FromServices].

  "/route": {
      "get": {
        "tags": [
          "tag"
        ],
        "summary": "get xy",
        "operationId": "getXy",
        "requestBody": {
          "content": { }
        },
        "responses": { 
...

This is currently breaking our frontend API Client Generation with NSwag, because usually a GET Request doesn't allow a body, but it is being generated, due to the wrong generation of the swagger.json.

Expected Behavior

Generated JSON without requestBody

  "/route": {
      "get": {
        "tags": [
          "tag"
        ],
        "summary": "get xy",
        "operationId": "getXy",
        "responses": { 
...

Steps To Reproduce

    private static IEndpointRouteBuilder MapXy(this IEndpointRouteBuilder app)
    {
        var endpoints = app.MapGroup("/xy");
        
        
        endpoints.MapGet(
            "/",
            async ([FromServices] IXyService xyService) =>
            {
                var xy = await xyService.ListAllAsync();
                return TypedResults.Ok(xy);
            }
        ).WithOpenApi(openapi => new(openapi)
        {
            OperationId = "getXy",
            Summary = "Get xy",
            Tags = new List<OpenApiTag>() {new OpenApiTag() {Name = "tag"}}
        }).Produces<IReadOnlyList<XyDto>>(statusCode: StatusCodes.Status200OK);

        return app;
    }

Exceptions (if any)

No response

.NET Version

8.0.200

Anything else?

.NET SDK:
Version: 8.0.200
Commit: 438cab6a9d
Workload version: 8.0.200-manifests.e575128c

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.200\

.NET workloads installed:
There are no installed workloads to display.

Host:
Version: 8.0.2
Architecture: x64
Commit: 1381d5ebd2

.NET SDKs installed:
7.0.406 [C:\Program Files\dotnet\sdk]
8.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    old-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