-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Fix mapping for nested schemas and [Produces] attributes in OpenAPI implementation #57852
Conversation
// reference by duplicate rules. | ||
if (schema == null || currentDepth > MaxSchemaReferenceRecursionDepth) | ||
{ | ||
return; |
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.
Can/should we log?
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.
Yep, we should be able to inject a logger into this codepath.
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.
Hmmm...actually I think we should throw here...
@@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.OpenApi; | |||
/// </summary> | |||
internal sealed class OpenApiSchemaStore | |||
{ | |||
// Matches default MaxValidationDepth and MaxModelBindingRecursionDepth used by MVC. | |||
private readonly int MaxSchemaReferenceRecursionDepth = 32; |
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.
MaxValidationDepth
and MaxModelBindingRecursionDepth
are both configurable via MvcOptions
. Do we think this will need to be configurable too?
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.
In a future release, yes, but we will have to live with it being un-configurable for .NET 9 for now. :/
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.
Per off-line discussion, we're relying on STJ's recursion depth check which do have a configurable option via JsonSerializerOptions.MaxDepth
.
Approved via email. |
Description
This PR consists of two changes to address feedback received after .NET 9 RC 1 for the new APIs in the Microsoft.AspNetCore.OpenApi package.
[Produces]
attribute with no-type would override the schema for a pre-existing schema by replacing direct assignment for content types withTryAdd
inOpenApiDocumentService.GetResponseAsync
.OpenApiSchemaStore.PopulateSchemaIntoReferenceCache
.Fixes #57799
Customer Impact
This PR resolves issues reported in the OpenAPI implementation that don't currently have any viable workarounds for users. Without these changes, documents generated by this implementation may unintentionally drop schemas for responses generated controller actions with certain attributes. This change also stabilizes the generations of schema names for deeply nested type hierarchies in the OpenAPI document.
Regression?
Risk
Changes in this PR only impact the
Microsoft.AspNetCore.OpenApi
and don't affect any APIs in the shared framework. Changes are in new code paths that were introduced in .NET 9 so there is no risk of version-to-version regression.Verification
Packaging changes reviewed?