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

Validate fails incorrectly for integer values #837

Open
tylergannon opened this issue Aug 29, 2024 · 0 comments
Open

Validate fails incorrectly for integer values #837

tylergannon opened this issue Aug 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@tylergannon
Copy link
Contributor

Your issue may already be reported!
Please search on the issue tracker before creating one.

Describe the bug
Validator fails on schema type "integer".

To Reproduce
Make a schema that contains an integer data type and then validate an object using that schema.

Expected behavior
Validation should pass

Additional context

Golang unmarshals all numbers as float64. The type check for data.(int) therefore fails.

What will succeed will be

	case jsonschema.Integer:
		if num, ok := data.(float64); ok {
			if num == float64(int64(num)) {
				return true
			}
		}
		if _, ok := data.(int); ok {
			return true // Just in case other versions of Golang support this
		}

I don't have the time to create a PR at this point so I've just copied your validate.go into my own codebase FTTB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant