Skip to content

Support minimum/maximum on quoted numerals  #171

Closed
@kosty

Description

@kosty

Context

As mentioned in #118 there is a "loose" mode support for numeric types. Although not part of the JSON spec, the likely reason for such mode is JavaScript's specification of number type which basically uses only 64bit double type, aka 64-bit format IEEE 754-2008. Motivated by issues resulting from this well known behavior some languages converged on using serialized/quoted form when serializing long, double and bigger values to JSON, for example protocol buffers

Since quoted numeric values are accepted with loose typing other JSON Schema validators should handle them as well.

This issue focuses on maximum and minimum validators at the moment.

Sample test

A json payload like this

"9223372036854775807"

should check out agains schema like these

case 1

{
    "$schema":"http://json-schema.org/draft-04/schema#",
    "type": "integer",
    "maximum": 9223372036854775807
}

case 2

{
    "$schema":"http://json-schema.org/draft-04/schema#",
    "type": "integer",
    "maximum": 1E+20
}

case 3

{
    "$schema":"http://json-schema.org/draft-04/schema#",
    "type": "number",
    "maximum": "9223372036854775807.0"
}

case 4

{
    "$schema":"http://json-schema.org/draft-04/schema#",
    "type": "number",
    "maximum": 922337203685477580700
}

Essentially either of integer/number types and any valid JSON number as maximum/minimum value (including quoted numeric type).

Edge case

Not clear if the following combination should trigger a maximum/minimum validators
json

"42"

schema

{
    "$schema":"http://json-schema.org/draft-04/schema#",
    "type": "string",
    "maximum": 100
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions