-
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 branch 'master' of github.com:fuhrysteve/marshmallow-jsonschema…
… into propertyOrder Conflicts: marshmallow_jsonschema/base.py tests/test_dump.py
- Loading branch information
Showing
8 changed files
with
419 additions
and
117 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
0.3.0 (2016-06-12) | ||
- add support for marshmallow validators (see #14) | ||
|
||
0.2.0 (2016-05-25) | ||
- add support for titles & descriptions in metadata |
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,19 @@ | ||
|
||
|
||
installcheck: | ||
pip install -U .[reco] | ||
pip install strict-rfc3339 jsonschema coveralls coverage | ||
|
||
check: | ||
py.test -v | ||
|
||
coverage: | ||
coverage erase | ||
coverage run --source marshmallow_jsonschema -m py.test -v | ||
coverage report -m | ||
|
||
pypitest: | ||
python setup.py sdist upload -r pypitest | ||
|
||
pypi: | ||
python setup.py sdist upload -r pypi |
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,106 @@ | ||
from marshmallow import fields | ||
|
||
|
||
def handle_length(schema, field, validator, parent_schema): | ||
"""Adds validation logic for ``marshmallow.validate.Length``, setting the | ||
values appropriately for ``fields.List``, ``fields.Nested``, and | ||
``fields.String``. | ||
Args: | ||
schema (dict): The original JSON schema we generated. This is what we | ||
want to post-process. | ||
field (fields.Field): The field that generated the original schema and | ||
who this post-processor belongs to. | ||
validator (marshmallow.validate.Length): The validator attached to the | ||
passed in field. | ||
parent_schema (marshmallow.Schema): The Schema instance that the field | ||
belongs to. | ||
Returns: | ||
dict: A, possibly, new JSON Schema that has been post processed and | ||
altered. | ||
Raises: | ||
ValueError: Raised if the `field` is something other than | ||
`fields.List`, `fields.Nested`, or `fields.String` | ||
""" | ||
if isinstance(field, fields.String): | ||
minKey = 'minLength' | ||
maxKey = 'maxLength' | ||
elif isinstance(field, (fields.List, fields.Nested)): | ||
minKey = 'minItems' | ||
maxKey = 'maxItems' | ||
else: | ||
raise ValueError("In order to set the Length validator for JSON " | ||
"schema, the field must be either a List or a String") | ||
|
||
if validator.min: | ||
schema[minKey] = validator.min | ||
|
||
if validator.max: | ||
schema[maxKey] = validator.max | ||
|
||
if validator.equal: | ||
schema[minKey] = validator.equal | ||
schema[maxKey] = validator.equal | ||
|
||
return schema | ||
|
||
|
||
def handle_one_of(schema, field, validator, parent_schema): | ||
"""Adds the validation logic for ``marshmallow.validate.OneOf`` by setting | ||
the JSONSchema `enum` property to the allowed choices in the validator. | ||
Args: | ||
schema (dict): The original JSON schema we generated. This is what we | ||
want to post-process. | ||
field (fields.Field): The field that generated the original schema and | ||
who this post-processor belongs to. | ||
validator (marshmallow.validate.OneOf): The validator attached to the | ||
passed in field. | ||
parent_schema (marshmallow.Schema): The Schema instance that the field | ||
belongs to. | ||
Returns: | ||
dict: A, possibly, new JSON Schema that has been post processed and | ||
altered. | ||
""" | ||
if validator.choices: | ||
schema['enum'] = validator.choices | ||
|
||
return schema | ||
|
||
|
||
def handle_range(schema, field, validator, parent_schema): | ||
"""Adds validation logic for ``marshmallow.validate.Range``, setting the | ||
values appropriately ``fields.Number`` and it's subclasses. | ||
Args: | ||
schema (dict): The original JSON schema we generated. This is what we | ||
want to post-process. | ||
field (fields.Field): The field that generated the original schema and | ||
who this post-processor belongs to. | ||
validator (marshmallow.validate.Length): The validator attached to the | ||
passed in field. | ||
parent_schema (marshmallow.Schema): The Schema instance that the field | ||
belongs to. | ||
Returns: | ||
dict: A, possibly, new JSON Schema that has been post processed and | ||
altered. | ||
""" | ||
if not isinstance(field, fields.Number): | ||
return schema | ||
|
||
if validator.min: | ||
schema['minimum'] = validator.min | ||
schema['exclusiveMinimum'] = True | ||
else: | ||
schema['minimum'] = 0 | ||
schema['exclusiveMinimum'] = False | ||
|
||
if validator.max: | ||
schema['maximum'] = validator.max | ||
schema['exclusiveMaximum'] = True | ||
|
||
return schema |
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
Oops, something went wrong.