Open
Description
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.
This behaviour is defined by:
Related (I think) issue: #40
Failing Test Case
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 😄
Metadata
Metadata
Assignees
Labels
No labels