Is there an existing issue for this?
Describe the bug
I originally submitted this bug report to domaindrivendev/Swashbuckle.AspNetCore#3775 but they pointed out that this is a bug in ApiExporter.
I tried to use Results<Ok<WeatherForecast[]>, UnauthorizedHttpResult, ProblemHttpResult> as controller response type. It seems ApiExporter exports only a success response type and doesn't contain description for non-success responses.
I expected it to contain at least 401 for the UnauthorizedHttpResult in responses object.
Expected Behavior
All types from Results should be included as possible response types.
Steps To Reproduce
C# Code
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http.HttpResults;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.MapControllers();
app.Run();
public record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
[HttpGet]
public Results<Ok<WeatherForecast[]>, UnauthorizedHttpResult, ProblemHttpResult> Get()
{
try
{
var result = Random.Shared.Next(3);
if (result == 1)
{
return TypedResults.Unauthorized();
}
if (result == 2)
{
throw new InvalidOperationException("Failed to get the weather forecast");
}
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
Summaries[Random.Shared.Next(Summaries.Length)]
))
.ToArray();
return TypedResults.Ok(forecast);
}
catch (Exception ex)
{
return TypedResults.Problem(ex.Message);
}
}
}
Exceptions (if any)
No response
.NET Version
10.0.102
Anything else?
No response
Is there an existing issue for this?
Describe the bug
I originally submitted this bug report to domaindrivendev/Swashbuckle.AspNetCore#3775 but they pointed out that this is a bug in ApiExporter.
I tried to use
Results<Ok<WeatherForecast[]>, UnauthorizedHttpResult, ProblemHttpResult>as controller response type. It seems ApiExporter exports only a success response type and doesn't contain description for non-success responses.I expected it to contain at least 401 for the UnauthorizedHttpResult in responses object.
Expected Behavior
All types from Results should be included as possible response types.
Steps To Reproduce
C# Code
Exceptions (if any)
No response
.NET Version
10.0.102
Anything else?
No response