fix: compare numeric enum values numerically#1050
Merged
Merged
Conversation
Enum validation used type-strict slices.Contains, but the runtime value type depends on its source: JSON bodies decode integers as float64 while query/path params parse as int64. Tag-based enums are stored as float64 (via json.Unmarshal), so an integer enum could never satisfy both paths - query/path params always failed with 'expected value to be one of'. Extract the numeric normalization already inlined in the type check into a shared toFloat64 helper (now also handling json.Number) and use it to compare integer/number enums numerically rather than by Go type. Non numeric enums keep strict comparison.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1050 +/- ##
==========================================
+ Coverage 93.15% 93.16% +0.01%
==========================================
Files 23 23
Lines 4906 4918 +12
==========================================
+ Hits 4570 4582 +12
Misses 272 272
Partials 64 64 ☔ 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.
Fixes #1044
Integer enums always failed validation for query/path parameters. The enum check used type-strict
slices.Contains, but the runtime value type depends on its source: JSON bodies decode integers asfloat64while query/path params parse asint64. Tag-based enums are stored asfloat64(viajson.Unmarshal), so a single enum slice could never satisfy both paths.Changes
toFloat64helper (now also handlingjson.Number).Tests
Added regression cases covering int64 values against float64-stored enums (tag-based and custom
Schema()), plus a negative guard. Verified they fail without the fix and pass with it. Full suite (789 tests) passes, vet clean.