Skip to content

Conversation

@sunshowers
Copy link
Contributor

Previously, if an element changed between:

  • a single-element anyOf, allOf, or oneOf
  • a bare reference

Then, we wouldn't be able to tell that they were semantically equivalent. (This kind of change can occur if a doc comment gets added or goes away.)

Fix this by unwrapping single-element wrappers, drilling through them to compare the underlying refs.

Also add some debugging info I found useful.

Created using spr 1.3.6-beta.1
metadata: new_meta,
},
) => {
if old_meta != new_meta {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it okay to just compare the metadata like this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Close enough until we have some tighter comparison?

@sunshowers sunshowers requested a review from ahl December 8, 2025 19:55
Copy link
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

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

This is all good and thank you for doing it. I do think we might consider these cases a little more generally--in particular such that we don't require the singleton subschema to be a $ref.

I could imagine saying

  • are both new and old singleton subschemas? then compare those subschemas?
  • is new a singleton subschema, compare its subschema to old
  • is old a singleton subschema, compare its subschema to new

For example, I made this test:

[
  {
    "op": "replace",
    "path": "/paths/~1hello~1{name}/get/parameters/0/schema",
    "value": {
      "allOf": [
        {
          "type": "string"
        }
      ]
    }
  }
]

and it fails like this:

--- change-param-to-allof.json
+++ patched
@@ -76,7 +76,11 @@
             "in": "path",
             "name": "name",
             "schema": {
-              "type": "string"
+              "allOf": [
+                {
+                  "type": "string"
+                }
+              ]
             }
           },
           {


Result for patch:
[
    Change {
        message: "schema kind changed from regular type to allOf",
        old_path: [
            "#/paths/~1hello~1{name}/get/parameters/0/schema",
        ],
        new_path: [
            "#/paths/~1hello~1{name}/get/parameters/0/schema",
        ],
        comparison: Input,
        class: Incompatible,
        details: Datatype,
    },
]

metadata: new_meta,
},
) => {
if old_meta != new_meta {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Close enough until we have some tighter comparison?

Created using spr 1.3.6-beta.1
@sunshowers
Copy link
Contributor Author

This is all good and thank you for doing it. I do think we might consider these cases a little more generally--in particular such that we don't require the singleton subschema to be a $ref.

Fixed and added tests for these cases.

Comment on lines +340 to +342
let old_not = old_schema_kind.append_deref(old_not.as_ref(), "not");
let new_not = new_schema_kind.append_deref(new_not.as_ref(), "not");
self.compare_schema_ref_helper(dry_run, comparison, old_not, new_not)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also ended up fixing this (I think?) since it was pretty straightforward.

Copy link
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

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

nice work

"#/paths/~1hello~1{name}/get/parameters/0/schema",
],
comparison: Input,
class: Trivial,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

@ahl ahl merged commit 2e0ac92 into main Dec 9, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants