C
C#2y ago
ægteemil

❔ Swagger shows unwanted schemas when with minimal api

Hey. If I have an endpoint like this:
app.MapGet("foo", () => Foo.Bar).Produces(StatusCodes.Status200OK);
app.MapGet("foo", () => Foo.Bar).Produces(StatusCodes.Status200OK);
Where the method Foo.Bar looks like:
public static class Foo
{
public static IResult Bar()
{
return Results.Ok("foo-bar");
}
}
public static class Foo
{
public static IResult Bar()
{
return Results.Ok("foo-bar");
}
}
My swagger output includes a bunch of schemas. If I simply do the endpoint like this instead, they don't appear:
// adding () after Bar makes the schema work as expected
app.MapGet("foo", () => Foo.Bar()).Produces(StatusCodes.Status200OK);
// adding () after Bar makes the schema work as expected
app.MapGet("foo", () => Foo.Bar()).Produces(StatusCodes.Status200OK);
This is obviously not a problem with an endpoint like this, but as soon as the endpoint starts taking in stuff from DI it becomes a problem
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?