You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my openapi file, I have one property that is described as follows:
Quantity:
type: number
maximum: 999999999.99
minimum: -999999999.99
multipleOf: 0.01
The problem is that not every value provided as Quantity passes validation.
This part of lib code seems to be responsible for random outcome: kin-openapi/openapi3/schema.go#L1508 as the division value/0.01 sometimes gives a rounded value (so it’s Int and it passes validation), but sometimes it gives decimal outcome and the validation returns an error.
Here are some examples of Quantity for which division by 0.01 returns Int, so the validation passes:
8.11
68.15
2130.46
5895083
And here are some examples of Quantity for which division by 0.01 returns non-Int, so the validation fails:
8.1
2.07
19628.87
323.39
40428.2
I believe some adjustments to this validation should be provided.
The text was updated successfully, but these errors were encountered:
Hello! Indeed IEEE floats seem to be getting in the way. https://pkg.go.dev/math/big#Rat should be used instead.
If you're down to open a PR with this fix as well as with regression tests, I'll gladly review it! Thanks
Indeed big.Rat usage is full of footguns. decimal is too short on precision for JSON (float64). decimal128 looks good enough to go with it!
We should keep that choice of lib hidden (to the API) so as to be able to switch to a future golang/std impl.
This means tweaking openapi3.Schema de-serialization of MinMax and MultipleOf, also json.Number.
If we can't manage this well we'll that'd just be a breaking change and new version.
Feel free to publish your attempts at this! I'll help :)
In my openapi file, I have one property that is described as follows:
The problem is that not every value provided as Quantity passes validation.
This part of lib code seems to be responsible for random outcome: kin-openapi/openapi3/schema.go#L1508 as the division value/0.01 sometimes gives a rounded value (so it’s Int and it passes validation), but sometimes it gives decimal outcome and the validation returns an error.
Here are some examples of Quantity for which division by 0.01 returns Int, so the validation passes:
8.11
68.15
2130.46
5895083
And here are some examples of Quantity for which division by 0.01 returns non-Int, so the validation fails:
8.1
2.07
19628.87
323.39
40428.2
I believe some adjustments to this validation should be provided.
The text was updated successfully, but these errors were encountered: