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

Multi type: number/null type validation fails #147

Closed
driv3r opened this issue Dec 8, 2020 · 5 comments · Fixed by #148
Closed

Multi type: number/null type validation fails #147

driv3r opened this issue Dec 8, 2020 · 5 comments · Fixed by #148

Comments

@driv3r
Copy link

driv3r commented Dec 8, 2020

Hi, I've encountered issue with validating numbers: example

Schema

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "properties": {
        "content_length": {
            "type": ["number", "null"]
        }
    }
}

Object for test

{
    "content_length": 42
}

when having those files under benches/number_* and running cli, I get

cargo run -- benches/number_schema.json -i benches/number_valid.json
    Finished dev [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/jsonschema benches/number_schema.json -i benches/number_valid.json`
benches/number_valid.json - INVALID. Errors:
1. '42' is not of types 'null', 'number'

But as far as I checked, this should be valid, at least by looking at https://github.com/Stranger6667/jsonschema-rs/blob/master/src/keywords/type_.rs#L54-L57 with my beginners rust knowledge.

Also when running against "type":["number"] everything looks as it's supposed to.

@driv3r driv3r changed the title Number/null type validation fails Multi type: number/null type validation fails Dec 8, 2020
@Stranger6667
Copy link
Owner

Hi! Thanks for reporting, I'll take a look :)

@Stranger6667
Copy link
Owner

Yes, it is a bug; the upstream test suite (at least the version used by this lib) does not include such cases. I'll work on a fix

@driv3r
Copy link
Author

driv3r commented Dec 8, 2020

@Stranger6667 this was fast! Kudos!

@Stranger6667
Copy link
Owner

@driv3r You're welcome! I will release the fix tomorrow :)

@Stranger6667
Copy link
Owner

Stranger6667 commented Dec 9, 2020

FYI @driv3r . There are still some issues regarding the comparison of two JSON values (#149) - but I plan to release a fix for this one and then make some refactorings & solve #149 in subsequent patches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants