Ejemplo n.º 1
0
Archivo: app.py Proyecto: kennydo/medea
    def wrapped(*args, **kwargs):
        # TODO: Request validation
        if config['validate_requests']:
            validate_request(request)

        response = func(*args, **kwargs)

        if isinstance(response, tuple):
            response_body, status_code = response
        else:
            response_body, status_code = response, 200

        if config['validate_responses']:
            validate_response_dict(request.url_rule.rule, response_body, http_method=request.method, status_code=status_code)

        return jsonify(response_body), status_code
Ejemplo n.º 2
0
    def wrapped(*args, **kwargs):
        # TODO: Request validation
        if config['validate_requests']:
            try:
                validate_request(request)
            except JsonSchemaValidationError as ex:
                raise ValueError("Request did not validate: " + str(ex)) from None

        response = func(*args, **kwargs)

        if isinstance(response, tuple):
            response_body, status_code = response
        else:
            response_body, status_code = response, 200

        if config['validate_responses']:
            try:
                validate_response_dict(request.url_rule.rule, response_body, http_method=request.method, status_code=status_code)
            except JsonSchemaValidationError as ex:
                raise ValueError("Response did not validate: " + str(ex)) from None


        return jsonify(response_body), status_code