Open itsMGA opened 1 year ago
hi @itsMGA
validate_request
is just a shortcut for validation. Iteration over errors withiter_errors
is still available (although not documented) under validator class
from openapi_cote import V30RequestValidator
V30RequestValidator(spec).iter_errors(request)
Dear @p1c2u, thank you for this lib and responding to the question from @itsMGA. In our project we are iterating over the errors and want to return a list of validation errors with the response:
...
spec = Spec.from_file_path(settings.OPENAPI_LOCAL_SPEC_FILE)
openapi_request = FlaskOpenAPIRequest(flask.request)
errors = [str(error) for error in list(V31RequestValidator(spec).iter_errors(openapi_request))]
if len(errors) == 0:
return f(*args, **kwargs)
raise SchemaValidationException('Schema Validation Error:', errors)
...
Unfortunately the response has only one general entry:
{
"error": "Request body validation error"
}
Is it possible to get the list of specific errors, to give more details to the API-consumer?
Best regards! Ralf
It also seems like it only shows the first error!?
Suggested Behavior
In the depreciated version there was:
Existing fuctionality:
validate_request(request=request, spec=spec)
Only raises errors, no way of iterating through themWhy is this needed?
Errors do not need to be raised necessarily, there are cases when you would want to iterate and do actions for certain errors, gather information and so on
References
No response
Would you like to implement a feature?
No