Skip to content
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

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

captainsafia
Copy link
Member

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.

  • Resolves a bug where a [Produces] attribute with no-type would override the schema for a pre-existing schema by replacing direct assignment for content types with TryAdd in OpenApiDocumentService.GetResponseAsync.
  • Adds sub-schemas recursively into the schema-by-reference cache by updating 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?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

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

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

@captainsafia captainsafia added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc labels Sep 13, 2024
@captainsafia captainsafia requested a review from a team as a code owner September 13, 2024 06:28
@captainsafia captainsafia added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Sep 13, 2024
// reference by duplicate rules.
if (schema == null || currentDepth > MaxSchemaReferenceRecursionDepth)
{
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can/should we log?

Copy link
Member Author

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.

Copy link
Member Author

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...

@captainsafia captainsafia added the Servicing-consider Shiproom approval is required for the issue label Sep 13, 2024
@@ -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;
Copy link
Member

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?

Copy link
Member Author

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. :/

Copy link
Member Author

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.

@captainsafia captainsafia added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Sep 14, 2024
@captainsafia
Copy link
Member Author

Approved via email.

@wtgodbe wtgodbe merged commit 9b3ca0b into release/9.0 Sep 16, 2024
25 checks passed
@wtgodbe wtgodbe deleted the safia/openapi-bug-fixes branch September 16, 2024 15:45
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-rc2 milestone Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-openapi Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants