示例#1
0
文件: Swagger.php 项目: seytar/psx
 public function generate(Resource $resource)
 {
     $declaration = new Declaration($this->apiVersion);
     $declaration->setBasePath($this->basePath);
     $declaration->setApis($this->getApis($resource));
     $declaration->setModels($this->getModels($resource));
     $declaration->setResourcePath(ApiGeneration::transformRoutePlaceholder($resource->getPath()));
     $writer = new JsonWriter();
     $swagger = $writer->write($declaration);
     // since swagger does not fully support the json schema spec we must
     // remove the $ref fragments
     $swagger = str_replace('#\\/definitions\\/', '', $swagger);
     return $swagger;
 }
示例#2
0
文件: Index.php 项目: visapi/amun
 private function buildApiDetails(Declaration $declaration, $serviceName)
 {
     $declaration->setResourcePath('/swagger/' . $serviceName);
     $result = $this->hm->getTable('AmunService\\Core\\Service')->select(array('autoloadPath', 'name', 'path', 'namespace'))->orderBy('id', Sql::SORT_ASC)->where('name', '=', str_replace('-', '/', $serviceName))->getAll();
     foreach ($result as $row) {
         try {
             // get the api class
             $apiPath = '../' . $row['autoloadPath'] . '/' . $row['namespace'] . '/Api';
             $apiPath = str_replace('\\', '/', $apiPath);
             if (is_dir($apiPath)) {
                 $models = array();
                 $classes = $this->findApiClasses($apiPath, $row['path'], $row['namespace'] . '\\Api');
                 foreach ($classes as $endpoint => $class) {
                     $this->scanMethods($declaration, $class, $endpoint, $models);
                 }
                 // add models
                 $models = array_unique($models);
                 if (!empty($models)) {
                     /*
                     foreach($models as $model)
                     {
                     	try
                     	{
                     		$record = new ReflectionClass($model);
                     
                     		$declaration->addModel($record->newInstance($provider->getTable()));
                     	}
                     	catch(Exception $e)
                     	{
                     	}
                     }
                     */
                 }
             }
         } catch (\Exception $e) {
         }
     }
 }