Skip to content
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

Fix multipleOf bugs #114

Merged
merged 9 commits into from
Nov 1, 2024
Merged

Conversation

bertramakers
Copy link
Contributor

@bertramakers bertramakers commented Oct 8, 2024

Follow-up to #113

I figured out how to fix the multipleOf validation without using the modulo operator which doesn't work when using a multipleOf value that is a float with decimals, caused by the modulo operator converting the multipleOf value to integer.

The new validation divides the value of the field by the multipleOf value (if not null). If the value is indeed a multiple of the multipleOf property, the result should always be a whole number. We can check this by comparing it to the same result but rounded.

@bertramakers
Copy link
Contributor Author

@tobyzerner as with the previous PR this would be useful to have in the openapi branch if approved, since we're currently using that one until the OpenAPI generator is finalized.

- `%d` casts the multipleOf to a whole number even if its a float with decimals
- `%f` would add unnecessary decimals, e.g. `0.01` would become `0.010000`
- `%s` maintains the same number of decimals, e.g. `0.01` stays `0.01`
@tobyzerner tobyzerner merged commit cc41c28 into tobyzerner:main Nov 1, 2024
2 of 3 checks passed
@tobyzerner
Copy link
Owner

Clever solution @bertramakers, thank you!

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.

2 participants