question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

multipleOf validation fails when the value is fractional

See original GitHub issue

Describe the bug

Given an openAPI spec that contains validation of multipleOf: 0.1 for a double type, there are several valid values for which the validation fails, and therefor the API request is not sent.

To Reproduce

Steps to reproduce the behavior:

  1. Use autorest to generate a typescript client with the following type contained
  2. Attempt to call the API with a value of 2.0
  3. Observe that the validation fails and the command is not sent
       fractionalValue:
          type: number
          format: double
          minimum: 0
          maximum: 100
          multipleOf: 0.1
          example: 0.1

Expected behavior

For a multipleOf value of 0.1, all of the following values (and others) should be valid:

  • 0.1
  • 0.2
  • 1
  • 2

Additional context

I believe this may be resolved by changing line 57 of https://github.com/Azure/ms-rest-js/blob/45f89c90414db812e4950185ffe7f9f6becb5664/lib/serializer.ts to use an epsilon value of MultipleOf when the type is double.

This may include false positives that I have not considered. However, for client-side validation false positives are expected, since the client does not have full context, and will rely on server validation in other scenarios.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
sarangan12commented, May 19, 2022

I have sent a note to the Autorest crew abount these validations and based on their input, I will decide on removing the constraints.

1reaction
sarangan12commented, May 31, 2022

Removed the constraints check. Closing this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Float precision errors with multipleOf · Issue #187 - GitHub
From the multipleOf JSON schema specification: The value of "multipleOf" MUST be a JSON number. This number MUST be strictly greater than 0....
Read more >
Symfony 2.8: Percent form field validation incorrect for fractions
When I try to save a Symfony 2.8 form field of type "percent" with a fractional value, the validation returns. This value should...
Read more >
defining a numeric type that allows up to 2 decimal places
Is there an alternative way to define a numeric type which will only allow a maximum of 2 decimal places?
Read more >
Simple decimals fail to pass validation [#2230909] | Drupal.org
Problem/Motivation - Create decimal field, set precision to 10 (minimum in the UI and scale to 4 - Saving new node with value...
Read more >
21.1 Using Bean Validation Constraints
The Bean Validation model is supported by constraints in the form of annotations placed on a field, ... @Digits(integer=6, fraction=2) BigDecimal price;.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found