redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Linter problem with multipleOf (no-invalid-schema-examples rule)

Open Herrick19 opened this issue 3 years ago • 2 comments

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

Herrick19 avatar Jul 06 '22 02:07 Herrick19

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 avatar Jul 07 '22 09:07 tatomyr

@tatomyr we can fix it easily by passing multipleOfPrecision: 6 to AJV options.

https://github.com/ajv-validator/ajv/commit/5f2cc30449d81a7d10148567f3f1ed038b00718e

RomanHotsiy avatar Jul 07 '22 09:07 RomanHotsiy