Repository navigation
fix: compare the schema behind a changed $ref - #668
Open
josephaxisa wants to merge 1 commit into
Open
josephaxisa wants to merge 1 commit into
josephaxisa wants to merge 1 commit into
Conversation
When a schema $ref was replaced by an inline schema, an inline schema by a $ref, or a $ref pointed somewhere else, CompareSchemas recorded a non-breaking $ref change and returned, so changes in the new schema were never reported. A $ref to a schema with type: int becoming an inline type: string was a single non-breaking change. Keep the $ref change, then compare the two schemas as it would compare two inline schemas. It still stops at the $ref change, now keeping that change instead of returning nil, when either side doesn't resolve, is on a reference loop, or comes from a document that was not checked for circular references (a loop can't be recognised there), and when a 3.1 $ref with sibling keywords is involved, since its internal allOf form doesn't line up with the referenced schema field by field. Rolodex gains HasCheckedForCircularReferences for that check. The helpers that recognise equivalent forms now look through a reference, so a change made through a $ref is reported like the same inline change: the object composition handling from pb33f#650 ($ref: Thing becoming anyOf: [$ref: Thing, type: 'null']), the simple allOf view, and a type array matching an anyOf of scalar types. Fixes pb33f#663
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #668 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 309 309
Lines 39178 39197 +19
=========================================
+ Hits 39178 39197 +19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Fixes #663.
When a
$refwas replaced by an inline schema, an inline schema by a$ref, or a$refpointed at another schema,CompareSchemasrecorded the non-breaking$refchange and returned. The new schema was never compared, so the repro in #663 ($ref: Petbecoming an inline schema withrequired: [name]) reported 1 non-breaking change, while the same edit between two inline schemas is breaking.The
$refchange is now kept, and the two schemas are then compared like any other two schemas, as e935b3e did. Comparison stops at the$refchange (keeping it rather than returning nil) when:SkipExternalRefResolution). Otherwise everything would be reported as removed.SkipCircularReferenceCheck), since a loop can't be recognised there.Rolodexgets a smallHasCheckedForCircularReferences()getter for this.$refwith sibling keywords is involved. Its internalallOfform doesn't line up with the referenced schema field by field. That case needs its own fix.Three helpers that recognise equivalent forms now look through a reference, so a change made through a
$refis reported like the same change made inline:$ref: ThingbecominganyOf: [$ref: Thing, type: 'null']reports the$refchange plus the non-breakinganyOfaddition, not removed properties.allOfobject view.anyOfof scalar types.Existing tests that asserted a single change now also assert the change behind the
$ref, e.g.TestCompareSchemas_PropertyRefChange_Fail(int→string, breaking). InTestCheckExplodedFileCheck, both references change andc-alt.yamlhas a new description, so the test now expects 3 non-breaking changes. The threeCheckRefChangeCirculartests keep the$refchange instead of expecting nil.New tests: the #663 repro both ways and checked against the inline equivalent, a retargeted
$ref, an identical inline copy (still no change), the simpleallOfview, the nullable wrap, siblings and circular targets stopping at the$ref, unresolved targets, a skipped circular check, and the equivalent scalar union. The touched functions are at 100% coverage. The full suite and openapi-changes' tests pass.Things worth knowing:
$refcosts what following an identical external$refalready costs: a deep graph of shared schemas is compared once per path. I checked a 25-level diamond where every level is renamed. Memoizing per schema pair would make the comparison cheap, but the report would still list the change once per path, so I left that for a separate discussion. On real Stripe history the time and memory are unchanged. Loaded the way openapi-changes loads it, and with $ref changes are dropped when a document has any circular reference #662's fix, the 2024-01...2026-09 diff gains 117 breaking changes.$refpoint at the target schema's lines, as they do when an external$refis followed today.$refchange each.Related: #662. In documents with any circular reference, this only takes effect with that fix.