-
Notifications
You must be signed in to change notification settings - Fork 10.3k
WithOpenAPI Generates Empty requestBody.content #54189
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
Comments
Any news on this? |
Right now this would be a Workaround. Just applying a filter and nulling the RequestBody whenever the HttpMethod is "GET". public class HttpGetBodyFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (context.ApiDescription.HttpMethod is not "GET")
{
return;
}
if (operation.RequestBody is not null)
{
operation.RequestBody = null;
}
}
} |
@LouisTrinczek Thanks for reporting this issue! I've tracked down that this seems to only repro when using the copy constructor provided for .WithOpenApi(openApi => {
openApi.OperationId = "GetWeatherForecast";
openApi.Summary = "Get weather forecast";
openApi.Tags = new List<OpenApiTag>() {new OpenApiTag() {Name = "WeatherForecast"}};
return openApi;
}); It looks like the underlying issue was fixed in microsoft/OpenAPI.NET#1195. We'll need to bump up the version of |
Thank you! |
@LouisTrinczek I've only merged the fix into .NET 9 for now. Locally, you should be able to resolve this by bumping up the version of
|
Is there an existing issue for this?
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].
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
Steps To Reproduce
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
The text was updated successfully, but these errors were encountered: