Honor nullable collection elements in OpenAPI schemas - #68982
Open
snemeckayova wants to merge 4 commits into
Open
Honor nullable collection elements in OpenAPI schemas#68982snemeckayova wants to merge 4 commits into
snemeckayova wants to merge 4 commits into
Conversation
…ility-componentized-type
snemeckayova
marked this pull request as ready for review
September 3, 2026 11:39
snemeckayova
requested review from
a team,
Youssef1313,
cincuranet,
davpetr and
rokonec
as code owners
September 3, 2026 11:39
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes directly address the described nullability loss, are consistently applied across properties/items/additionalProperties, and are backed by targeted tests plus updated integration snapshots.
Pull request overview
This PR updates ASP.NET Core’s OpenAPI schema generation to correctly preserve C# nullable annotations for collection element schemas (arrays/lists) and dictionary value schemas, including when those element/value schemas are componentized (moved into #/components/schemas/*). This aligns generated documents with expected OpenAPI nullability semantics and fixes the reported regression in #68322.
Changes:
- Propagates “nullable element/value” intent through schema generation via
x-is-nullable-propertymetadata for componentized item/value schemas and resolves them intooneOfnullable wrappers. - Adds response-specific handling so nullable array element return types (including async returns) produce nullable
itemsschemas. - Extends test coverage and updates integration snapshots across OpenAPI 3.0/3.1/3.2 outputs.
File summaries
| File | Description |
|---|---|
| src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs | Ensures nullable wrappers are applied when resolving references for properties, array items, and dictionary additionalProperties. |
| src/OpenApi/src/Services/OpenApiDocumentService.cs | Applies nullable-item handling for response schemas when the action return type’s array element is nullable. |
| src/OpenApi/src/Extensions/TypeExtensions.cs | Adds response array-element nullability detection using NullabilityInfoContext and refactors response nullability logic into a shared helper. |
| src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs | Applies nullable annotations to collection element schemas and dictionary value schemas during JsonNode-based schema generation, including componentized cases via metadata. |
| src/OpenApi/test/.../OpenApiSchemaService.ResponseSchemas.cs | Adds a focused test for nullable componentized array elements in response schemas. |
| src/OpenApi/test/.../OpenApiSchemaService.PropertySchemas.cs | Adds a focused test for nullable componentized collection elements in request model property schemas. |
| src/OpenApi/test/.../snapshots/*.verified.txt | Updates expected OpenAPI document snapshots to reflect preserved element/value nullability across versions. |
Review details
- Files reviewed: 10/10 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Updates OpenAPI schema generation to preserve nullable annotations for collection elements and dictionary values.
Nullable inline element schemas include null in their type. Nullable componentized elements use a nullable oneOf wrapper around the component reference. The same behavior is applied to model properties, dictionary values, and array response elements, including asynchronous endpoint return types.
Fixes #68322