Skip to content

fix: unwrap single-entry anyOf/oneOf nullable reference wrappers#7531

Merged
gavinbarron merged 5 commits intomainfrom
fix/nullable-ref-wrapper-stack-overflow
Apr 1, 2026
Merged

fix: unwrap single-entry anyOf/oneOf nullable reference wrappers#7531
gavinbarron merged 5 commits intomainfrom
fix/nullable-ref-wrapper-stack-overflow

Conversation

@gavinbarron
Copy link
Copy Markdown
Contributor

@gavinbarron gavinbarron commented Mar 25, 2026

  • Unwrap single-entry anyOf/oneOf ref wrappers in CreateModelDeclarations
  • Add discriminator cycle guard, reentrance guard, and depth guard
  • Add tests: NullableReferenceWrapperUnwrapsToReferencedSchemaAsync and NullableReferenceWrapperWithDiscriminatorIsNotUnwrappedAsync
  • Apply dotnet format - fix xUnit1051 warnings by using TestContext.Current.CancellationToken in new tests

Kiota hits a StackOverflowException when generating from OpenAPI specs that
use single-entry anyOf wrappers for nullable references to self-referential
schemas. This pattern is valid OpenAPI 3.0 and is now produced by newer
versions of hidi, which collapses the previous two-entry anyOf into a
cleaner single-entry form that kiota had no handler for.

- Unwrap single-entry anyOf/oneOf ref wrappers (no discriminator, no own
  properties) early in CreateModelDeclarations
- Add ThreadLocal<HashSet<string>> discriminator cycle guard in AddModelClass
- Add Monitor.IsEntered reentrance guard in ModelClassBuildLifecycle with
  warning log on activation
- Add ThreadLocal<int> depth guard (max 50) in CreatePropertiesForModelClass
  as safety net for patterns not caught by the unwrap
- Add regression tests for self-referential nullable ref unwrapping and
  discriminator-bearing wrapper preservation

Closes #7530

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@gavinbarron gavinbarron requested a review from a team as a code owner March 25, 2026 15:59
@msgraph-bot msgraph-bot bot added this to Kiota Mar 25, 2026
baywet
baywet previously approved these changes Mar 25, 2026
@baywet
Copy link
Copy Markdown
Member

baywet commented Mar 25, 2026

put together #7532 to unblock this

@gavinbarron gavinbarron enabled auto-merge (squash) April 1, 2026 13:54
@gavinbarron
Copy link
Copy Markdown
Contributor Author

@copilot run dornet format

…in tests

Agent-Logs-Url: https://github.com/microsoft/kiota/sessions/b7ce9587-9a01-4d10-a7cf-8fd0b3ffea35

Co-authored-by: gavinbarron <7122716+gavinbarron@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

@copilot run dornet format

Done in c4369c9. Applied dotnet format — fixed xUnit1051 warnings by using TestContext.Current.CancellationToken in the two new test methods.

@gavinbarron gavinbarron merged commit cd3a778 into main Apr 1, 2026
297 checks passed
@gavinbarron gavinbarron deleted the fix/nullable-ref-wrapper-stack-overflow branch April 1, 2026 15:09
@github-project-automation github-project-automation bot moved this from In Progress 🚧 to Done ✔️ in Kiota Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

3 participants