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
Hapic raise not all error during the dump in the marshmallow processor.
Workaround with custom processor that is not perfect (does not "merge the dump and the load errors") :
importtypingfromhapicimportMarshmallowProcessorfromhapic.exceptionimportOutputValidationExceptionfromhapic.exceptionimportValidationExceptionfromhapic.processor.mainimportProcessValidationErrorfromhapic.processor.mainimportProcessorclassMyProcessor(MarshmallowProcessor):
"""Patched hapic processor that return error when dump data is not correct"""defdump(self, data: typing.Any) ->typing.Any:
""" Use schema to validate given data and return dumped data. If validation fail, raise InputValidationException :param data: data to validate and dump :return: dumped data """clean_data=self.clean_data(data)
dump=self.schema.dump(clean_data)
dump_data=dump.dataerrors=dump.errorsifnoterrors:
# Re-validate with dumped dataerrors=self.schema.load(dump_data).errorsiferrors:
raiseValidationException("Error when dumping: {}".format(str(errors)))
returndump_datadefdump_output(self, output_data: typing.Any) ->typing.Union[typing.Dict, typing.List]:
""" Dump output data and raise OutputValidationException if validation error :param output_data: output data to validate :return: given data """clean_data=self.clean_data(output_data)
dump=self.schema.dump(clean_data)
dump_data=dump.dataerrors=dump.errorsifnoterrors:
# Re-validate with dumped dataerrors=self.schema.load(dump_data).errorsiferrors:
raiseOutputValidationException("Error when validate input: {}".format(str(errors)))
returndump_datadefget_output_validation_error(self, data_to_validate: typing.Any) ->ProcessValidationError:
""" Return ProcessValidationError for given output data :param data_to_validate: output data to use :return: ProcessValidationError instance for given output data """clean_data=self.clean_data(data_to_validate)
dump=self.schema.dump(clean_data)
dump_data=dump.dataerrors=dump.errorsifnoterrors:
# Re-validate with dumped dataerrors=self.schema.load(dump_data).errorsreturnProcessValidationError(message="Validation error of output data", details=errors)
The text was updated successfully, but these errors were encountered:
Hapic raise not all error during the dump in the marshmallow processor.
Workaround with custom processor that is not perfect (does not "merge the dump and the load errors") :
The text was updated successfully, but these errors were encountered: