Skip to content

Commit 17ea740

Browse files
committed
Add field name to all property errors
1 parent b66ec04 commit 17ea740

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

openapi_core/schema/schemas/exceptions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ class UndefinedSchemaProperty(OpenAPISchemaError):
4747
def __str__(self):
4848
return "Extra unexpected properties found in schema: {0}".format(self.extra_props)
4949

50+
@attr.s
51+
class InvalidSchemaProperty(OpenAPISchemaError):
52+
property_name = attr.ib()
53+
original_exception = attr.ib()
54+
55+
def __str__(self):
56+
return "Invalid schema property {0}: {1}".format(self.property_name, self.original_exception)
5057

5158
@attr.s
5259
class MissingSchemaProperty(OpenAPISchemaError):

openapi_core/schema/schemas/models.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from openapi_core.schema.schemas.exceptions import (
1515
InvalidSchemaValue, UndefinedSchemaProperty, MissingSchemaProperty,
1616
OpenAPISchemaError, NoOneOfSchema, MultipleOneOfSchema, NoValidSchema,
17-
UndefinedItemsSchema, InvalidCustomFormatSchemaValue,
17+
UndefinedItemsSchema, InvalidCustomFormatSchemaValue, InvalidSchemaProperty,
1818
)
1919
from openapi_core.schema.schemas.util import (
2020
forcebool, format_date, format_datetime,
@@ -297,8 +297,11 @@ def _unmarshal_properties(self, value, one_of_schema=None,
297297
if not prop.nullable and not prop.default:
298298
continue
299299
prop_value = prop.default
300-
properties[prop_name] = prop.unmarshal(
301-
prop_value, custom_formatters=custom_formatters)
300+
try:
301+
properties[prop_name] = prop.unmarshal(
302+
prop_value, custom_formatters=custom_formatters)
303+
except OpenAPISchemaError as exc:
304+
raise InvalidSchemaProperty(prop_name, exc)
302305

303306
self._validate_properties(properties, one_of_schema=one_of_schema,
304307
custom_formatters=custom_formatters)
@@ -539,6 +542,9 @@ def _validate_properties(self, value, one_of_schema=None,
539542
if not prop.nullable and not prop.default:
540543
continue
541544
prop_value = prop.default
542-
prop.validate(prop_value, custom_formatters=custom_formatters)
545+
try:
546+
prop.validate(prop_value, custom_formatters=custom_formatters)
547+
except OpenAPISchemaError as exc:
548+
raise InvalidSchemaProperty(prop_name, original_exception=exc)
543549

544550
return True

0 commit comments

Comments
 (0)