这是indexloc提供的服务,不要输入任何密码
Skip to content

fix: better integer validation checks #768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged

Conversation

danielgtaylor
Copy link
Owner

This adds an additional check for integers using math.Trunc(...) to try and fail earlier with a more reasonable error message for users passing in floating point values for integers.

Fixes #745. (not entirely, but it's an improvement)

@Copilot Copilot AI review requested due to automatic review settings March 17, 2025 16:38
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves integer validation by introducing an early check using math.Trunc to better handle cases when floating point values are mistakenly passed as integers.

  • Update the validation logic in validate.go to distinguish between integers and non-integer numbers.
  • Adjust test cases in validate_test.go to expect "expected integer" errors instead of "expected number."
  • Introduce a new error message constant in validation/messages.go to support the updated error messaging.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
validate.go Added checks for integer validation using math.Trunc and updated error messages accordingly
validate_test.go Updated test cases to reflect the new integer error message expectation
validation/messages.go Added a new error message constant for integer validation
Comments suppressed due to low confidence (1)

validate.go:431

  • [nitpick] Consider consolidating the error message logic for integer validation. Currently, the error message for non-matching types is added in two places; refactoring this could improve maintainability.
if s.Type == TypeInteger {

Copy link

codecov bot commented Mar 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.06%. Comparing base (5b6d56a) to head (21710f6).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #768   +/-   ##
=======================================
  Coverage   93.05%   93.06%           
=======================================
  Files          23       23           
  Lines        5254     5261    +7     
=======================================
+ Hits         4889     4896    +7     
  Misses        313      313           
  Partials       52       52           

☔ View full report in Codecov by Sentry.
📢 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.

@danielgtaylor danielgtaylor merged commit ad6a04a into main Mar 17, 2025
7 checks passed
@danielgtaylor danielgtaylor deleted the better-int-checks branch March 17, 2025 16:40
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.

Differentiate between integer and number in OpenAPI Schema Validation
1 participant