Generate a model given a schema.
187388
public function generate(Schema $schema, string $className, Context $context)
    {
        foreach ($schema->getClasses() as $class) {
            $properties = [];
            $methods = [];

            foreach ($class->getProperties() as $property) {
                $properties[] = $this->createProperty($property, $schema->getNamespace() . '\\Model');
                $methods[] = $this->createGetter($property, $schema->getNamespace() . '\\Model');
                $methods[] = $this->createSetter($property, $schema->getNamespace() . '\\Model');
            }

            $model = $this->createModel(
                $class->getName(),
                $properties,
                $methods,
                \count($class->getExtensionsType()) > 0
            );

            $namespace = new Stmt\Namespace_(new Name($schema->getNamespace() . '\\Model'), [$model]);

            $schema->addFile(new File($schema->getDirectory() . '/Model/' . $class->getName() . '.php', $namespace, self::FILE_TYPE_MODEL));
        }
    }
361570
function generateSchemas() {
  // this.ajv.addMetaSchema(_generate.call(this, 'evaluate_metaschema'));
  this._validate = this.ajv.compile(_generate.call(this, 'schema'));
  this._expandMacros = this.ajv.compile(_generate.call(this, 'expand_macros'));
  this._evaluate = this.ajv.compile(_generate.call(this, 'evaluate'));
  // console.log(this._validate.toString().length, this._evaluate.toString().length);
}
1320247
def construct(cls: Type['Model'], values: 'DictAny', fields_set: 'SetStr') -> 'Model':
        
        m = cls.__new__(cls)
        object.__setattr__(m, '__values__', values)
        object.__setattr__(m, '__fields_set__', fields_set)
        return m
1231702
function CreateModelProperty(object, model, schema_name, index) {

    Object.defineProperty(object, schema_name, {
        configurable: false,
        enumerable: true,
        get: function() {

            let m = this.prop_array[index];

            if (!m) {
                let address = this.address.slice();
                address.push(index);
                m = new model(null, this.root, address);
                m.par = this;
                m.prop_name = schema_name;
                m.MUTATION_ID = this.MUTATION_ID;
                this.prop_array[index] = m;
            }

            return this.getHook(schema_name, m);
        }
    });
}
1350859
function generateModelDefinition(schema, definitionName) {
    var definition = {
      required: [],
      properties: {}
    };
    mergePaths(definition, schema.paths, definitionName);
    mergePaths(definition, schema.virtuals, definitionName);
	
    //remove empty arrays -> swagger 2.0 validates 
    if (definition.required.length === 0) {
    	delete(definition.required);
    }
    if (definition.properties.length === 0) {
    	delete(definition.properties);
    }
    return definition;
  }
995109
def schema(self):
        """"""
        if not hasattr(self, "_schema"):
            ret = None
            o = self._type
            if isinstance(o, type):
                ret = getattr(o, "schema", None)

            elif isinstance(o, Schema):
                ret = o

            else:
                module, klass = utils.get_objects(o)
                ret = klass.schema

            self._schema = ret

        return self._schema
482544
def to_schema(self):
        
        types = set()
        generated_schemas = []
        for schema_generator in self._schema_generators:
            generated_schema = schema_generator.to_schema()
            if len(generated_schema) == 1 and 'type' in generated_schema:
                types.add(generated_schema['type'])
            else:
                generated_schemas.append(generated_schema)

        if types:
            if len(types) == 1:
                (types,) = types
            else:
                types = sorted(types)
            generated_schemas = [{'type': types}] + generated_schemas
        if len(generated_schemas) == 1:
            (result_schema,) = generated_schemas
        elif generated_schemas:
            result_schema = {'anyOf': generated_schemas}
        else:
            result_schema = {}

        return result_schema
451383
function generate(model, count) {
  count = count || 1;
  var registry = {};
  var models = [];

  if (model) {
    models = typeof model === 'string' ? [model] : model;
  } else {
    models = Object.keys(schemas);
  }

  function build(model) {
    var instance = jsf(schemas[model]);
    var invalid = validate(instance);
    if (invalid) {
      var errors = JSON.stringify(invalid, null, 2);
      throw new Error('Invalid "' + model + '" instance:\n' + errors);
    }
    return instance;
  }

  function factory(model) {
    var instances = [];
    for (var i = 0, len = count; i < len; i++) {
      var instance = build(model);
      instances.push(instance);
    }
    registry[model] = instances;
  }

  models.forEach(factory);
  return registry;
}
878097
def load_raw(cls, model_fn, schema, *args, **kwargs):
        
        c = cls(*args, **kwargs)
        c.schema = schema.copy(schema_only=True)
        c._model_data = open(model_fn, 'rb').read()
        return c
512692
def generate_schema_mapping(resolver, schema_uri, depth=1):
    
    visitor = SchemaVisitor({'$ref': schema_uri}, resolver)
    return _generate_schema_mapping(visitor, set(), depth)
1198097
function _generate(schemaName) {
  var schema = generateSchema(schemaName, this._instructions, this._macros, this._opts.strict);
  this.ajv.removeSchema(schema.id);
  return schema;
}
562432
function generateSchemaRaw(modelParam, opts = {}) {
  validate.notNil(modelParam, "modelParam is mandatory");

  let models;
  if (_.isArray(modelParam)) {
    models = modelParam;
  } else if (_.isObject(modelParam)) {
    models = [modelParam];
  } else {
    throw new Error("modelParam should be an object or an array of objects");
  }

  return models.map(model => {
    const processedSchema = modelTransformer.transformJsonSchemaFromModel(
      model,
      opts
    );

    return {
      name: model.name,
      schema: processedSchema
    };
  });
}
692747
def schema_map(schema):
    """"""
    mapper = {}
    for name in getFieldNames(schema):
        mapper[name] = name
    return mapper
489841
def create_model_class(cls, name, table_name, attrs, validations=None, *, otherattrs=None,
                         other_bases=None):
    """"""
    members = dict(table_name=table_name, attrs=attrs, validations=validations or [])
    if otherattrs:
      members.update(otherattrs)
    return type(name, other_bases or (), members)
93833
def schema_from_context(context):
    """"""
    item_class = context.get('class')
    return (
        serializer_mapping[item_class] if item_class else BaseSchema,
        context.get('many', False)
    )
945600
def to_schema(self):
        """"""
        if not self.name or not self.process:
            raise ValueError("field is not registered with process")

        schema = {
            'name': self.name,
            'type': self.get_field_type(),
        }
        if self.required is not None:
            schema['required'] = self.required
        if self.label is not None:
            schema['label'] = self.label
        if self.description is not None:
            schema['description'] = self.description
        if self.default is not None:
            schema['default'] = self.default
        if self.hidden is not None:
            schema['hidden'] = self.hidden
        if self.choices is not None:
            for choice, label in self.choices:
                schema.setdefault('choices', []).append({
                    'label': label,
                    'value': choice,
                })

        return schema
267671
def create_schema(self, schema):
        
        if schema not in self.schemas:
            sql = "CREATE SCHEMA " + schema
            self.execute(sql)