fix(diff): compare MaxLength, not MinLength, in CheckStringTypeChanges - #253
Merged
Merged
Conversation
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>
martel
marked this pull request as ready for review
October 2, 2026 19:38
Codecov Report✅ All modified and coverable lines are covered by tests. 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. |
Member
|
It shows the the instructions left to the agents in this repo are useful! |
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.
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
CheckStringTypeChangesindiff/checks.gopasses theMinLengthfields to theMaxLengthcomparison:This has two effects on
diff.Compare:minLengthis reported twice, the second time labelledMaxLength. AddingminLength: 1, maxLength: 255to a string property reportsMinLength(1)andMaxLength(1)asAddedConstraint.maxLengthalone is never reported. NarrowingmaxLengthfrom 1000 to 255 on a request body property produces no difference, so a breaking change passesswagger diffunflagged.The line has been like this since
swagger diffwas added to go-swagger in go-swagger/go-swagger#1961 (cmd/swagger/commands/diff/spec_analyser.go). It moved tochecks.goin 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 largermaxLengthisWidenedType, a smaller one isNarrowedType.Tests
TestCheckStringTypeChangesis new; the function had no direct test. It coversmaxLengthadded, removed, narrowed and widened,minLengthandmaxLengthadded together, and aminLengthchange withmaxLengthunchanged. All six cases fail on the old line and pass with the fix.go test -race ./...andgo test workpass.golangci-lint run ./diff/...reports nothing on the changed lines. It reports 7 issues that predate this change: onegofumptinspec_analyser.go:927and sixmodernizehints onfloatPointerOf/intPointerOfinchecks_test.go.