Skip to content

fix: compare numeric enum values numerically#1050

Merged
wolveix merged 2 commits into
mainfrom
fix/numeric-enum-validation
Jun 18, 2026
Merged

fix: compare numeric enum values numerically#1050
wolveix merged 2 commits into
mainfrom
fix/numeric-enum-validation

Conversation

@wolveix

@wolveix wolveix commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

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 as float64 while query/path params parse as int64. Tag-based enums are stored as float64 (via json.Unmarshal), so a single enum slice could never satisfy both paths.

Changes

  • Extract the numeric normalization already inlined in the type check into a shared toFloat64 helper (now also handling json.Number).
  • Compare integer/number enums numerically instead of by Go type. Non-numeric enums keep strict comparison.

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.

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

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (93b5a32) to head (829e46e).

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.
📢 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.

@wolveix
wolveix merged commit fd8148e into main Jun 18, 2026
7 checks passed
@wolveix
wolveix deleted the fix/numeric-enum-validation branch June 18, 2026 23:08
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.

Bug: integer enum on query/path parameters always fails validation when schema enum values are emitted as float64

1 participant