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

integer & number minimum (& maximum) don't allow a minimum of zero (or any negative numbers) #424

Closed
amp001 opened this issue Jan 19, 2024 · 6 comments

Comments

@amp001
Copy link

amp001 commented Jan 19, 2024

if *schema.Value.Minimum <= 0 {

I believe this is tripping up both integer and number schemas with a minimum: 0 qualifier. But, integers and numbers are both signed, so why restrict the minimum (and maximum, checked a few lines below this one) to being greater than 0? You should be able to have a minimum: -100 and a maximum: -50 if you want to.

@daveshanley
Copy link
Owner

will provide a patch to fix this today.

daveshanley added a commit that referenced this issue Jan 20, 2024
An off my one issue, I used the wrong comparitor and then did not build the correct tests required that would have caight it. This has now been fixed.

Signed-off-by: quobix <dave@quobix.com>
daveshanley added a commit that referenced this issue Jan 20, 2024
An off my one issue, I used the wrong comparitor and then did not build the correct tests required that would have caight it. This has now been fixed.

Signed-off-by: quobix <dave@quobix.com>
@daveshanley
Copy link
Owner

This is fixed in v0.8.1

@darrenspurgeon
Copy link

Hi, @daveshanley . The 0.8.1 fix works now a minimum: 0 by itself, yet I think (as @amp001 suggested) that the spec should allow for negative signed integers as well. The error is thrown for cases of minimum: -100 and maximum: -50. My spec has just such a use case where min and max are both negative.

Maybe one way to validate this is to take one or all of minimum, maximum, type, and format together. For example, make sure minimum < value < maximum alongside a signed (type: integer + format: int32). Not sure.

I hope I'm not off base on this. Thanks as always!

@amp001
Copy link
Author

amp001 commented Jan 21, 2024

Agreed @darrenspurgeon – minimum and maximum should both be numbers, and minimum should be less than maximum. Other than than, I suppose if the type is integer, they should both be integers, and if the format is int32, they should be within the range of -2,147,483,648 to 2,147,437 (-2^31 to 2^31 - 1) – similarly limited for int64. In Go, the constants for these should be available as math.MinInt32, math.MaxInt32, math.MinInt64, and math.MaxInt64.

But, other than that, I don't think I'd be overly strict on this aspect of schema definition.

@daveshanley
Copy link
Owner

Hi, I re-checked the spec, negative numbers are allowed for min/max. I will update the rule.

@daveshanley daveshanley reopened this Jan 22, 2024
daveshanley added a commit that referenced this issue Jan 24, 2024
Signed-off-by: quobix <dave@quobix.com>
@daveshanley daveshanley mentioned this issue Jan 24, 2024
daveshanley added a commit that referenced this issue Jan 24, 2024
Signed-off-by: quobix <dave@quobix.com>
@daveshanley
Copy link
Owner

resolved in v0.8.3

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

3 participants