-
Notifications
You must be signed in to change notification settings - Fork 10.4k
OpenAPI: Fix Circular reference in specific order gives empty schema #63511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This was a head-scratcher 😅. The fun of recursive methods 😛. |
@captainsafia I know it was yesterday, but I remember why it's in two seperate groups in the sample. If one of the property orders is correct the referencedmodel schema is emitted. So it's in the rare case when the circular reference is in the specific order, and the referenced model is not used in any other endpoint. I will remove it from the sample (it's not really adding value there) and just create two seperate isolated unit tests in the schema service tests. |
@desjoerd Sounds like a good plan to just use unit tests to validate this -- thanks! |
This is fixed by not adding/registering a schema when it contains a reference, as it is a incomplete/unresolved schema
1f27ab9
to
f159bed
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug in the OpenAPI schema generation service where circular references processed in a specific order could result in empty schemas. The fix changes how schema references are handled to prevent premature registration of incomplete schemas.
Key changes:
- Modified the
ResolveReferenceForSchema
method to return a reference instead of registering the schema immediately - Added comprehensive test coverage for circular reference scenarios with different property orders
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
OpenApiSchemaService.cs | Changed schema reference resolution to prevent premature registration of incomplete schemas |
OpenApiSchemaService.SchemaReferences.cs | Added test cases covering circular reference scenarios with different property ordering |
...NetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.SchemaReferences.cs
Outdated
Show resolved
Hide resolved
...NetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.SchemaReferences.cs
Outdated
Show resolved
Hide resolved
...NetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.SchemaReferences.cs
Outdated
Show resolved
Hide resolved
@captainsafia I've moved the tests 😊. Luckily the same methods where available so an easy change. Let me know if you prever them higher up or not. I am not fond of |
OpenAPI: Fix Circular reference in specific order gives empty schema
In the ResolveReferenceForSchema method it could be that when executed in a certain order with a circular reference that it would register the schema without properties.
Description
In the ResolveReferenceForSchema method it now no longer registers schemas with a $ref as a full schema. They will eventually be registered as the method is recursive.
Fixes #63503