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

Some numbers are generated as strings when using multipleOf with exponential notation #748

Open
michaelmior opened this issue Mar 2, 2023 · 4 comments

Comments

@michaelmior
Copy link
Contributor

michaelmior commented Mar 2, 2023

Schema

{
  "type": "number",
  "multipleOf": 1e-8,
  "minimum": 0,
  "maximum": 1
}

Generated JSON

"2e-8"

I expect that this would generate a valid number, instead of a string.

@michaelmior
Copy link
Contributor Author

I see that the number generator uses toExponential, which explicitly converts results to a string. There seems to be some attempt to perform special handling of multipleOf less than 1, but it seems to be broken.

@michaelmior
Copy link
Contributor Author

michaelmior commented Mar 2, 2023

On further investigation, it seems like there is a related bug with is-my-json-valid.

$ node
> const validator = require('is-my-json-valid')
> validator({"type": "number", "multipleOf": 1e-8, "maximum": 1000000000})(736329017)
false

736329017 is indeed a valid multiple of 1e-8.

Update: It is a known issue. See mafintosh/is-my-json-valid#192.

@pateketrueke
Copy link
Member

Very nice issue! I think this would take more time as we need to investigate it properly.

@michaelmior
Copy link
Contributor Author

michaelmior commented Mar 2, 2023

@pateketrueke I tried removing the call to toExponential, which solved this bug but then introduced another failure because of the bug in is-my-json-valid. I think removing toExponential may be the correct fix once the is-my-json-valid bug is also fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants