Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect swagger.json causing application hang in Minimal API when using WithOpenApi extension method with DateTime query parameter #45305

Closed
1 task done
marcominerva opened this issue Nov 28, 2022 · 1 comment
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@marcominerva
Copy link
Contributor

marcominerva commented Nov 28, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm using .NET 7.0. I have created a Minimal API with the following endpoint:

app.MapPost("/api/people", (Person person, DateTime? dateTime) =>
{
    return TypedResults.NoContent();
});

public record class Person(string FirstName, string LastName);

The corresponding swagger.json contains the following definition:

"parameters": [
  {
    "name": "dateTime",
    "in": "query",
    "style": "form",
    "schema": {
      "type": "string"
    }
  }
]

If, however, I add a call to WithOpenApi extension method after the MapPost:

app.MapPost("/api/people", (Person person, DateTime? dateTime) =>
{
    return TypedResults.NoContent();
}).WithOpenApi();

Then the swagger.json changes in this way:

"parameters": [
  {
    "name": "dateTime",
    "in": "query",
    "style": "form",
    "schema": {
      "type": "string"
    },
    "content": {
      "application/json": { }
    }
  }
]

The content section has appeared. The result is that, if I try to call the endpoint using Swagger, with no dateTime query parameter, the Minimal API totally hang. If, instead, I specify a value (let's say 2020-01-01), the endpoint is correctly invoked.
After that, if I try to call again the endpoint, with no query parameter, now the API is reached as expected.

Expected Behavior

Endpoint with optional DateTime query parameter should not hang at the first call when I use the WithOpenApi extension method.

Steps To Reproduce

Minimal repro here: https://github.com/marcominerva/MinimalApiHang.

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

Visual Studio 2022 17.4.1

.NET SDK:
Version: 7.0.100
Commit: e12b7af219

Ambiente di runtime:
OS Name: Windows
OS Version: 10.0.22621
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100\

Host:
Version: 7.0.0
Architecture: x64
Commit: d099f075e4

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

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0 [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

@captainsafia
Copy link
Member

This looks like it might be a dupe of #45365.

Omitting the Content property causes the UI to execute the request correctly. This behavior only happens when sending requests via the Swagger UI so I suspect that there might be an issue there.

More comments to follow in the issue linked above.

@captainsafia captainsafia added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Dec 1, 2022
@ghost ghost added the Status: Resolved label Dec 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Dec 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants