-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Harden schema reference transformer for relative references #59763
Conversation
1db3d04
to
9b39954
Compare
...NetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs
Show resolved
Hide resolved
...NetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs
Show resolved
Hide resolved
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/OpenApiSchemaExtensionsTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Brennan <[email protected]>
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Extensions/OpenApiSchemaExtensionsTests.cs
Outdated
Show resolved
Hide resolved
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.
Looks good! 👍
...NetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs
Show resolved
Hide resolved
...NetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs
Show resolved
Hide resolved
...NetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs
Show resolved
Hide resolved
We also have a similar issue, when can we expect a fix to be released for this issue? |
This PR will need to be approved and merged into main first before being back ported and going through the servicing process (ref). Release timelines vary depending on when the PRs to main and release/9.0 get merged so we'll know then. |
/backport to release/9.0 |
Started backporting to release/9.0: https://github.com/dotnet/aspnetcore/actions/runs/12677731301 |
@captainsafia backporting to release/9.0 failed, the patch most likely resulted in conflicts: $ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Harden schema reference transformer for relative references
Using index info to reconstruct a base tree...
M src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs
M src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs
Auto-merging src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs
CONFLICT (content): Merge conflict in src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config advice.mergeConflict false"
Patch failed at 0001 Harden schema reference transformer for relative references
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
* Harden schema reference transformer for relative references * Apply suggestions from code review Co-authored-by: Brennan <[email protected]> * Remove uneeded setting * One more cleanup * Check for top-level schemas in tests --------- Co-authored-by: Brennan <[email protected]>
…nces (#59779) * Harden schema reference transformer for relative references (#59763) * Harden schema reference transformer for relative references * Apply suggestions from code review Co-authored-by: Brennan <[email protected]> * Remove uneeded setting * One more cleanup * Check for top-level schemas in tests --------- Co-authored-by: Brennan <[email protected]> * Update src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/Implementations/OpenApiSchemaReferenceTransformerTests.cs --------- Co-authored-by: Brennan <[email protected]>
Addresses #59677, #58968, and #59427.
This PR resolves a set of issues that have been reported with schema reference resolution in the OpenAPI implementation. The crux of the issue deals with the way the underlying System.Text.Json generates relative references for schemas that include recursion or duplication.
For example, given the following type:
The JsonSchemaExporter will produce the following schema:
Where a relative reference to the first
name
schema in theItem1
property is used in theItem2
property. STJ anchors these references relative to the base type that was provided to the exporter, theRoot
type in this case. These relative references don't map to the OpenAPI document where the root for all schemas is the#/components/schemas
entry.To resolve this issue, we update the OpenAPI schema comparer to treat schemas where one schema uses a relative reference and the other does not as equivalent. In this case, the schemas for the
item1
anditem2
properties would be considered as equivalent since on contains a reference mapped to the other.The current implementation is optimized to address the issue for when nested types are included directly in the referenced property. This PR expands the fix to address relative references that occur anywhere in the schema.