Skip to content

Fix multipleOf bugs in Number type #113

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

Closed
wants to merge 2 commits into from

Conversation

bertramakers
Copy link
Contributor

@bertramakers bertramakers commented Oct 7, 2024

Fixes the multipleOf validation crashing when trying to use the modulo operator on a value that is zero, and an InvalidArgumentException when calling multipleOf() with null to reset it.

Edit: To clarify, 0 is considered to be a multiple of any multipleOf value by JSON schema, see for example https://www.jsonschemavalidator.net/s/lPabCUQd. This is also confirmed on https://www.learnjsonschema.com/2020-12/validation/multipleof/ (See examples: "Valid - 0 is a multiple of 4.1")

bertramakers and others added 2 commits October 7, 2024 16:19
Fixes the multipleOf validation crashing when trying to use the modulo operator on a value that is zero, and an InvalidArgumentException when calling multipleOf() with `null` to reset it
@bertramakers
Copy link
Contributor Author

@tobyzerner It would be useful if this could also be merged into the openapi branch once approved, since we're using that for now until the OpenAPI generator is finished.

@bertramakers
Copy link
Contributor Author

bertramakers commented Oct 7, 2024

Closing this because the issue I was having was actually that the modulo operator (%) doesn't support floats as a divider, while I was using 0.01 as multipleOf. I tried fixing this by using fmod() instead but because 0.01 is hard to represent accurately as a floating point number it doesn't work as expected. So I'm closing this since it doesn't solve the original issue and I will have to use a workaround that is not generic enough to implement in this class since it will be specific to some of our types where the multipleOf is 0.01 specifically. Nevertheless it's an interesting edge case that could benefit from some more investigation down the line I think.

Example: https://onlinephp.io/?s=s7EvyCjg5eLlKkssik8pzS3QSMvNT9EwNDDQUTDQM9TUtAYA&v=8.0.28

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.

1 participant