Skip to content

Commit

Permalink
Merge pull request #53 from OpenDataServices/26-extend-jsonschema
Browse files Browse the repository at this point in the history
processor.cove: Extend jsonschema validation with our own functions
  • Loading branch information
michaelwood committed Mar 2, 2021
2 parents 8506f87 + 665a255 commit d8cc5f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions standards_lab/processor/cove.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from libcove.lib.common import (
common_checks_context,
SchemaJsonMixin,
validator,
)

from decimal import Decimal
Expand All @@ -13,6 +14,11 @@
from rq.job import Job
from rq.exceptions import NoSuchJobError

from .extra_validator_funcs import patch_validator


patch_validator(validator)


def start(project):
schema_name = project["rootSchema"]
Expand Down
14 changes: 14 additions & 0 deletions standards_lab/processor/extra_validator_funcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from jsonschema.exceptions import ValidationError


def startswith(validator, schema_value, instance, schema_parent_value):
if not isinstance(instance, str):
return
if not instance.startswith(schema_value):
yield ValidationError("Should start with '{}'".format(schema_value))


def patch_validator(validator):
validator.VALIDATORS.update({
"startswith": startswith
})

0 comments on commit d8cc5f7

Please sign in to comment.