Validate an RPC response.
    The response must either take the
    form of the given schema, or it must
    take the form of {'error': ...}

    Returns the resp on success
    Returns {'error': ...} on validation error
550882
def json_validate(schema, resp):
    
    # is this an error?
    try:
        json_validate_error(resp)
    except ValidationError:
        if json_is_exception(resp):
            # got a traceback 
            if BLOCKSTACK_TEST:
                log.error('\n{}'.format(resp['traceback']))

            return {'error': 'Blockstack Core encountered an exception. See `traceback` for details', 'traceback': resp['traceback'], 'http_status': 500}

        if 'error' in resp and 'http_status' not in resp:
            # bad error message
            raise 

        # not an error.
        jsonschema.validate(resp, schema)

    return resp
777094
function validateEndpointData(
  data,
  { prettyErrorMessage = 'invalid response data', includeKeys = false } = {}
) {
  return validate(
    {
      ErrorClass: InvalidResponse,
      prettyErrorMessage,
      includeKeys,
      traceErrorMessage: 'Response did not match schema',
      traceSuccessMessage: 'Response after validation',
      allowAndStripUnknownKeys: false,
    },
    data,
    endpointSchema
  )
}
688635
def validate_status_code_to_response_definition(response, operation_definition):
    
    status_code = response.status_code
    operation_responses = {str(code): val for code, val
                           in operation_definition['responses'].items()}

    key = status_code
    if key not in operation_responses:
        key = 'default'

    try:
        response_definition = operation_responses[key]
    except KeyError:
        raise ValidationError(
            MESSAGES['response']['invalid_status_code'].format(
                status_code, ', '.join(operation_responses.keys()),
            ),
        )
    return response_definition
367163
def validate(self, data, schema, **kwargs):
        """"""
        if not isinstance(schema, dict):
            schema = {'$ref': schema}
        return validate(
            data,
            schema,
            resolver=self.ref_resolver_cls.from_schema(schema),
            types=self.app.config.get('RECORDS_VALIDATION_TYPES', {}),
            **kwargs
        )
685270
def _validate_example(rh, method, example_type):
    
    example = getattr(method, example_type + "_example")
    schema = getattr(method, example_type + "_schema")

    if example is None:
        return None

    try:
        validate(example, schema)
    except ValidationError as e:
        raise ValidationError(
            "{}_example for {}.{} could not be validated.\n{}".format(
                example_type, rh.__name__, method.__name__, str(e)
            )
        )

    return json.dumps(example, indent=4, sort_keys=True)
1038098
async def _query_validator(self, request_type, response_proto,
                               payload, error_traps=None):
        
        LOGGER.debug(
            'Sending %s request to validator',
            self._get_type_name(request_type))

        payload_bytes = payload.SerializeToString()
        response = await self._send_request(request_type, payload_bytes)
        content = self._parse_response(response_proto, response)

        LOGGER.debug(
            'Received %s response from validator with status %s',
            self._get_type_name(response.message_type),
            self._get_status_name(response_proto, content.status))

        self._check_status_errors(response_proto, content, error_traps)
        return self._message_to_dict(content)
724651
def validation_error_inform_error(err, data, schema):
    
    abort(Response(
        json.dumps({'error': str(err), 'data': data, 'schema': schema}),
        status=HTTPStatus.BAD_REQUEST))
1270837
def validate_parameters(cls, parameters, schema=None):
        
        if schema is None:
            schema = cls.get_parameters_schema()
        jsonschema.validate(parameters, schema)
1109485
def validate(self, data):
        
        validator = self._schema.validator(self._id)
        validator.validate(data)
1124618
def validate(response)
      case response.code
      when 400 then fail Error::BadRequest, error_message(response)
      when 401 then fail Error::Unauthorized, error_message(response)
      when 403 then fail Error::Forbidden, error_message(response)
      when 404 then fail Error::NotFound, error_message(response)
      when 405 then fail Error::MethodNotAllowed, error_message(response)
      when 409 then fail Error::Conflict, error_message(response)
      when 500 then fail Error::InternalServerError, error_message(response)
      when 502 then fail Error::BadGateway, error_message(response)
      when 503 then fail Error::ServiceUnavailable, error_message(response)
      end

      handle_response(response)
    end
819421
def handle_error(self, error, req, schema, error_status_code, error_headers):
        
        status_code = error_status_code or self.DEFAULT_VALIDATION_STATUS
        response = exception_response(
            status_code,
            detail=text_type(error),
            headers=error_headers,
            content_type="application/json",
        )
        body = json.dumps(error.messages)
        response.body = body.encode("utf-8") if isinstance(body, text_type) else body
        raise response
176761
function generateValidationFn(schema) {
        return function (req) {

            // if already an error, return without doing any additional validation
            if (req.error) { return req; }

            var keys = Object.keys(schema);
            var len = (req.value && req.value.trim().length) || 0;
            var i, key, originalKey;

            for (i = 0; i < keys.length; i++) {
                key = originalKey = keys[i];
                if (key.indexOf('ui-') === 0) {
                    key = key.substring(3);
                }

                // if validation function exists but it returns false then we have error
                if (check[key] && !check[key](schema, req.value)) {
                    var errMsg = schema[key + 'Desc'] || errorMessage[key] || 'Invalid input';
                    req.error = errMsg
                        .replace('{' + key + '}', schema[originalKey])
                        .replace('{value}', req.value)
                        .replace('{length}', len);
                    break;
                }
            }

            return req;
        };
    }
661686
def validate(self, export):
        
        target_url = self.client.get_url(self._URL_KEY, 'POST', 'validate')
        response_object = ExportValidationResponse()
        r = self.client.request('POST', target_url, json=export._serialize())
        return response_object._deserialize(r.json())
528755
def form_validation_response(self, e):
        
        resp = rc.BAD_REQUEST
        resp.write(' '+str(e.form.errors))
        return resp
1216444
def response_helper(self, response, **kwargs):
        
        self.resolve_schema(response)
        if "headers" in response:
            for header in response["headers"].values():
                self.resolve_schema(header)
        return response
1181610
def _validate_keyschema(self, schema, field, value):
        
        if isinstance(value, Mapping):
            validator = self._get_child_validator(
                document_crumb=field,
                schema_crumb=(field, 'keyschema'),
                schema=dict(((k, schema) for k in value.keys())))
            if not validator(dict(((k, k) for k in value.keys())),
                             normalize=False):
                self._drop_nodes_from_errorpaths(validator._errors,
                                                 [], [2, 4])
                self._error(field, errors.KEYSCHEMA, validator._errors)
412968
def _validate(self, data: Any, schema: AnyMapping) -> Any:
        
        try:
            return self.validate_func(schema, self._pure_data(data))
        except self.validation_error_class as err:
            logger.error(
                'Schema validation error',
                exc_info=True,
                extra={'schema': schema, 'schema_module': self.module})
            if self.error_class is None:
                raise
            raise self.make_error('Validation Error', error=err) from err