[release/10.0] OpenAPI: Fix Circular reference in specific order gives empty schema #63585
+144
−1
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.
Backport of #63511 to release/10.0
/cc @captainsafia @desjoerd
OpenAPI: Fix Circular reference in specific order gives empty schema
Summary of the changes (Less than 80 chars)
Fix circular reference resolution to prevent empty schemas regardless of property order
Description
This PR fixes an issue in the OpenAPI schema generation service where circular references could result in empty schemas for referenced types depending on the order of property declarations. The fix changes the schema reference resolution logic from using
AddOpenApiSchemaByReference
to directly creatingOpenApiSchemaReference
objectsFixes #63503
Customer Impact
Customers using ASP.NET Core's OpenAPI generation with models containing circular references may experience incomplete or empty schemas in their OpenAPI documents, particularly when the order of properties affects schema processing. We can consider this a follow-on the the circular reference fixes that we included in .NET 10 Preview 7.
Regression?
Risk
This is a targeted fix that only changes the reference creation mechanism without affecting the broader schema generation architecture. The change is minimal and there's existing and new test coverage in the space.
Verification
Packaging changes reviewed?