We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
fields.Integer should produce a JSON schema with "type": "integer" as per https://json-schema.org/understanding-json-schema/reference/numeric.html?highlight=integer#integer . However, a schema with "type": "number", "format": "integer" is produced. The number docs do not mention integer as a format and AFAIK JSON schema validators will not perform the intended integer validation.
fields.Integer
"type": "integer"
"type": "number", "format": "integer"
number
integer
format
This behaviour is defined by:
marshmallow-jsonschema/marshmallow_jsonschema/base.py
Line 33 in 81f08af
Related (I think) issue: #40
diff --git a/tests/test_dump.py b/tests/test_dump.py index ee63cda..02a191c 100644 --- a/tests/test_dump.py +++ b/tests/test_dump.py @@ -1,10 +1,32 @@ import pytest +import jsonschema from marshmallow import Schema, fields, validate from marshmallow_jsonschema import JSONSchema, UnsupportedValueError + from . import UserSchema, validate_and_dump +class TestIntegerField: + class Foo(Schema): + bar = fields.Integer() + + def test_schema_type(self): + schema = JSONSchema().dump(self.Foo()) + bar_property = schema["definitions"]["Foo"]["properties"]["bar"] + + assert bar_property["type"] == "integer" + assert "format" not in bar_property + + def test_validation(self): + schema = JSONSchema().dump(self.Foo()) + + jsonschema.validate({"bar": 1}, schema) + + with pytest.raises(jsonschema.ValidationError): + jsonschema.validate({"bar": 1.1}, schema) + + def test_dump_schema(): schema = UserSchema()
I'm happy to submit a PR for this if an appropriate course of action is agreed upon 😄
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
fields.Integer
should produce a JSON schema with"type": "integer"
as per https://json-schema.org/understanding-json-schema/reference/numeric.html?highlight=integer#integer . However, a schema with"type": "number", "format": "integer"
is produced. Thenumber
docs do not mentioninteger
as aformat
and AFAIK JSON schema validators will not perform the intended integer validation.This behaviour is defined by:
marshmallow-jsonschema/marshmallow_jsonschema/base.py
Line 33 in 81f08af
Related (I think) issue: #40
Failing Test Case
I'm happy to submit a PR for this if an appropriate course of action is agreed upon 😄
The text was updated successfully, but these errors were encountered: