/** * Loads the Laravel Models into the Swagger JSON * * @param Analysis $analysis */ private function load_models(Analysis $analysis) { foreach ($this->models as $model) { /** @var Model $model */ $obj = new $model(); if ($obj instanceof Model) { //check to make sure it is a model $reflection = new ReflectionClass($obj); $with = $reflection->getProperty('with'); $with->setAccessible(true); $list = Schema::getColumnListing($obj->getTable()); $list = array_diff($list, $obj->getHidden()); $properties = []; foreach ($list as $item) { $data = ['property' => $item, 'type' => $this->get_type($obj->getTable(), $item)]; $default = $this->get_default($obj->getTable(), $item); if (!is_null($default)) { $data['default'] = $default; } $properties[] = new Property($data); } foreach ($with->getValue($obj) as $item) { $class = get_class($obj->{$item}()->getModel()); $properties[] = new Property(['property' => $item, 'ref' => '#/definitions/' . $class]); } $definition = new Definition(['definition' => $model, 'properties' => $properties]); $analysis->addAnnotation($definition, new Context(['-', $model])); } } }