OpenAPI: nullability is dropped for collection elements whose type is componentized
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
When a collection's element type is a nullable value type that gets componentized into #/components/schemas/*, the generated document loses the element's nullability. The items schema is emitted as a bare $ref to the non-nullable component:
```
"listOfNullableEnums": {
"type": "array",
"items": { "$ref": "#/components/schemas/TestEnum" }
}
```
Affected shapes include, at minimum:
• Properties typed List on request or response models.
• Response bodies typed TEnum?[].
The similar query-parameter scenario, TEnum?[] nullableValues, was addressed separately in PR #[68250](https://github.com/dotnet/aspnetcore/pull/68250).
### Expected Behavior
Nullable collection elements should keep their nullability:
```
"items": {
"oneOf": [
{ "type": "null" },
{ "$ref": "#/components/schemas/TestEnum" }
]
}
```
### Steps To Reproduce
_No response_
### Exceptions (if any)
_No response_
### .NET Version
_No response_
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.