RequestDelegateGenerator enabled results in incorrect ApiParameterDescription.IsRequired for nullable array
- 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
Basically the title. This translates to issues with the downstream OpenApi document, Swagger pages, etc.
### Expected Behavior
Enabling RDG should not affect how `ApiParameterDescription`s are generated
### Steps To Reproduce
Create a new dotnet 10 minimal API project.
```xml
net10.0
enable
enable
true
```
```cs
using Microsoft.AspNetCore.Mvc.ApiExplorer;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("demo", ([AsParameters] Request request, IApiDescriptionGroupCollectionProvider descriptionGroupCollectionProvider) =>
{
var apiDescription = descriptionGroupCollectionProvider.ApiDescriptionGroups.Items.SelectMany(x => x.Items).Single();
return apiDescription.ParameterDescriptions.ToDictionary(p => p.Name, p => p.IsRequired);
});
await app.RunAsync();
public class Request
{
// When is enabled, this incorrectly determines this parameter is required. When disabled, it works correctly.
// This behaved correctly in dotnet 8 regardless of RDG
public int[]? OptionalIds { get; set; }
// This has correct nullability, regardless of RDG
public string? OptionalString { get; set; }
}
```
Note that the `IsRequired` for the `ApiParameterDescription` for the `OptionalIds` is incorrect, but only if RDG is set to enabled. I have so far only noticed this for nullable arrays, and not for other types (as included in the demo)
### Exceptions (if any)
None
### .NET Version
dotnet 10
### Anything else?
Let me know if the repro steps are not clear for some reason.
Contributor guide
Assessment
This issue has not been assessed yet.