Skip to content

Commit

Permalink
Move schema validation error message creation to its own function (#1360
Browse files Browse the repository at this point in the history
)

* RequestBodyValidator schema validation error message creation moved to function

* RequestBodyValidator._error_path_message is now private method - no need to update public api

Co-authored-by: andrej_virgovic <andrej.virgovic@pantheon.tech>
Co-authored-by: Robbe Sneyders <robbe.sneyders@ml6.eu>
  • Loading branch information
3 people authored Jul 8, 2021
1 parent c014299 commit e57e72b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions connexion/decorators/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ def wrapper(request):

return wrapper

@classmethod
def _error_path_message(cls, exception):
error_path = '.'.join(str(item) for item in exception.path)
error_path_msg = f" - '{error_path}'" if error_path else ""
return error_path_msg

def validate_schema(self, data, url):
# type: (dict, AnyStr) -> Union[ConnexionResponse, None]
if self.is_null_value_valid and is_null(data):
Expand All @@ -199,9 +205,7 @@ def validate_schema(self, data, url):
try:
self.validator.validate(data)
except ValidationError as exception:
error_path = '.'.join(str(item) for item in exception.path)
error_path_msg = f" - '{error_path}'" \
if error_path else ""
error_path_msg = self._error_path_message(exception=exception)
logger.error(
"{url} validation error: {error}{error_path_msg}".format(
url=url, error=exception.message,
Expand Down

0 comments on commit e57e72b

Please sign in to comment.