Skip to content

Compare prefixItems by index - #1192

Open
reuvenharrison wants to merge 1 commit into
mainfrom
prefix-items-positional
Open

Compare prefixItems by index#1192
reuvenharrison wants to merge 1 commit into
mainfrom
prefix-items-positional

Conversation

@reuvenharrison

Copy link
Copy Markdown
Collaborator

Fixes #1180.

prefixItems is positional: the schema at index i validates the array element at index i. The diff compared it with getSubschemasDiff, which is built for allOf, anyOf and oneOf, where order carries no meaning, so it paired entries by $ref name, content and title. Under that matching, swapping two entries paired each with its identical twin on the other side and reported no change, when every position it touches now validates against a different schema. Inserting an entry at the front reported one addition while every later position changed type.

getPrefixItemsDiff pairs entry i on each side and diffs the pair; an entry past the end of the shorter list is an addition or a deletion at its index. The output type is unchanged, so the diff JSON keeps its shape, and the subschema walker already descends into modified prefixItems entries, so the property-level checks inherit per-position reporting with no checker change.

The three cases from the issue, after:

$ # reorder [string, integer] -> [integer, string]   (was: No changes detected)
error [request-property-type-changed] the `/prefixItems[subschema #1]/` request property `type` changed from `string` to `integer`
error [request-property-type-changed] the `/prefixItems[subschema #2]/` request property `type` changed from `integer` to `string`

$ # insert boolean at the front   (was: one addition, "subschema #1")
error [request-property-type-changed] the `/prefixItems[subschema #1]/` request property `type` changed from `string` to `boolean`
error [request-property-type-changed] the `/prefixItems[subschema #2]/` request property `type` changed from `integer` to `string`
info  [request-body-prefix-items-added] added `subschema #3` to the request body 'prefixItems' list

$ # append   (the case the old message described)
info  [request-body-prefix-items-added] added `subschema #3` to the request body 'prefixItems' list

getSubschemasDiff is untouched: it is correct for the unordered constructs it was built for.

The full suite passes with no other change, which says nothing had pinned the unordered behaviour; TestGetPrefixItemsDiff_Positional and TestRequestBodyPrefixItemsReordered pin the positional one.

Fixes #1180.

prefixItems is positional: the schema at index i validates the array
element at index i. The diff compared it with getSubschemasDiff, which
is built for allOf, anyOf and oneOf, where order carries no meaning, so
it paired entries by $ref name, content and title. Under that matching,
swapping two entries paired each with its identical twin on the other
side and reported no change, when every position it touches now
validates against a different schema. Inserting an entry at the front
reported one addition while every later position changed type.

getPrefixItemsDiff pairs entry i on each side and diffs the pair, so a
type change at a position is reported as a type change at that position;
an entry past the end of the shorter list is an addition or a deletion
at its index. The output type is unchanged, so the diff JSON keeps its
shape, and the subschema walker already descends into the modified
entries, so the property-level checks inherit per-position reporting
with no checker change:

    reorder [string, integer] -> [integer, string]
    error [request-property-type-changed] the `/prefixItems[subschema #1]/`
          request property `type` changed from `string` to `integer`
    error [request-property-type-changed] the `/prefixItems[subschema #2]/`
          request property `type` changed from `integer` to `string`

getSubschemasDiff is untouched: it is correct for the unordered
constructs it was built for.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QDvUFsg5nu1NBWQffErGDw
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.60%. Comparing base (c42a1a4) to head (47c9cf6).

Files with missing lines Patch % Lines
diff/prefix_items_diff.go 85.71% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1192      +/-   ##
==========================================
- Coverage   88.60%   88.60%   -0.01%     
==========================================
  Files         337      338       +1     
  Lines       15767    15781      +14     
==========================================
+ Hits        13970    13982      +12     
- Misses       1230     1231       +1     
- Partials      567      568       +1     
Flag Coverage Δ
unittests 88.60% <86.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

prefixItems is compared as an unordered set, so reordering entries reports no change

2 participants