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

Type defined as string gets rejects a string integer #475

Open
andykoch opened this issue Nov 18, 2022 · 1 comment
Open

Type defined as string gets rejects a string integer #475

andykoch opened this issue Nov 18, 2022 · 1 comment

Comments

@andykoch
Copy link

andykoch commented Nov 18, 2022

I would expect a string that is just a number to pass validation as a string.

 JSON::Validator.fully_validate({type: "string"}, "123")
=> ["The property '#/' of type integer did not match the following type: string in schema"]
 JSON::Validator.fully_validate({type: "string"}, "123-Foo")
=> []

When I use the same schema and value in a third party validator, it passes fine.

According to the json schema specs: https://json-schema.org/understanding-json-schema/reference/string.html#string

image

@andykoch
Copy link
Author

I dug into the source and discovered the string was getting JSON.parse() called on it, which returns integer 123. To address that I appended a to_json.

JSON::Validator.fully_validate({type: "string"}, "123".to_json)

"123".to_json returns "\"123\""

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

1 participant