Build https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/accessor.schema.json
427002
function getAccessor (accessor, bufferViews) {
  if (accessor._data) return accessor

  const numberOfComponents = GLTF_ACCESSOR_TYPE_COMPONENTS_NUMBER[accessor.type]
  if (accessor.byteOffset === undefined) accessor.byteOffset = 0

  accessor._bufferView = bufferViews[accessor.bufferView]

  const TypedArrayConstructor = WEBGL_TYPED_ARRAY_BY_COMPONENT_TYPES[accessor.componentType]
  const byteSize = GLTF_ACCESSOR_COMPONENT_TYPE_SIZE[accessor.componentType]

  const data = new TypedArrayConstructor(accessor._bufferView._data.slice(
    accessor.byteOffset,
    accessor.byteOffset + accessor.count * numberOfComponents * byteSize
  ))
  accessor._data = data

  // Sparse accessors
  // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/accessor.sparse.schema.json
  if (accessor.sparse !== undefined) {
    const TypedArrayIndicesConstructor =
      WEBGL_TYPED_ARRAY_BY_COMPONENT_TYPES[accessor.sparse.indices.componentType]

    // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/accessor.sparse.indices.schema.json
    const sparseIndices = new TypedArrayIndicesConstructor(
      bufferViews[accessor.sparse.indices.bufferView]._data,
      accessor.sparse.indices.byteOffset || 0,
      accessor.sparse.count
    )

    // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/accessor.sparse.values.schema.json
    const sparseValues = new TypedArrayConstructor(
      bufferViews[accessor.sparse.values.bufferView]._data,
      accessor.sparse.values.byteOffset || 0,
      accessor.sparse.count * numberOfComponents
    )

    if (accessor._data !== null) {
      accessor._data = accessor._data.slice()
    }

    let valuesIndex = 0
    for (let indicesIndex = 0; indicesIndex < sparseIndices.length; indicesIndex++) {
      let dataIndex = sparseIndices[indicesIndex] * numberOfComponents
      for (let componentIndex = 0; componentIndex < numberOfComponents; componentIndex++) {
        accessor._data[dataIndex++] = sparseValues[valuesIndex++]
      }
    }
  }

  return accessor
}
287849
def build_collection_schema(**args)
      object.map { |object| self.class.new(object, context).build_schema(args) }
    end
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
803457
public static JsonSchema buildBaseSchema(Type type) {
    JsonObject jsonObject = new JsonObject();
    JsonObject dataType = new JsonObject();
    jsonObject.addProperty(COLUMN_NAME_KEY, DEFAULT_RECORD_COLUMN_NAME);
    dataType.addProperty(TYPE_KEY, type.toString());
    jsonObject.add(DATA_TYPE_KEY, dataType);
    return new JsonSchema(jsonObject);
  }
998292
function Schema(registry, definition, opt_depth) {
  this._allowUnknownProperties = false;
  this._registry = registry;

  this.id = undefined;
  this.type = TYPES.UNKNOWN;
  this.depth = opt_depth || registry.depth;

  // possible primitive values or array elements
  this.enum = undefined;
  this.ordered = false;

  // object property schemas
  this.properties = undefined;
  this.propertiesList = [];
  this.wildcard = undefined;

  // single schema for all array elements
  this.content = undefined;

  this.value = undefined;
  this.min = undefined;
  this.max = undefined;
  this.pattern = undefined;

  // schema value can be null
  this.allowNullValue = false;

  return this._configure(definition);
}
888916
function(schema, dontRecurse) {
    if ('string' === typeof schema) {
      var schemaName = schema.split("#");
      schema = schemas.build(schemaName[0], schemaName[1]);
      if (!schema)
        throw new Error('Could not load schema: ' + schemaName.join('#'));
    } else if (schema && !dontRecurse && (!schema.hasOwnProperty('parse') && !schema.hasOwnProperty('serialize'))) {
      var keys = Object.keys(schema);
      keys.forEach(function(key) {
        schema[key] = loadSchema(schema[key], true);
      });
    }
    return schema;
  }
1028340
function initJsonSchema (args) {
    // get global validator instance
    var validator = this.global().validator
    // get schema id based on model name - must be globally unique
    this.schemaId = '/model/'+this.name
    // set option to perform schema validation on created/update
    this.validateSchema = args.validate === false ? false : true
    // create schema for model
    var schema = this.schemaMeta = {
        id: this.schemaId,
        properties: {},
        required: [],
        type: 'object',
    }
    // get data column
    var dataColumn = this.columnName('data')
    // create entry in schema for data if model has data
    if (dataColumn) {
        // schema id for data only
        this.schemaDataId = '/model/'+this.name+'/data'
        // create data schema - meta and data schemas are compiled without
        // ref so that the complete schemas can be easily sent to clients
        var schemaData = this.schemaData = schema.properties[dataColumn] = {
            additionalProperties: args.additionalProperties,
            id: this.schemaDataId,
            properties: {},
            type: 'object',
        }
        // merge schema from args over data schema
        _.merge(schemaData.properties, args.properties)
        // if required properties are set then add
        if (args.required) {
            // required must be array
            if (typeof args.required === 'string') {
                args.required = [args.required]
            }
            // throw error if not array
            assert.ok(Array.isArray(args.required), 'required must be array or string')
            // add list of required properties
            schemaData.required = args.required
        }
        // add data schema
        validator.addSchema(schemaData, this.schemaDataId)
    }
    // create schema for each default column
    _.each(this.defaultColumns, (defaultName, columnName) => {
        // skip data column which is already specified
        if (defaultName === 'data') {
            return
        }
        // get column spec
        var column = this.columns[columnName]
        // if there is not schema for type then skip
        if (!defaultSchemas[column.type]) {
            return
        }
        // get column schema
        var columnSchema = _.cloneDeep(defaultSchemas[column.type])
        // set default schema based on type
        schema.properties[columnName] = columnSchema
        // make property required unless nullable
        if (column.null === false) {
            schema.required.push(columnName)
        }
    })
    // add schema
    validator.addSchema(schema, this.schemaId)
}
47771
function parseProperties(source, baseDirectory) {
  // Get the raw SCSS concrete syntax tree.
  const rawTree = parseCSS(source);
  removeWhitespace(rawTree);

  // Convert the concrete syntax tree into a more convenient AST.
  let schema
  const rootRules = []
  for (const rule of rawTree.value) {
    if (rule.type === 'atrule') {
      removeWhitespace(rule);
      const [keyword, argument] = rule.value;
      if (keyword.value === 'schema') {
        schema = visitSchema(argument, baseDirectory)
      } else if (keyword.value === 'import') {
        rootRules.push(...visitImport(argument, baseDirectory))
      }
    } else {
      rootRules.push(visitRule(rule, false))
    }
  }

  // Flatten out any nested selectors.
  const rules = []
  for (const rootRule of rootRules) {
    flattenRule(rootRule, rules, [[]]);
  }

  const validator = new Validator();

  for (const rule of rules) {
    // Validate each rule's properties against the schema.
    for (const property in rule.properties) {
      if (schema) {
        const propertySchema = schema[property]
        const value = rule.properties[property]
        if (!propertySchema) {
          throw new Error(`Property '${property}' is not present in the schema`);
        }
        const {errors} = validator.validate(value, propertySchema);
        if (errors.length > 0) {
          throw new Error(`Invalid value '${value}' for property '${property}'`)
        }
      }
    }

    rule.selectors = rule.selectors.map(applyPseudoClasses)
  }

  return rules;
}
579406
function buildLoadKey (blueprintMeta, originalKey, json) {
  const keyParts = [
    blueprintMeta.namespace,
    originalKey
  ]

  if (json.version) {
    keyParts.push(json.version.replace('.', '_'))
  }

  return keyParts.join('_')
}
224537
function superstruct(config = {}) {
  const types = {
    ...Types,
    ...(config.types || {}),
  }

  /**
   * Create a `kind` struct with `schema`, `defaults` and `options`.
   *
   * @param {Any} schema
   * @param {Any} defaults
   * @param {Object} options
   * @return {Function}
   */

  function struct(schema, defaults, options = {}) {
    if (isStruct(schema)) {
      schema = schema.schema
    }

    const kind = Kinds.any(schema, defaults, { ...options, types })

    function Struct(data) {
      if (this instanceof Struct) {
        if (process.env.NODE_ENV !== 'production') {
          throw new Error(
            'The `Struct` creation function should not be used with the `new` keyword.'
          )
        } else {
          throw new Error('Invalid `new` keyword!')
        }
      }

      return Struct.assert(data)
    }

    Object.defineProperty(Struct, IS_STRUCT, { value: true })
    Object.defineProperty(Struct, KIND, { value: kind })

    Struct.kind = kind.name
    Struct.type = kind.type
    Struct.schema = schema
    Struct.defaults = defaults
    Struct.options = options

    Struct.assert = value => {
      const [error, result] = kind.validate(value)

      if (error) {
        throw new StructError(error)
      }

      return result
    }

    Struct.test = value => {
      const [error] = kind.validate(value)
      return !error
    }

    Struct.validate = value => {
      const [error, result] = kind.validate(value)

      if (error) {
        return [new StructError(error)]
      }

      return [undefined, result]
    }

    return Struct
  }

  /**
   * Mix in a factory for each specific kind of struct.
   */

  Object.keys(Kinds).forEach(name => {
    const kind = Kinds[name]

    struct[name] = (schema, defaults, options) => {
      const type = kind(schema, defaults, { ...options, types })
      const s = struct(type, defaults, options)
      return s
    }
  })

  /**
   * Return the struct factory.
   */

  return struct
}
1232860
def schema_helper(self, name, _, schema=None, **kwargs):
        
        if schema is None:
            return None

        schema_instance = resolve_schema_instance(schema)

        schema_key = make_schema_key(schema_instance)
        self.warn_if_schema_already_in_spec(schema_key)
        self.openapi.refs[schema_key] = name

        json_schema = self.openapi.schema2jsonschema(schema_instance)

        return json_schema
1096737
def build(self, schema: Schema) -> Mapping[str, Any]:
        
        fields = list(self.iter_fields(schema))

        properties = {
            field.name: self.build_parameter(field)
            for name, field in fields
        }

        result = dict(
            type="object",
            properties=properties,
        )

        required_fields = [
            name
            for name, field in fields
            if field.required and not field.allow_none
        ]

        if required_fields:
            result["required"] = required_fields

        return result
617661
def build_schema(schema: Schema) -> Mapping[str, Any]:
    
    builder = Schemas(build_parameter=build_parameter)
    return builder.build(schema)
681283
def _convert_schema(bundle):
    
    # http://docs.ckan.org/en/latest/api/#ckan.logic.action.create.resource_create
    schema_csv = None
    for f in bundle.dataset.files:
        if f.path.endswith('schema.csv'):
            contents = f.unpacked_contents
            if isinstance(contents, six.binary_type):
                contents = contents.decode('utf-8')
            schema_csv = six.StringIO(contents)
            schema_csv.seek(0)
            break

    ret = {
        'package_id': bundle.dataset.vid.lower(),
        'url': 'http://example.com',
        'revision_id': '',
        'description': 'Schema of the dataset tables.',
        'format': 'text/csv',
        'hash': '',
        'name': 'schema',
        'upload': schema_csv,
    }

    return ret
451185
public static org.apache.avro.Schema toAvroSchema(Schema pangoolSchema) {
		List<org.apache.avro.Schema.Field> avroFields = new ArrayList<org.apache.avro.Schema.Field>();

		for(Field pangoolField : pangoolSchema.getFields()) {
			org.apache.avro.Schema.Type avroFieldType = null;
			org.apache.avro.Schema.Field avroField = null;
			org.apache.avro.Schema avroFieldSchema=null;
			switch(pangoolField.getType()){
				case INT: 
				case FLOAT: 
				case DOUBLE: 
				case LONG: 
				case BOOLEAN: 
				case STRING:  
				case BYTES:
					avroFieldType = org.apache.avro.Schema.Type.valueOf(pangoolField.getType().toString());
					avroFieldSchema =org.apache.avro.Schema.create(avroFieldType); 
					avroField = new org.apache.avro.Schema.Field(pangoolField.getName(),avroFieldSchema
							,null,null);
				break;
				case OBJECT: 
					avroFieldType = org.apache.avro.Schema.Type.BYTES; 
					avroFieldSchema = org.apache.avro.Schema.create(avroFieldType);
					avroField = new org.apache.avro.Schema.Field(pangoolField.getName(),avroFieldSchema
							,null,null);
					avroField.addProp(Field.METADATA_BYTES_AS_OBJECT,"true");
					
				break;
				case ENUM: 
					avroFieldType = org.apache.avro.Schema.Type.ENUM;
					Object[] enumValues = pangoolField.getObjectClass().getEnumConstants();
					List<String> values=new ArrayList<String>();
					for (Object e : enumValues){
						values.add(e.toString());
					}
					avroFieldSchema = org.apache.avro.Schema.createEnum(pangoolField.getName(),null,null, values);
					avroField = new org.apache.avro.Schema.Field(pangoolField.getName(),avroFieldSchema
							,null,null);
					break;
				default:
					throw new PangoolRuntimeException("Not avro conversion from Pangool Schema type:" + pangoolField.getType());
				
			}
			if (pangoolField.getObjectClass() != null){
				avroField.addProp(Field.METADATA_OBJECT_CLASS, pangoolField.getObjectClass().getName());
			}
			if (pangoolField.getObjectSerialization() != null){
				avroField.addProp(Field.METADATA_OBJECT_SERIALIZATION,pangoolField.getObjectSerialization().getName());
			}
			for (Map.Entry<String,String> property : pangoolField.getProps().entrySet()){
				avroField.addProp(property.getKey(),property.getValue());
			}
			avroFields.add(avroField);
		}
		org.apache.avro.Schema avroSchema = org.apache.avro.Schema.createRecord(pangoolSchema.getName(), null, null, false);
		avroSchema.setFields(avroFields);
		return avroSchema;
	}
1125009
function buildJsonSchema(comments) {

    // skeleton schema object
    var schema = {
        properties: {
        }
    };

    // go through each comment block
    (comments || []).forEach(function(block) {

        // we're only interested in customTags (none standard jsDoc comments i.e. @schema.)
        (block.customTags || []).forEach(function(item) {

            var tag = item.tag.replace('schema.', '');
            var value = item.value || '';

            // skip properties with no value
            if (value === '') return;

            if (block.scope === 'global') {
                schema[tag] = value;
            }
            else {

                // item is a property
                schema.properties[block.name] = schema.properties[block.name] || {};

                // jsdoc-parse lowercase tag names, so we need more case blocks to correct this
                switch (tag) {

                    /* integers */

                    case 'minimum':
                    case 'maximum': {
                        schema.properties[block.name][tag] = parseInt(value, 10);
                    } break;

                    case 'minitems': {
                        schema.properties[block.name].minItems = parseInt(value, 10);
                    } break;

                    case 'maxitems': {
                        schema.properties[block.name].maxItems = parseInt(value, 10);
                    } break;

                    case 'minlength': {
                        schema.properties[block.name].minLength = parseInt(value, 10);
                    } break;

                    case 'maxlength': {
                        schema.properties[block.name].maxLength = parseInt(value, 10);
                    } break;

                    case 'exclusiveminimum': {
                        schema.properties[block.name].exclusiveMinimum = parseInt(value, 10);
                    } break;

                    case 'exclusivemaximum': {
                        schema.properties[block.name].exclusiveMaximum = parseInt(value, 10);
                    } break;

                    case 'divisibleby': {
                        schema.properties[block.name].divisibleBy = parseInt(value, 10);
                    } break;

                    /* boolean's */

                    case 'required': {
                        schema.properties[block.name][tag] = (value === 'true');
                    } break;

                    case 'uniqueitems': {
                        schema.properties[block.name].uniqueItems = (value === 'true');
                    } break;

                    /* strings */

                    case 'extends':
                    case 'id':
                    case 'type':
                    case 'pattern':
                    case 'title':
                    case 'format':
                    case 'disallow':
                    case 'extends':
                    case 'enum':
                    case 'description':
                    case 'name':
                    case 'default':
                    default: {
                        schema.properties[block.name][tag] = value;
                    } break;
                }
            }

        });
    });

    return schema;
}
809327
private void generateSchema(Class clazz) {
    try {
      File targetFile = new File(getGeneratedResourcesDirectory(), clazz.getName() + ".json");
      getLog().info("Generate JSON schema: " + targetFile.getName());
      SchemaFactoryWrapper schemaFactory = new SchemaFactoryWrapper();
      OBJECT_MAPPER.acceptJsonFormatVisitor(OBJECT_MAPPER.constructType(clazz), schemaFactory);
      JsonSchema jsonSchema = schemaFactory.finalSchema();
      OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValue(targetFile, jsonSchema);
    }
    catch (IOException ex) {
      throw new RuntimeException(ex);
    }
  }