Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
goschtl committed Feb 28, 2024
1 parent 1c7365f commit a41a0e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/jsonschema_colander/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def get_options(self):
"title": self.label,
"description": self.description,
"missing": missing,
# "oid": self.name,
}
if len(self.validators) > 1:
options["validator"] = colander.All(*self.validators)
Expand Down
16 changes: 7 additions & 9 deletions src/jsonschema_colander/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __call__(self, node, value):
def node_json_traverser(node, stack):
if not stack:
return node
if children := getattr(node, 'children', None):
if children := getattr(node, "children", None):
name, stack = stack[0], stack[1:]
if isinstance(name, str):
for child in children:
Expand All @@ -57,18 +57,18 @@ def node_json_traverser(node, stack):
elif isinstance(name, int):
assert len(children) == 1
items = children[0]
assert items.name == 'items'
assert items.name == "items"
if not stack:
return node
return node_json_traverser(items, stack)

raise LookupError('Node not found')
raise LookupError("Node not found")


def node_json_error(error, node, stack):
if not stack:
return error
if children := getattr(node, 'children', None):
if children := getattr(node, "children", None):
name, stack = stack[0], stack[1:]
if isinstance(name, str):
for num, child in enumerate(children):
Expand All @@ -79,17 +79,15 @@ def node_json_error(error, node, stack):
elif isinstance(name, int):
assert len(children) == 1
items = children[0]
assert items.name == 'items'
assert items.name == "items"
if not stack:
return error
return node_json_error(error, items, stack)

raise LookupError('Node not found')

raise LookupError("Node not found")


class JS_Schema_Validator:

def __init__(self, key, jsonschema):
self.jsonschema = {"type": "object", key: jsonschema}

Expand All @@ -99,6 +97,6 @@ def __call__(self, node, value, **kwargs):
validate(value, self.jsonschema)
except ValidationError as e:
base_error = colander.Invalid(node)
error = node_json_error(base_error, node, list(e.path))
error = node_json_error(base_error, node, list(e.path) or e.validator_value)
error.msg = e.message
raise base_error

0 comments on commit a41a0e4

Please sign in to comment.