Replies
This resource contains a single object” indicates my Produces isn’t right I guess?
Yes, since you’re trying to return a collection, your type should describe some type of collection or enumerable.
e.g. .Produces<IEnumerable<PersonModel>>()
Anthony,
It’s not about App Builder supporting IResult, it’s about feeding Swagger with information to properly describe the response type.
e.g.

When using IResult with no additional information this area will be empty.
Even if I change the return Results.OK(…) to return TypedResults.OK(…) app builder stays greyed out I suspect because the PersonGetAll() function returns a Task<IResult>
If you only return OK results, then change it to Task<Ok<YourResponseType>> like in the docs:
public static async Task<Ok<Todo[]>> GetAllTodos(TodoGroupDbContext database)
{
var todos = await database.Todos.ToArrayAsync();
return TypedResults.Ok(todos);
}
If you need to keep IResult, then you need to add a .Produces<>() statement:
Consider the following endpoint, for which a 400 BadRequest status code is returned when the orderId is greater than 999. Otherwise, it produces a 200 OK with the expected content.
C#
app.MapGet("/orders/{orderId}", IResult (int orderId)
=> orderId > 999 ? TypedResults.BadRequest() : TypedResults.Ok(new Order(orderId)))
.Produces(400)
.Produces();
I hope this helps.
Hi Anthony,
Sorry that we missed your last reply.
[quote user=”510F913F05A872B58571539D53877DF984417AC9″]But I think the issue is returning an IResult?[/quote]
Exactly. Results.Ok() is an old method and loses all the type information which swagger (OpenAPI) needs to produce the correct metadata and App Builder to be able to "see" the return types.
In .Net 7+ you need to either:
- Return Task<YourResponseType>, where OK is assumed.
- Return TypedResult.Ok(yourResponse), where OK is explicit.
Any of those will be able to generate the correct OpenAPI Schema, and App Builder to consume it.
You can read more about typed results in .Net documentation TypedResults vs Results.
Regards,
Pablo