Linter problem with multipleOf (no-invalid-schema-examples rule)
Describe the bug The linter incorrectly flags a problem with a multipleOf that is valid in the rule no-invalid-schema-examples
To Reproduce Create an openapi definition and create a property like this:
foo:
format: float
multipleOf: 0.1
type: number
example: 98.8
Expected behavior This shouldn't cause any issue as 98.8 is a multipleOf 0.1
**Problem ** The linter gives this error message:
[1] specs\internal.json:20644:36 at #/components/schemas/queue-getStatus-v1-Response-mPayload/properties/dQueueSlapercent/example
Example value must conform to the schema: must be multiple of 0.1.
20642 | "multipleOf": 0.1,
20643 | "type": "number",
20644 | "example": 98.8
20645 | },
20646 | "a_objQueuemember": {
referenced from specs\internal.json:20639:41
Error was generated by the no-invalid-schema-examples rule.
OpenAPI definition 3.0.3
Redocly Version(s) npx @redocly/openapi-cli --version 1.0.0-beta.95
Node.js Version(s)
npm -v
8.13.1
Thanks in advance
Thanks for creating the issue. This most likely is coming from AJV and is related to the way JavaScript handles math operations for floating point numbers. See the discussion for additional context.
@tatomyr we can fix it easily by passing multipleOfPrecision: 6 to AJV options.
https://github.com/ajv-validator/ajv/commit/5f2cc30449d81a7d10148567f3f1ed038b00718e