RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.67k stars 1.23k forks source link

Minimal API - Nested MapGroups #4341

Open shaunpearsondev opened 1 year ago

shaunpearsondev commented 1 year ago

When using Nested Groups in minimal api's like below

var root = app.MapGroup("/first/{param1}")
    .RequireAuthorization();

root.MapGroup("second")
   .MapGet("{param2}", IResult(string param2) 
        => TypedResults.Ok(param2));

the swagger is generating a route of

/first//second/{param2} instead of /first/{param1}/second/{param2}

and is also not generating a way to enter a value for {param1}

I did a little bit of further digging and when trying to add a custom OperationProcessor it appear as though the OpenApiOperationDescription is not being formed correctly.

Please let me know if you need any more information

MattParkerDev commented 2 months ago

Its not generating a way to enter param1 because you haven't passed param1 to the second route's parameters. it should be

var root = app.MapGroup("/first/{param1}")
    .RequireAuthorization();

root.MapGroup("second")
   .MapGet("{param2}", IResult(string param1, string param2) 
        => TypedResults.Ok(param2));
shaunpearsondev commented 2 months ago

Thanks Matt,

I think there was a subtle nuance to this that doesn't appear to be caught in the post... I swapped to swashbuckle for the use case as it did work there.

Away on holiday this week so will double check when I'm back.