Skip to content

fix(diff): compare MaxLength, not MinLength, in CheckStringTypeChanges - #253

Merged
fredbi merged 1 commit into
go-openapi:masterfrom
martel:fix-diff-maxlength
Oct 2, 2026
Merged

fredbi merged 1 commit into
go-openapi:masterfrom
martel:fix-diff-maxlength

Conversation

@martel

@martel martel commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Hi, I've discovered this bug and let my Claude take it, fix and post this PR. I have close to zero Go familiarity myself, but the fix looks very simple. Hope that's okay.

Problem

CheckStringTypeChanges in diff/checks.go passes the MinLength fields to the MaxLength comparison:

maxLengthDiffs := CompareIntValues("MaxLength", type1.MinLength, type2.MinLength, WidenedType, NarrowedType)

This has two effects on diff.Compare:

  • A change to minLength is reported twice, the second time labelled MaxLength. Adding minLength: 1, maxLength: 255 to a string property reports MinLength(1) and MaxLength(1) as AddedConstraint.
  • A change to maxLength alone is never reported. Narrowing maxLength from 1000 to 255 on a request body property produces no difference, so a breaking change passes swagger diff unflagged.

The line has been like this since swagger diff was added to go-swagger in go-swagger/go-swagger#1961 (cmd/swagger/commands/diff/spec_analyser.go). It moved to checks.go in 2020 and to this repository in go-swagger/go-swagger#3308 without changing. go-swagger v0.36.6 depends on analysis v1.0.0, which has the bug.

Fix

Pass type1.MaxLength, type2.MaxLength. The change codes stay the same: a larger maxLength is WidenedType, a smaller one is NarrowedType.

Tests

TestCheckStringTypeChanges is new; the function had no direct test. It covers maxLength added, removed, narrowed and widened, minLength and maxLength added together, and a minLength change with maxLength unchanged. All six cases fail on the old line and pass with the fix.

  • go test -race ./... and go test work pass.
  • golangci-lint run ./diff/... reports nothing on the changed lines. It reports 7 issues that predate this change: one gofumpt in spec_analyser.go:927 and six modernize hints on floatPointerOf / intPointerOf in checks_test.go.

CheckStringTypeChanges passed type1.MinLength and type2.MinLength to
the MaxLength comparison. diff.Compare reported every minLength change
a second time as MaxLength, and never reported a maxLength change, so
narrowing maxLength went unflagged.

Add TestCheckStringTypeChanges, which fails on the old line.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Mike Minicki <martel@post.pl>

@fredbi fredbi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah good catch

@martel
martel marked this pull request as ready for review October 2, 2026 19:38
@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.24%. Comparing base (f20e430) to head (1598990).
⚠️ Report is 7 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #253      +/-   ##
==========================================
+ Coverage   94.21%   94.24%   +0.02%     
==========================================
  Files          29       29              
  Lines        3404     3404              
==========================================
+ Hits         3207     3208       +1     
+ Misses        193      192       -1     
  Partials        4        4              

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

@fredbi
fredbi merged commit ba97125 into go-openapi:master Oct 2, 2026
25 of 26 checks passed
@fredbi

fredbi commented Oct 2, 2026

Copy link
Copy Markdown
Member

It shows the the instructions left to the agents in this repo are useful!

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.

2 participants