Repository navigation
Conversation
SchemaDiff resolves $ref schemas against the components before comparing them, so the fact that a schema was reached through a reference is lost in the diff result: ChangedSchema only keeps the resolved schemas. Keep the original $ref values on ChangedSchema before resolution. They are captured in SchemaDiff#computeDiffForReal, the single place where every schema pair passes through, and in the additional properties fallback of SchemaDiffResult, which builds its schema without going through that path. The refs are inert metadata for downstream consumers and do not affect change detection. Part of OpenAPITools#956 Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
There was a problem hiding this comment.
1 issue found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="core/src/main/java/org/openapitools/openapidiff/core/compare/SchemaDiff.java">
<violation number="1" location="core/src/main/java/org/openapitools/openapidiff/core/compare/SchemaDiff.java:362">
P2: `keepSourceRefs` can overwrite nested item refs because array diffs return their `itemsDiff` as the result. A referenced array containing a changed referenced item therefore reports the array's `$ref` on the item's `ChangedSchema`; apply refs to the actual owning schema or preserve the child metadata instead of unconditionally overwriting it.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| // If schema type is same then get specific SchemaDiffResult and compare the properties | ||
| SchemaDiffResult result = SchemaDiff.getSchemaDiffResult(right.getClass(), openApiDiff); | ||
| return result.diff(refSet, leftComponents, rightComponents, left, right, context); | ||
| return keepSourceRefs( |
There was a problem hiding this comment.
P2: keepSourceRefs can overwrite nested item refs because array diffs return their itemsDiff as the result. A referenced array containing a changed referenced item therefore reports the array's $ref on the item's ChangedSchema; apply refs to the actual owning schema or preserve the child metadata instead of unconditionally overwriting it.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At core/src/main/java/org/openapitools/openapidiff/core/compare/SchemaDiff.java, line 362:
<comment>`keepSourceRefs` can overwrite nested item refs because array diffs return their `itemsDiff` as the result. A referenced array containing a changed referenced item therefore reports the array's `$ref` on the item's `ChangedSchema`; apply refs to the actual owning schema or preserve the child metadata instead of unconditionally overwriting it.</comment>
<file context>
@@ -352,11 +354,28 @@ public DeferredChanged<ChangedSchema> computeDiffForReal(
// If schema type is same then get specific SchemaDiffResult and compare the properties
SchemaDiffResult result = SchemaDiff.getSchemaDiffResult(right.getClass(), openApiDiff);
- return result.diff(refSet, leftComponents, rightComponents, left, right, context);
+ return keepSourceRefs(
+ result.diff(refSet, leftComponents, rightComponents, left, right, context),
+ leftRef,
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #956 (item 1 of 4: storing the old/new
$refonChangedSchema; the change-list/builder items remain open).What
ChangedSchemanow keeps the$refvalues the old and new schemas were referenced by before the diff resolved them:getOldRef()/getNewRef()(with fluent setters) onChangedSchema, plus the usual equals/hashCode/toString treatment. The values are inert metadata for downstream consumers; they do not affect change detection.SchemaDiff#computeDiffForReal, the single place every schema pair passes through, right beforeRefPointer#resolveRefdrops the refs. This covers the direct path, the deferred schema cache (the raw schemas are re-diffed there later with their refs intact), property refs, array items, oneOf mappings, and the type-changed result.SchemaDiffResult#compareAdditionalPropertiesbuilds oneChangedSchemaoutside that path (the added/removed additional-properties fallback), so it stores the refs from the raw schemas there too.No renderer or rule changes; nothing consumes the new fields yet. This builds on the ref-following model from #938 and gives the later R0 change-list slices the location information they need.
Tests
New fixture pair
schemaDiff/schema-ref-handling-*.yamlcovering the three capture shapes, asserted inSchemaDiffTest#schemaRefsAreKeptOnChangedSchema:$refto a component schema: old and new refs kept on the top-levelChangedSchema$refwhose target changed type: refs kept on the propertyChangedSchema(the deferred-cache path)./mvnw verifypasses: 271 core tests, 13 maven-plugin tests, 0 failures (2 pre-existing skips inSwagger2CompatibilityTest). The coveo format check runs as part of the build.Question on the issue text
The last scope line of #956 says
ruleandresultare "owned by #724", but that issue no longer exists (404). Those fields are untouched here either way; asking in case the ownership moved somewhere this branch of work should reference.Summary by cubic
ChangedSchemanow records the$refvalues the old and new schemas were referenced by before the diff resolves them, so downstream consumers can tell which component schemas were compared.SchemaDiff#computeDiffForReal, the single path every schema pair passes through, covering request-body, property, array, andoneOf-mapped refs plus the deferred-cache re-diff; the additional-properties fallback inSchemaDiffResult#compareAdditionalPropertiescaptures refs separately.nullrefs.Part of #956 (item 1 of 4). Note the issue's last scope line assigns
rule/resultownership to #724, which no longer exists; those fields are untouched here.Written for commit 80f81c7. Summary will update on new commits.