Skip to content

Fix compatibility issues with jsonschema>=4 #364

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

Merged
merged 12 commits into from
Oct 14, 2022
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Jinja2
slack-sdk
boto
premailer
jsonschema[format]==3.2.0
jsonschema[format]==4.0.0
schematics==2.1.0
python-slugify
scrapy
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
package_data={"spidermon": ["VERSION"]},
zip_safe=False,
include_package_data=True,
install_requires=["jsonschema[format]==3.2.0", "python-slugify"],
install_requires=["jsonschema[format]==4.0.0", "python-slugify"],
tests_require=test_requirements,
extras_require={
# Specific monitors and tools to support notifications and reports
Expand Down
5 changes: 2 additions & 3 deletions spidermon/contrib/validation/jsonschema/formats.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from jsonschema._format import FormatChecker, _checks_drafts
from jsonschema.compat import str_types

from spidermon.contrib.validation.utils import is_valid_url, is_valid_email


@_checks_drafts("url")
def is_url(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return is_valid_url(instance)


@_checks_drafts("email")
def is_email(instance):
if not isinstance(instance, str_types):
if not isinstance(instance, str):
return True
return is_valid_email(instance)

Expand Down
2 changes: 1 addition & 1 deletion spidermon/contrib/validation/jsonschema/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class JSONSchemaMessageTranslator(MessageTranslator):
r"^.* is less than the minimum of .*$": messages.NUMBER_TOO_LOW,
r"^.* is less than or equal to the minimum of .*$": messages.NUMBER_TOO_LOW,
r"^.* is not a multiple of .*$": messages.NOT_MULTIPLE_OF,
r"^.* is not allowed for .*$": messages.NOT_ALLOWED_VALUE,
r"^.* should not be valid under .*$": messages.NOT_ALLOWED_VALUE,
r"^.+ is too short$": messages.FIELD_TOO_SHORT,
r"^.+ is too long$": messages.FIELD_TOO_LONG,
r"^.+ does not match .*$": messages.REGEX_NOT_MATCHED,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_validators_jsonschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def __init__(self, name, data, valid, expected_errors=None, schema=None):
self.valid = valid
self.expected_errors = expected_errors or {}
self.schema = schema
if isinstance(self.schema, dict) and not self.schema.get("$schema"):
self.schema["$schema"] = "http://json-schema.org/draft-07/schema#"


class AdditionalItems(SchemaTest):
Expand Down Expand Up @@ -638,6 +640,7 @@ class Format(SchemaTest):
),
DataTest(
name="hostname. valid",
schema={"$schema": "http://json-schema.org/draft-04/schema"},
data={
"hostnames": [
"localhost",
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[tox]
envlist = py36,py37,py38,py39,py310
envlist = py{3.6,3.7,3.8,3.9}-jsonschema4
skip_missing_interpreters = True

[testenv]
deps =
jsonschema4: jsonschema>=4.0.0,<5.0.0
extras =
tests
validation
Expand Down