mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-22 03:00:10 +00:00
Add field name to all property errors
This commit is contained in:
parent
b66ec04ac2
commit
17ea740b7b
2 changed files with 17 additions and 4 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue