OpenAPI: Minimal API unused Path parameters are not emitted in the OpenAPI
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
The following unit test fails because the parameters are `null`.
```csharp
[Fact]
public async Task SupportsUnusedRouteParametersFromMinimalApis()
{
var source = """
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
var builder = WebApplication.CreateBuilder();
builder.Services.AddOpenApi();
var app = builder.Build();
app.MapGet("/{userId}", RouteHandlerExtensionMethods.Get);
app.Run();
public static class RouteHandlerExtensionMethods
{
/// The id of the user.
public static string Get()
{
return "Hello, World!";
}
}
""";
var generator = new XmlCommentGenerator();
await SnapshotTestHelper.Verify(source, generator, out var compilation);
await SnapshotTestHelper.VerifyOpenApi(compilation, document =>
{
var path = document.Paths["/{userId}"].Operations[HttpMethod.Get];
Assert.NotEmpty(path.Parameters);
Assert.Equal("The id of the user.", path.Parameters[0].Description);
});
}
```
### Expected Behavior
The unused path parameter `{userId}` should be emitted on the operation or on the path as a parameter (that is `document.Paths["/{userId}"].Parameters`).
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
10.0.100-rc.1.25420.111
### Anything else?
Found while fixing #63757
Contributor guide
Assessment
This issue has not been assessed yet.