Skip to content
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

Should this be validated as integer #205

Open
trufanov-nok opened this issue Jan 23, 2025 · 1 comment
Open

Should this be validated as integer #205

trufanov-nok opened this issue Jan 23, 2025 · 1 comment

Comments

@trufanov-nok
Copy link

I has declared a type constraint:

        "graphId": {
          "type": "integer",
          "minimum": 1
        }

And was surprise to find the following violates it:
"graphId": 3658777115

The value is > Int32 but < UInt32

The "type": "numeric" works fine.
Should it be so?

@tristanpenman
Copy link
Owner

tristanpenman commented Jan 29, 2025

Hey @trufanov-nok, hopefully this answer reaches you at a time that it is still relevant.

To the best of my understanding, JSON Schema doesn't place any hard constraints on the range supported by the integer type. Therefore the actual range is going to depend on the JSON Parser being used, and maybe even the OS/compiler (e.g. 32-bit vs 64-bit).

To help explain this, here is the actual code that checks integer types (in validation_visitor.hpp):

case TypeConstraint::kInteger:
    valid = m_target.isInteger() || (!m_strictTypes && m_target.maybeInteger());
    break;

The call to m_target.isInteger() here is what determines whether a value is an integer. The isInteger() method is provided by the adapter, and for pretty much all adapter types, it just asks the underlying parser whether the value is an integer.

Hope this helps!

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

No branches or pull requests

2 participants