Add field name to all property errors

This commit is contained in:
Domen Kožar 2018-09-12 17:43:31 +01:00
parent b66ec04ac2
commit 17ea740b7b
No known key found for this signature in database
GPG key ID: C2FFBCAFD2C24246
2 changed files with 17 additions and 4 deletions

View file

@ -47,6 +47,13 @@ class UndefinedSchemaProperty(OpenAPISchemaError):
def __str__(self):
return "Extra unexpected properties found in schema: {0}".format(self.extra_props)
@attr.s
class InvalidSchemaProperty(OpenAPISchemaError):
property_name = attr.ib()
original_exception = attr.ib()
def __str__(self):
return "Invalid schema property {0}: {1}".format(self.property_name, self.original_exception)
@attr.s
class MissingSchemaProperty(OpenAPISchemaError):

View file

@ -14,7 +14,7 @@ from openapi_core.schema.schemas.enums import SchemaFormat, SchemaType
from openapi_core.schema.schemas.exceptions import (
InvalidSchemaValue, UndefinedSchemaProperty, MissingSchemaProperty,
OpenAPISchemaError, NoOneOfSchema, MultipleOneOfSchema, NoValidSchema,
UndefinedItemsSchema, InvalidCustomFormatSchemaValue,
UndefinedItemsSchema, InvalidCustomFormatSchemaValue, InvalidSchemaProperty,
)
from openapi_core.schema.schemas.util import (
forcebool, format_date, format_datetime,
@ -297,8 +297,11 @@ class Schema(object):
if not prop.nullable and not prop.default:
continue
prop_value = prop.default
properties[prop_name] = prop.unmarshal(
prop_value, custom_formatters=custom_formatters)
try:
properties[prop_name] = prop.unmarshal(
prop_value, custom_formatters=custom_formatters)
except OpenAPISchemaError as exc:
raise InvalidSchemaProperty(prop_name, exc)
self._validate_properties(properties, one_of_schema=one_of_schema,
custom_formatters=custom_formatters)
@ -539,6 +542,9 @@ class Schema(object):
if not prop.nullable and not prop.default:
continue
prop_value = prop.default
prop.validate(prop_value, custom_formatters=custom_formatters)
try:
prop.validate(prop_value, custom_formatters=custom_formatters)
except OpenAPISchemaError as exc:
raise InvalidSchemaProperty(prop_name, original_exception=exc)
return True