Skip to content

Conversation

Revolyssup
Copy link
Contributor

@Revolyssup Revolyssup commented May 8, 2025

Fixes #817

Following the suggestion here #817 (comment)

@@ -1643,7 +1644,10 @@ func (schema *Schema) visitJSONNumber(settings *schemaValidationSettings, value
if v := schema.MultipleOf; v != nil {
// "A numeric instance is valid only if division by this keyword's
// value results in an integer."
if bigFloat := big.NewFloat(value / *v); !bigFloat.IsInt() {
numParsed, _ := decimal128.Parse(fmt.Sprintf("%.10f", value))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going higher, example %.15f here will break test case like 19628.87
As using %.15f turns this to 19628.869999999989.... causing non zero remainder later. I think it's okay to lose a little precision here to have precision in the remainder.

@fenollp fenollp changed the title fix: replace bigfloat with decimal128 openapi3: replace bigfloat with decimal128 to fix rounding errors during validation May 9, 2025
@fenollp fenollp merged commit d4bdebd into getkin:master May 9, 2025
5 checks passed
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.

property described with multipleOf does not pass the validation
2 participants