Ejemplo n.º 1
0
    def validate_schema(self, data, url):
        if self.is_null_value_valid and is_null(data):
            return None

        try:
            print(data)
            self.validator.validate(data)
        except ValidationError as exception:
            print("{url} validation error: {error}".format(url=url,
                                                           error=exception))
            return problem(400, "Bad Request", str(exception))

        return None
Ejemplo n.º 2
0
    def validate_schema(self, data, url):
        # type: (dict, AnyStr) -> Union[ConnexionResponse, None]
        if self.is_null_value_valid and is_null(data):
            return None
        try:
            self.validator.validate(data)
        except JsonSchemaValidationError as exception:
            # Add field name to the error response
            exception_field = ''
            for i in exception.path:
                exception_field = i + ': '
            if exception.__cause__ is not None:
                exception_message = str(exception.__cause__.message) + ' ' + exception_field + str(exception.message)
            else:
                exception_message = exception_field + str(exception.message)
            logger.error("{url} validation error: {error}".
                         format(url=url, error=exception_message))
            return problem(400, 'Bad Request', exception_message)

        return None
Ejemplo n.º 3
0
    def validate_schema(self, data, url):
        # type: (dict, AnyStr) -> Union[ConnexionResponse, None]
        if self.is_null_value_valid and is_null(data):
            return None
        try:
            self.validator.validate(data)
        except JsonSchemaValidationError as exception:
            # Add field name to the error response
            exception_field = ''
            for i in exception.path:
                exception_field = i + ': '
            if exception.__cause__ is not None:
                exception_message = str(exception.__cause__.message) + ' ' + exception_field + str(exception.message)
            else:
                exception_message = exception_field + str(exception.message)
            logger.error("{url} validation error: {error}".
                         format(url=url, error=exception_message))
            return problem(400, 'Bad Request', exception_message)

        return None
Ejemplo n.º 4
0
    def validate_schema(self, data, url):
        # type: (dict, AnyStr) -> Union[ConnexionResponse, None]
        if self.is_null_value_valid and is_null(data):
            return None
        try:
            self.validator.validate(data)
        except jsonschema.ValidationError as exception:
            # Add field name to the error response
            exception_field = ""
            for i in exception.path:
                exception_field = i + ": "
            if exception.__cause__ is not None:
                exception_message = exception.__cause__.message + " " + exception_field + exception.message
            else:
                exception_message = exception_field + exception.message
            # Some exceptions could contain unicode characters - if we don't replace them
            # we could end up with a UnicodeEncodeError.
            logger.error("{url} validation error: {error}".format(url=url, error=exception_message.encode("utf-8", "replace")))
            return problem(400, "Bad Request", exception_message)

        return None
Ejemplo n.º 5
0
    def validate_schema(self, data, url):
        if self.is_null_value_valid and is_null(data):
            return None

        try:
            self.validator.validate(data)
        except ValidationError as exception:
            if hasattr(config,
                       "DEBUG_LOGGING") and config.DEBUG_LOGGING is True:
                logging.info(
                    f"{url} validation error: {exception.message}",
                    extra={"validator": "body"},
                )
            else:
                logging.error(
                    f"{url} validation error: {exception.message}",
                    extra={"validator": "body"},
                )

            raise BadRequestProblem(title="Bad Request",
                                    detail=exception.message)

        return None
Ejemplo n.º 6
0
def validate_schema(self, data, url):
    # type: (dict, AnyStr) -> Union[ConnexionResponse, None]
    """
    @Override default RequestBodyValidator validate_schema. Only used to edit return String.
    @param self:
    @param data:
    @param url:
    @return:
    """
    if self.is_null_value_valid and is_null(data):
        return None

    try:
        self.validator.validate(data)
    except ValidationError as exception:
        logging.error("{url} validation error: {error}".format(
            url=url, error=exception.message),
                      extra={'validator': 'body'})
        return problem(400,
                       'Bad Request',
                       'Some data is missing or incorrect',
                       type='Validation')

    return None
Ejemplo n.º 7
0
    def validate_schema(self, data, url):
        """This function is largely based on https://github.com/zalando/connexion/blob/master/connexion/decorators/validation.py
        and should largely be kept in line with it."""
        # type: (dict, AnyStr) -> Union[ConnexionResponse, None]
        if self.is_null_value_valid and is_null(data):
            return None
        try:
            self.validator.validate(data)
        except jsonschema.ValidationError as exception:
            # Add field name to the error response
            exception_field = ""
            for i in exception.path:
                exception_field = i + ": "
            if exception.__cause__ is not None:
                exception_message = exception.__cause__.message + " " + exception_field + exception.message
            else:
                exception_message = exception_field + exception.message
            # Some exceptions could contain unicode characters - if we don't replace them
            # we could end up with a UnicodeEncodeError.
            logger.error("{url} validation error: {error}".format(
                url=url, error=exception_message.encode("utf-8", "replace")))
            raise BadRequestProblem(detail=exception_message)

        return None