[6/11] Add gt/lt strict numeric comparison checkers - #229
Merged
Conversation
gte/lte cover inclusive bounds, but there was no strict-inequality equivalent, a common gap for users coming from other validators. - gt.go/lt.go mirror gte.go/lte.go exactly, including the CanInt/ CanUint/CanFloat handling from #193 and the ErrNotNumeric-preserving contract on a non-numeric field. - Registered in maker.go under "gt"/"lt". - Added ExclusiveMinimum/ExclusiveMaximum to the Schema struct (no existing field covered them) and mapped gt/lt to them in schema_maker.go, matching JSON Schema's exclusiveMinimum/ exclusiveMaximum keywords. - NOT_GT/NOT_LT messages added to all 23 locale files plus en-US. Along the way, spotted that NOT_LTE's message is byte-identical to NOT_GTE's across every single locale file -- a pre-existing copy-paste bug (lte's error says "cannot be less than" when it should say "cannot be greater than"), unrelated to this change and left alone here; worth a small dedicated fix later. - Documented in the README's checker table. Fixes #203 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #229 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 54 56 +2
Lines 983 1051 +68
=========================================
+ Hits 983 1051 +68 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Problem
gte/ltecover inclusive numeric bounds, but there's no strict-inequality equivalent — a common gap for users coming from validators that offer both.Fix
Add
gt/lt, mirroringgte.go/lte.goexactly, including theCanInt/CanUint/CanFloathandling from #193 and the non-numeric-field-panics contract:gt.go/lt.goregistered inmaker.gounder"gt"/"lt".ExclusiveMinimum/ExclusiveMaximumto theSchemastruct (nothing existing covered them) and mappedgt/ltto them inschema_maker.go, matching JSON Schema'sexclusiveMinimum/exclusiveMaximumkeywords.NOT_GT/NOT_LTmessages added to all 23 locale files plus en-US.Bonus find, not fixed here: while writing these messages I noticed
NOT_LTE's text is byte-identical toNOT_GTE's across every single locale file — a pre-existing copy-paste bug (lte's error currently says "cannot be less than X" when it should say "cannot be greater than X"). Left untouched since it's unrelated to this PR's scope; worth a small dedicated fix as a follow-up. Wrote correct, non-copy-pasted text for the newNOT_GT/NOT_LTmessages so this PR doesn't propagate the same mistake.Testing
gt_test.go/lt_test.go: value/boundary/error cases including an explicit "equal to bound is an error" test (the actual difference fromgte/lte), int/uint/float, non-string... non-numeric-field panic, bad-param panic.TestJSONSchemaGtLtExclusiveBoundsplus bad-param panic tests for the new schema makers.go vet,gosec,reviveclean.Fixes #203
Chain note: PR 6 of 11.
🤖 Generated with Claude Code
https://claude.ai/code/session_01FLdVmP5daHiknrTW4Geh2i