Skip to content

Add boundary cases for integers #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hudlow
Copy link

@hudlow hudlow commented May 20, 2025

I certainly don't like all of these behaviors, but if we want truly consistent behavior across languages, we'll have to match the least-common-denominator behavior for JSON parsers (particularly ECMAScript's JSON.parse()).

@hudlow hudlow requested a review from a team as a code owner May 20, 2025 15:09
Comment on lines +26 to +30
{
"description": "a float with zero fractional part is an integer",
"data": 1.0,
"valid": true
},
Copy link
Author

Choose a reason for hiding this comment

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

Not sure why this wasn't included in draft3 already, but there might be a reason!

Comment on lines +26 to +30
{
"description": "a float with zero fractional part is an integer",
"data": 1.0,
"valid": true
},
Copy link
Author

@hudlow hudlow May 20, 2025

Choose a reason for hiding this comment

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

Not sure why this wasn't included in draft4 already, but there might be a reason!

Copy link
Member

Choose a reason for hiding this comment

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

draft4 and earlier have different integer semantics: in draft4, an integer is "A JSON number without a fraction or exponent part", therefore 1.0 is NOT an integer.

Copy link
Member

Choose a reason for hiding this comment

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

There ought to be a draft4 test for 1.0 not being an integer, but I only see one that confirms it is a number (but that's not sufficient because all integers are also numbers).

Copy link
Member

@karenetheridge karenetheridge left a comment

Choose a reason for hiding this comment

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

The "small and large float are integers" tests are not valid. You cannot make any assumptions about the architecture the tests are running on, and the expectation is that all integers, no matter the size, no matter whether they fit into the native integer size for your architecture, will still be treated as integers by JSON Schema.

Comment on lines +40 to +48
"description": "a small float whose non-zero fractional part is truncated in a binary64 float is an integer",
"data": 1.00000000000001,
"valid": true
},
{
"description": "a large float whose non-zero fractional part is truncated in a binary64 float is an integer",
"data": 9007199254740991.5,
"valid": true
},
Copy link
Member

Choose a reason for hiding this comment

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

@karenetheridge is correct. These are not integers. JSON Schema uses an object model based on the one defined by the JSON specification, RFC 8259, which does not put limits on numeric values. Range does not matter. See Core 6.2 and Validation 4.2.

We do already have some tests for extremely large numbers. They are in the optional folders as we recognize that they typically are not fully supported and are generally edge-case. An argument could be made that they should not be optional.

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.

3 participants