Skip to content

Fix maxItems detection for array parameters (issue #760)#781

Merged
reuvenharrison merged 1 commit intomainfrom
fix/issue-760-maxitems-array-parameter
Jan 13, 2026
Merged

Fix maxItems detection for array parameters (issue #760)#781
reuvenharrison merged 1 commit intomainfrom
fix/issue-760-maxitems-array-parameter

Conversation

@reuvenharrison
Copy link
Collaborator

Summary

Fixes #760 - The oasdiff breaking command was not detecting when maxItems is decreased on array query parameters because the checker was looking in the wrong location in the schema structure.

Problem

When maxItems is set directly on an array parameter schema (the correct location per OpenAPI spec), the checker failed to detect changes. For example:

parameters:
  - name: ids
    in: query
    schema:
      type: array
      maxItems: 50  # <-- maxItems here (on the array schema)
      items:
        type: string

When maxItems changed from 50 to 10, oasdiff diff would report it, but oasdiff breaking would not flag it as a breaking change.

Root Cause

The checker was only looking for maxItems in paramDiff.SchemaDiff.ItemsDiff.MaxItemsDiff (on the items schema) but not in paramDiff.SchemaDiff.MaxItemsDiff (on the parameter schema itself).

This worked for a legacy pattern where maxItems was incorrectly placed on the items schema, but failed for the correct OpenAPI specification pattern.

Solution

Updated RequestParameterMaxItemsUpdatedCheck to check both locations:

  1. First: Check maxItems on the parameter schema itself (correct per spec)
  2. Fallback: Check maxItems on the items schema (for backward compatibility)

Changes

  • checker/check_request_parameters_max_items_updated.go: Updated logic to check both locations
  • checker/check_request_parameters_max_items_updated_test.go: Added TestRequestParameterArrayMaxItemsDecreased
  • data/checker/request_parameter_array_max_items_*.yaml: Added test fixtures

Testing

  • ✅ New test TestRequestParameterArrayMaxItemsDecreased passes
  • ✅ All existing maxItems tests pass
  • ✅ Full checker test suite passes

Test plan

  • Run maxItems tests: go test github.com/oasdiff/oasdiff/checker -run ".*MaxItems" -v
  • Run full checker suite: go test github.com/oasdiff/oasdiff/checker
  • Verify the fix resolves issue Decreasing maxItems not a breaking change? #760 scenario

🤖 Generated with Claude Code

Fixes #760

The checker was only looking for maxItems in the items schema
(paramDiff.SchemaDiff.ItemsDiff.MaxItemsDiff) but not on the
array parameter schema itself (paramDiff.SchemaDiff.MaxItemsDiff).

This caused the tool to miss breaking changes when maxItems was
set directly on an array parameter, which is the correct location
according to the OpenAPI specification.

The fix checks both locations:
1. First checks maxItems on the parameter schema itself (correct location)
2. Falls back to checking maxItems on items schema (legacy support)

Changes:
- Updated RequestParameterMaxItemsUpdatedCheck to check both locations
- Added test case TestRequestParameterArrayMaxItemsDecreased
- Added test fixtures for the new scenario

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Jan 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.73%. Comparing base (a24c8d5) to head (f3a3a61).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #781      +/-   ##
==========================================
+ Coverage   88.71%   88.73%   +0.01%     
==========================================
  Files         246      246              
  Lines       12142    12144       +2     
==========================================
+ Hits        10772    10776       +4     
+ Misses        931      930       -1     
+ Partials      439      438       -1     
Flag Coverage Δ
unittests 88.73% <100.00%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@reuvenharrison reuvenharrison merged commit 635bec4 into main Jan 13, 2026
14 checks passed
@reuvenharrison reuvenharrison deleted the fix/issue-760-maxitems-array-parameter branch January 13, 2026 08:29
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.

Decreasing maxItems not a breaking change?

2 participants