You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the excellent library. I have a request. I'm currently getting error messages like the following for an invalid schema:
Traceback (most recent call last):
...
File ".../openapi_core/unmarshalling/schemas/unmarshallers.py", line 61, in validate
value, self.schema.type, schema_errors=errors)
openapi_core.unmarshalling.schemas.exceptions.InvalidSchemaValue: Value [{'id': 1, ...}] not valid for schema of type SchemaType.ARRAY: (<ValidationError: 'None for not nullable'>,)
This isn't very helpful, and it took me a while to figure out what was happening (I was running into OAI/OpenAPI-Specification#1368). I managed it by hacking on openapi-core in my venv and adding the following:
I understand that you probably don't want to raise an exception immediately since you'd only see the first error, but would it be possible to opt-in to this behavior, or at least surface up the more verbose error message, assuming jsonschema provides a way to access this?
The text was updated successfully, but these errors were encountered:
I find this code now works (note it uses structlog to log messages):
def _openapi_log_errors(message, function_name, validation_errors):
"""Log all validation errors in a way that can be addressed."""
for error_validation in validation_errors:
if len(error_validation.schema_errors) == 0:
# Catch when error does not have errors in schema_errors property.
# This should never happen.
logger.critical(
event=message,
value=error_validation.value
)
for schema_error in error_validation.schema_errors:
schema_absolute_path = ".".join(schema_error.absolute_path)
if len(schema_absolute_path) == 0:
schema_absolute_path = '.'
logger.error(
event=message,
function=function_name,
schema_error=schema_error.message,
schema_cause=schema_error.cause,
schema_validator=schema_error.validator,
schema_path=schema_absolute_path,
)
And here we get the result from our validation:
if len(request_validate_result.errors) > 0:
_openapi_log_errors(
message="openapi_request_validator failed",
function_name=func.__name__,
validation_errors=request_validate_result.errors
)
So after some pokeng around I feel this bug is resolved.
Thanks for the excellent library. I have a request. I'm currently getting error messages like the following for an invalid schema:
This isn't very helpful, and it took me a while to figure out what was happening (I was running into OAI/OpenAPI-Specification#1368). I managed it by hacking on openapi-core in my venv and adding the following:
which gave me a far more helpful:
I understand that you probably don't want to raise an exception immediately since you'd only see the first error, but would it be possible to opt-in to this behavior, or at least surface up the more verbose error message, assuming
jsonschema
provides a way to access this?The text was updated successfully, but these errors were encountered: