Open aureole82 opened 1 year ago
I also need this featue. Thank for your support 👍👍🙏
I also need this featue. Thank for your support 👍👍🙏
It's a know issue. You can read this GitHub issue to full detail :\ TypedResults metadata are not inferred for API Controllers
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 :\ Vernou.Swashbuckle.HttpResultsAdapter
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 :\ HttpResultsOperationFilter.cs
Hi
It's a know issue. You can read this GitHub issue to full detail : TypedResults metadata are not inferred for API Controllers
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 : Vernou.Swashbuckle.HttpResultsAdapter
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 : HttpResultsOperationFilter.cs
Hi, I gave your package a try. But there is one issue: most of my controller methods are async. Hence they return a Task
@hjrb, thank for you return.
The support to async action was added in the version 1.0.1.
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 :
Results<TResult1, TResultN> type
The static TypedResults class returns the concrete IResult implementation that allows using IResult as return type. The usage of the concrete IResult implementation offers the following benefit over the IResult type: ...
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
FYI. this is supported in DotSwashbuckle v3.0.8+
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
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 :-(