-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Please support Results<T> as return type of controllers #2595
Comments
I also need this featue. Thank for your support 👍👍🙏 |
1 similar comment
I also need this featue. Thank for your support 👍👍🙏 |
It's a know issue. You can read this GitHub issue to full detail : In summary, metadata aren't correctly inferred to action that return type HttpResults... but sadly, Swashbuckle need this metadata to generate the OpenApi schema. While waiting for a resolution, I do a operation filter to generate OpenApi response from HttpResults type and I wrapped it in a NuGet package : You can add the package : dotnet add package Vernou.Swashbuckle.HttpResultsAdapter So you can register the filter : var builder = WebApplication.CreateBuilder(args);
...
builder.Services.AddSwaggerGen(options =>
{
...
options.OperationFilter<Vernou.Swashbuckle.HttpResultsAdapter.HttpResultsOperationFilter>();
}); If you prefer, you can just copy/paste the filter file from the package repository : |
Hi
Hi, I gave your package a try. But there is one issue: most of my controller methods are async. Hence they return a Task. Your code does not account for this. I'll have a deeper look into your code and send you an suggestion how to hande async |
excellent |
FYI. this is supported in DotSwashbuckle v3.0.8+ |
@martincostello I do not see this an issue, if you use TypeResults you should use them only in MinimalApi (I have checked that the TypedResults works as expected). I would never use TypedResults over Controllers |
From the documentation Controller action return types in ASP.NET Core web API :
So it sound a legit use case. |
Yeah, I showed it, but I would in any case create an issue in open-api dotnet and wait for a new release |
I have just tested it with .NET 8 and Swashbuckle.AspNetCore v6.6.2 and it still doesn't produce any response type: "/WeatherForecast/{date}": {
"get": {
"tags": [
"WeatherForecast"
],
"operationId": "GetWeatherForecastByDate",
"parameters": [
{
"name": "date",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "date"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
} |
Yeah, I can indeed see the commit that was done in DotnetSwashbuckle, but as is not available either in new openApi package of MS, I have notified them |
…th FluentValidator. 2. Change actions return type to TypedResults to return different responses. Still have to use ProducesResponseType for Swagger. See domaindrivendev/Swashbuckle.AspNetCore#2595
@martincostello I am thinking about applying the same fix that was done in DotSwashbuckle. I created a PR to fix this on aspnetCore itself but I am not sure if they are going to backport it. |
I think it's fair game for any changes in DotSwashbuckle to fix user's issues to be ported back here. |
Introducing .NET 7
Results<T>
(https://learn.microsoft.com/en-us/aspnet/core/web-api/action-return-types#resultt-type) Microsoft promised thatBut if I write this:
The generated
swagger.json
only contains that:In order to get the correct schema I still need to add the following
ProducesResponseTypeAttribute
s :-(The text was updated successfully, but these errors were encountered: