-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from atmo/draft7_support
JSON schema draft 7 support
- Loading branch information
Showing
13 changed files
with
355 additions
and
389 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class UnsupportedValueError(Exception): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
coverage>=4.5.3 | ||
jsonschema>=2.6.0 | ||
jsonschema>=3.0.1 | ||
pytest>=4.6.3 | ||
pytest-cov | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import pytest | ||
from marshmallow import Schema, fields | ||
|
||
from marshmallow_jsonschema import UnsupportedValueError, JSONSchema | ||
from marshmallow_jsonschema.compat import RAISE, INCLUDE, EXCLUDE | ||
from . import validate_and_dump | ||
|
||
|
||
def test_additional_properties_default(): | ||
class TestSchema(Schema): | ||
foo = fields.Integer() | ||
|
||
schema = TestSchema() | ||
|
||
dumped = validate_and_dump(schema) | ||
|
||
assert not dumped["definitions"]["TestSchema"]["additionalProperties"] | ||
|
||
|
||
@pytest.mark.parametrize("additional_properties_value", (False, True)) | ||
def test_additional_properties_from_meta(additional_properties_value): | ||
class TestSchema(Schema): | ||
class Meta: | ||
additional_properties = additional_properties_value | ||
|
||
foo = fields.Integer() | ||
|
||
schema = TestSchema() | ||
|
||
dumped = validate_and_dump(schema) | ||
|
||
assert ( | ||
dumped["definitions"]["TestSchema"]["additionalProperties"] | ||
== additional_properties_value | ||
) | ||
|
||
|
||
def test_additional_properties_invalid_value(): | ||
class TestSchema(Schema): | ||
class Meta: | ||
additional_properties = "foo" | ||
|
||
foo = fields.Integer() | ||
|
||
schema = TestSchema() | ||
json_schema = JSONSchema() | ||
|
||
with pytest.raises(UnsupportedValueError): | ||
json_schema.dump(schema) | ||
|
||
|
||
def test_additional_properties_nested_default(): | ||
class TestNestedSchema(Schema): | ||
foo = fields.Integer() | ||
|
||
class TestSchema(Schema): | ||
nested = fields.Nested(TestNestedSchema()) | ||
|
||
schema = TestSchema() | ||
|
||
dumped = validate_and_dump(schema) | ||
|
||
assert not dumped["definitions"]["TestSchema"]["additionalProperties"] | ||
|
||
|
||
@pytest.mark.parametrize("additional_properties_value", (False, True)) | ||
def test_additional_properties_from_nested_meta(additional_properties_value): | ||
class TestNestedSchema(Schema): | ||
class Meta: | ||
additional_properties = additional_properties_value | ||
|
||
foo = fields.Integer() | ||
|
||
class TestSchema(Schema): | ||
nested = fields.Nested(TestNestedSchema()) | ||
|
||
schema = TestSchema() | ||
|
||
dumped = validate_and_dump(schema) | ||
|
||
assert ( | ||
dumped["definitions"]["TestNestedSchema"]["additionalProperties"] | ||
== additional_properties_value | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"unknown_value, additional_properties", | ||
((RAISE, False), (INCLUDE, True), (EXCLUDE, False)), | ||
) | ||
def test_additional_properties_deduced(unknown_value, additional_properties): | ||
class TestSchema(Schema): | ||
class Meta: | ||
unknown = unknown_value | ||
|
||
foo = fields.Integer() | ||
|
||
schema = TestSchema() | ||
|
||
dumped = validate_and_dump(schema) | ||
|
||
assert ( | ||
dumped["definitions"]["TestSchema"]["additionalProperties"] | ||
== additional_properties | ||
) | ||
|
||
|
||
def test_additional_properties_unknown_invalid_value(): | ||
class TestSchema(Schema): | ||
class Meta: | ||
unknown = "foo" | ||
|
||
foo = fields.Integer() | ||
|
||
schema = TestSchema() | ||
json_schema = JSONSchema() | ||
|
||
with pytest.raises(UnsupportedValueError): | ||
json_schema.dump(schema) |
Oops, something went wrong.