Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions schema_salad/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ def validate_doc(schema_names, # type: Names
for r in roots:
success = validate.validate_ex(
r, item, loader.identifiers, strict,
foreign_properties=loader.foreign_properties, raise_ex=False)
foreign_properties=loader.foreign_properties,
raise_ex=False, skip_foreign_properties=loader.skip_schemas)
if success:
break

Expand All @@ -315,7 +316,7 @@ def validate_doc(schema_names, # type: Names
validate.validate_ex(
r, item, loader.identifiers, strict,
foreign_properties=loader.foreign_properties,
raise_ex=True)
raise_ex=True, skip_foreign_properties=loader.skip_schemas)
except validate.ClassValidationException as e:
errors = [sl.makeError(u"tried `%s` but\n%s" % (
name, validate.indent(str(e), nolead=False)))]
Expand Down
30 changes: 17 additions & 13 deletions schema_salad/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def validate_ex(expected_schema, # type: Schema
foreign_properties=None, # type: Set[Text]
raise_ex=True, # type: bool
strict_foreign_properties=False, # type: bool
logger=_logger # type: logging.Logger
logger=_logger, # type: logging.Logger
skip_foreign_properties=False # type: bool
):
# type: (...) -> bool
"""Determine if a python datum is an instance of a schema."""
Expand Down Expand Up @@ -181,7 +182,8 @@ def validate_ex(expected_schema, # type: Schema
foreign_properties=foreign_properties,
raise_ex=raise_ex,
strict_foreign_properties=strict_foreign_properties,
logger=logger):
logger=logger,
skip_foreign_properties=skip_foreign_properties):
return False
except ValidationException as v:
if raise_ex:
Expand All @@ -200,7 +202,7 @@ def validate_ex(expected_schema, # type: Schema
for s in expected_schema.schemas:
if validate_ex(s, datum, identifiers, strict=strict, raise_ex=False,
strict_foreign_properties=strict_foreign_properties,
logger=logger):
logger=logger, skip_foreign_properties=skip_foreign_properties):
return True

if not raise_ex:
Expand All @@ -225,7 +227,7 @@ def validate_ex(expected_schema, # type: Schema
foreign_properties=foreign_properties,
raise_ex=True,
strict_foreign_properties=strict_foreign_properties,
logger=logger)
logger=logger, skip_foreign_properties=skip_foreign_properties)
except ClassValidationException as e:
raise
except ValidationException as e:
Expand Down Expand Up @@ -282,7 +284,7 @@ def validate_ex(expected_schema, # type: Schema
foreign_properties=foreign_properties,
raise_ex=raise_ex,
strict_foreign_properties=strict_foreign_properties,
logger=logger):
logger=logger, skip_foreign_properties=skip_foreign_properties):
return False
except ValidationException as v:
if f.name not in datum:
Expand All @@ -304,14 +306,16 @@ def validate_ex(expected_schema, # type: Schema
return False
split = urllib.parse.urlsplit(d)
if split.scheme:
err = sl.makeError(u"unrecognized extension field `%s`%s."
" Did you include "
"a $schemas section?" % (
d, " and strict_foreign_properties is True" if strict_foreign_properties else ""))
if strict_foreign_properties:
errors.append(err)
else:
logger.warn(err)
if not skip_foreign_properties:
err = sl.makeError(u"unrecognized extension field `%s`%s."
" Did you include "
"a $schemas section?" % (
d, " and strict_foreign_properties is True" if strict_foreign_properties else ""))
if strict_foreign_properties:
errors.append(err)
else:
logger.warn(err)
logger.warn("foreign properties %s", foreign_properties)
else:
err = sl.makeError(u"invalid field `%s`, expected one of: %s" % (
d, ", ".join("'%s'" % fn.name for fn in expected_schema.fields)))
Expand Down