Try and recursively iterate a JSON schema and to generate an ES mapping
    that encasulates it.
512692
def generate_schema_mapping(resolver, schema_uri, depth=1):
    
    visitor = SchemaVisitor({'$ref': schema_uri}, resolver)
    return _generate_schema_mapping(visitor, set(), depth)
118228
def data2schemacls(_data, **kwargs):
    
    content = {}

    for key in list(kwargs):  # fill kwargs
        kwargs[key] = data2schema(kwargs[key])

    if isinstance(_data, dict):
        datacontent = iteritems(_data)

    else:
        datacontent = getmembers(_data)

    for name, value in datacontent:

        if name[0] == '_':
            continue

        if isinstance(value, dict):
            schema = data2schemacls(value)()

        else:
            schema = data2schema(value)

        content[name] = schema

    content.update(kwargs)  # update content

    result = type('GeneratedSchema', (Schema,), content)

    return result
28245
function simpleType_jsonSchema(name) {
  var result = {};
  result.type = this.instance.toLowerCase();

  __processOptions(result, this.options)

  return result;
}
595942
private JsonElement parse(JsonElement element, JsonSchema schema)
      throws DataConversionException {
    JsonObject root = new JsonObject();
    root.add(DEFAULT_RECORD_COLUMN_NAME, element);
    JsonObject jsonObject = parse(root, schema);
    return jsonObject.get(DEFAULT_RECORD_COLUMN_NAME);
  }
1053967
def get_jsonschema(self, context=None):
        
        schema = super(Enum, self).get_jsonschema(context=None)
        schema.pop('type')
        if self.get_attr('enum'):
            schema['enum'] = self.get_attr('enum')
        return schema
342752
def parse_schema(schema):
    """"""

    if isinstance(schema, BaseSchema):
        return schema.validate

    if type(schema) is type:
        return _build_type_validator(schema)

    if isinstance(schema, dict):
        return _build_dict_validator(schema)

    if type(schema) in (list, tuple, set):
        return _build_iterable_validator(schema)

    if callable(schema):
        return _build_callable_validator(schema)

    return _build_static_validator(schema)
1146898
def to_dict(self):
        

        # 1. extract the schema fields
        data = self.extract_fields()

        # 2. include custom key-value pairs listed in the mapping dictionary
        for key, attr in self.attributes.iteritems():
            if key in self.ignore:
                continue  # skip ignores
            # fetch the mapped attribute
            value = getattr(self.context, attr, None)
            if value is None:
                value = getattr(self, attr, None)
            # handle function calls
            if callable(value):
                value = value()
            # map the value to the given key from the mapping
            data[key] = api.to_json_value(self.context, key, value)
        return data
374813
def load_schema(path):
    """"""
    with open(path) as json_data:
        schema = json.load(json_data)
    return schema
508498
def _schema_to_json_file_object(self, schema_list, file_obj):
        
        json.dump(schema_list, file_obj, indent=2, sort_keys=True)
618303
def read_yaml(yaml_data, schema):
    
    try:
        resource = resource_stream('atomic_reactor', schema)
        schema = codecs.getreader('utf-8')(resource)
    except (IOError, TypeError):
        logger.error('unable to extract JSON schema, cannot validate')
        raise

    try:
        schema = json.load(schema)
    except ValueError:
        logger.error('unable to decode JSON schema, cannot validate')
        raise
    data = yaml.safe_load(yaml_data)
    validator = jsonschema.Draft4Validator(schema=schema)
    try:
        jsonschema.Draft4Validator.check_schema(schema)
        validator.validate(data)
    except jsonschema.SchemaError:
        logger.error('invalid schema, cannot validate')
        raise
    except jsonschema.ValidationError:
        for error in validator.iter_errors(data):
            path = "".join(
                ('[{}]' if isinstance(element, int) else '.{}').format(element)
                for element in error.path
            )

            if path.startswith('.'):
                path = path[1:]

            logger.error('validation error (%s): %s', path or 'at top level', error.message)

        raise

    return data
272902
def dump(schema):
    
    result = {}

    for name, _ in iteritems(schema.getschemas()):

        if hasattr(schema, name):
            val = getattr(schema, name)

            if isinstance(val, DynamicValue):
                val = val()

            if isinstance(val, Schema):
                val = dump(val)

            result[name] = val

    return result
125992
def merge_schemas(cls, schema, _schema):
        
        tmp = schema.properties[:]  # copy
        prop = {}
        to_dict = lambda e: prop.update({e.pop('name'): e})
        [to_dict(i) for i in tmp]  # map(to_dict, tmp)
        for _prop in _schema.properties:
            if prop.get(_prop['name']):
                prop.pop(_prop['name'])
        if prop:
            for k, v in prop.items():
                v['name'] = k
                _schema.properties.append(v)
        return _schema
429395
private void traverseJsonData(JSONObject jsonData, String jsonPath, TestContext context) {
        for (Iterator it = jsonData.entrySet().iterator(); it.hasNext();) {
            Map.Entry jsonEntry = (Map.Entry) it.next();

            if (jsonEntry.getValue() instanceof JSONObject) {
                traverseJsonData((JSONObject) jsonEntry.getValue(), (StringUtils.hasText(jsonPath) ? jsonPath + "." + jsonEntry.getKey() : jsonEntry.getKey().toString()), context);
            } else if (jsonEntry.getValue() instanceof JSONArray) {
                JSONArray jsonArray = (JSONArray) jsonEntry.getValue();
                for (int i = 0; i < jsonArray.size(); i++) {
                    if (jsonArray.get(i) instanceof JSONObject) {
                        traverseJsonData((JSONObject) jsonArray.get(i), String.format((StringUtils.hasText(jsonPath) ? jsonPath + "." + jsonEntry.getKey() : jsonEntry.getKey().toString()) + "[%s]", i), context);
                    } else {
                        jsonArray.set(i, translate(String.format((StringUtils.hasText(jsonPath) ? jsonPath + "." + jsonEntry.getKey() : jsonEntry.getKey().toString()) + "[%s]", i), jsonArray.get(i), context));
                    }
                }
            } else {
                jsonEntry.setValue(translate((StringUtils.hasText(jsonPath) ? jsonPath + "." + jsonEntry.getKey() : jsonEntry.getKey().toString()),
                        jsonEntry.getValue() != null ? jsonEntry.getValue() : null, context));
            }
        }
    }
412449
def _parse_request(self, schema, req, locations):
        """"""
        if schema.many:
            assert (
                "json" in locations
            ), "schema.many=True is only supported for JSON location"
            # The ad hoc Nested field is more like a workaround or a helper,
            # and it servers its purpose fine. However, if somebody has a desire
            # to re-design the support of bulk-type arguments, go ahead.
            parsed = self.parse_arg(
                name="json",
                field=ma.fields.Nested(schema, many=True),
                req=req,
                locations=locations,
            )
            if parsed is missing:
                parsed = []
        else:
            argdict = schema.fields
            parsed = {}
            for argname, field_obj in iteritems(argdict):
                if MARSHMALLOW_VERSION_INFO[0] < 3:
                    parsed_value = self.parse_arg(argname, field_obj, req, locations)
                    # If load_from is specified on the field, try to parse from that key
                    if parsed_value is missing and field_obj.load_from:
                        parsed_value = self.parse_arg(
                            field_obj.load_from, field_obj, req, locations
                        )
                        argname = field_obj.load_from
                else:
                    argname = field_obj.data_key or argname
                    parsed_value = self.parse_arg(argname, field_obj, req, locations)
                if parsed_value is not missing:
                    parsed[argname] = parsed_value
        return parsed
692747
def schema_map(schema):
    """"""
    mapper = {}
    for name in getFieldNames(schema):
        mapper[name] = name
    return mapper
1065944
def _process_json(self, item, parent=None):
        
        if "data" in item:
            return [self._process_json(i, parent) for i in item["data"]]

        result = {}
        for key, value in item.items():
            if isinstance(value, dict) and ("type" in value or "data" in value):
                value = self._process_json(value, parent)
            result[key] = value
        if parent is not None and hasattr(parent, "type"):
            result[parent.type] = parent

        if "type" in result:
            object_class = self.objects_types.get(result["type"], Resource)
        else:
            object_class = self.objects_types.get(parent, Resource)
        return object_class(self, result)
461387
def validate_schema(schema_name):
    """"""
    def decorator(f):
        @wraps(f)
        def wrapper(*args, **kw):
            instance = args[0]
            try:
                instance.validator(instance.schemas[schema_name]).validate(request.get_json())
            except ValidationError, e:
                ret_dict = instance._create_ret_object(instance.FAILURE,
                                                       None, True,
                                                       instance.BAD_SCHEMA,
                                                       e.message)
                instance.logger.error("Invalid Schema", ret_dict)
                return jsonify(ret_dict), 400
            instance.logger.debug("Schema is valid")
            return f(*args, **kw)
        return wrapper
    return decorator