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

"minimum" validation error message is somewhat confusing #247

Closed
jinfengnarvar opened this issue Jun 12, 2019 · 1 comment
Closed

"minimum" validation error message is somewhat confusing #247

jinfengnarvar opened this issue Jun 12, 2019 · 1 comment
Labels

Comments

@jinfengnarvar
Copy link

version: github.com/xeipuuv/gojsonschema v1.1.0

schema:

                "x": {
                    "type": "integer",
                    "minimum": 0
                },

json:

                "x": -1

The error msg: .... x: Must be greater than or equal to 0/1'.

I suspect the issue comes from this line:

err.SetDescription(formatErrorDescription(err.DescriptionFormat(), details))

Where in this case details is of map[string]*big.Rat and its a is initialized to nil and b is initialized to nil as well. Reading big.Rat's doc seems like when b is nil, it will string() into 1.

This is true if minimum is set to 1, or any other number. The error msg will be: x: Must be greater than or equal to <whatever the min>/1'.

The trailing /1 is very confusing.

@johandorland
Copy link
Collaborator

Internally the numbers are stored as big.Rat, which allows for infinite precision which prevents rounding errors when using multipleOf. However in the output they should've been converted to big.Float which would automatically have the proper string representation in the output (without the ugly /1). However there are a few places where I forgot to do that conversion in #224.

The fix itself looks rather easy, but now that I'm looking at it there are a few more number related things I want to take a look at before merging a fix.

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

No branches or pull requests

2 participants