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

feat(type): support additional number types #72

Merged
merged 1 commit into from
Jul 23, 2020

Conversation

saracen
Copy link
Contributor

@saracen saracen commented Jun 29, 2020

At present, only Go float64 types are supported. Validating an integer in an interface{} of an unsupported number type currently displays an "unknown" type error.

This adds support for additional Go numeric types: uint, ints and float32s and converts them to float64's where comparisons are performed.

This is useful for cases where the interface was marshalled with an alternative json library, or in my case a yaml library, that uses ints instead of floats where it can. This also allows jsonschema to be used more generically against other interfaces.

@saracen saracen marked this pull request as draft July 1, 2020 01:45
@saracen
Copy link
Contributor Author

saracen commented Jul 1, 2020

Moving this to draft status, as I realised what I've added so far only solves one half of the problem.

At present, only Go float64 types are supported. Validating an integer in an
interface{} of another type currently displays an "unknown" type error.

This adds support for additional Go numeric types: uint, ints and float32s,
and converts them to float64s where required.
@saracen saracen marked this pull request as ready for review July 1, 2020 20:54
@saracen
Copy link
Contributor Author

saracen commented Jul 1, 2020

This is hopefully now ready for review.

I changed %f to %v for printing the float values in the error reports. Although the Go type is always a float, the error message can be confusing in instances where the schema requires an integer but the error returns something like: 5.0 must be less than 4.0.

@Arqu
Copy link
Contributor

Arqu commented Jul 23, 2020

Brilliant, thank you.

@Arqu Arqu merged commit 9874480 into qri-io:master Jul 23, 2020
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.

2 participants