-
-
Notifications
You must be signed in to change notification settings - Fork 136
Fix number validator #134
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
Fix number validator #134
Conversation
Codecov Report
@@ Coverage Diff @@
## master #134 +/- ##
=======================================
Coverage 96.33% 96.33%
=======================================
Files 54 54
Lines 1474 1474
=======================================
Hits 1420 1420
Misses 54 54
Continue to review full report at Codecov.
|
The `integer_types` is always a tuple. When checking if an instance is a number it fails because it's doing a comparison against a tuple instead of real type. ➜ python -c "from six import integer_types;import sys;print(integer_types);print(sys.version)" (<type 'int'>, <type 'long'>) 2.7.16 (default, Apr 6 2019, 01:42:57) [GCC 8.3.0] ➜ python3 -c "from six import integer_types;import sys;print(integer_types);print(sys.version)" (<class 'int'>,) 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.3.0] And spec defines a number as both int and float https://swagger.io/docs/specification/data-models/data-types/#numbers so both validators need to support both types.
raise InvalidSchemaValue("Value {value} is not of type {type}", value, self.type) | ||
|
||
return float(value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm This should stay as Python representation for number is float.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenAPI has two numeric types, number and integer, where number includes both integer and floating-point numbers. An optional format keyword serves as a hint for the tools to use a specific numeric type:
Ah yeah you're right. We need format unmarshalling then.
Fix number validator
The
integer_types
is always a tuple. When checkingif an instance is a number it fails because it's doing a comparison against a tuple
instead of real type.
➜ python -c "from six import integer_types;import sys;print(integer_types);print(sys.version)"
(<type 'int'>, <type 'long'>)
2.7.16 (default, Apr 6 2019, 01:42:57)
[GCC 8.3.0]
➜ python3 -c "from six import integer_types;import sys;print(integer_types);print(sys.version)"
(<class 'int'>,)
3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0]
And spec defines a number as both int and float https://swagger.io/docs/specification/data-models/data-types/#numbers so both validators need to support both types.