-
-
Notifications
You must be signed in to change notification settings - Fork 321
RFC7: add support for validator plugins #2396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -797,6 +797,28 @@ def manage_collection_item( | |
| HTTPStatus.BAD_REQUEST, headers, request.format, | ||
| 'InvalidParameterValue', msg) | ||
|
|
||
| if action in ['create', 'update']: | ||
| if p.validator is not None: | ||
| LOGGER.debug('Provider is configured for validation') | ||
| LOGGER.debug('Loading validator') | ||
| try: | ||
| v = load_plugin('validator', {'name': p.validator['name']}) | ||
| except Exception: | ||
| msg = 'Invalid validator configured' | ||
| return api.get_exception( | ||
| HTTPStatus.INTERNAL_SERVER_ERROR, headers, request.format, | ||
| 'NoApplicableCode', msg) | ||
|
|
||
| LOGGER.debug('Validating item') | ||
| try: | ||
| v.validate(request.data) | ||
| except Exception as err: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest to raise
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a non-JSON body crashes because |
||
| msg = err.user_msg or 'Item is not valid, please check and validate payload' # noqa | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validation details never reach the client, nor even the log line below |
||
| LOGGER.error(f'Validation errors: {err.message}') | ||
| return api.get_exception( | ||
| HTTPStatus.INTERNAL_SERVER_ERROR, headers, request.format, | ||
| 'InvalidParameterValue', msg) | ||
|
|
||
| if action == 'create': | ||
| LOGGER.debug('Creating item') | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON schema recompiles at each call, maybe we can cache the compiled schema?