public function resourcesAction() { $swagger = new \Swagger\Swagger(__DIR__); $content = json_encode($swagger->getResourceList()); $this->response->setContentType('application/json', 'utf-8'); return $this->response->setContent($content); }
function json() { $swagger = new \Swagger\Swagger(dirname(__DIR__)); header("Content-Type: application/json"); $result = $swagger->getResourceList(array()); $result['info'] = array('title' => 'WP elasticsearch API', 'description' => 'API to store posts from WordPress to Elasticsearch and back.<hr/>'); echo json_encode($result); }
public function fire() { $projectPaths = $this->realpaths($this->paths); $excludePaths = $this->realpaths($this->exclude); $outputPath = head((array) $this->output) . DIRECTORY_SEPARATOR; $swagger = new \Swagger\Swagger($projectPaths, $excludePaths); $resourceList = $swagger->getResourceList(['output' => 'array', 'suffix' => $this->suffix, 'apiVersion' => $this->default_api_version, 'swaggerVersion' => $this->default_swagger_version, 'template' => $this->api_doc_template]); $resourceOptions = ['output' => 'json', 'defaultSwaggerVersion' => $resourceList['swaggerVersion'], 'defaultBasePath' => $this->default_base_path]; if (isset($resourceList['apiVersion'])) { $resourceOptions['defaultApiVersion'] = $resourceList['apiVersion']; } $resourceName = false; $output = []; foreach ($swagger->getResourceNames() as $resourceName) { $json = $swagger->getResource($resourceName, $resourceOptions); $resourceName = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($resourceName, DIRECTORY_SEPARATOR)); $output[$resourceName] = $json; } if (!$output) { throw new SwaggerException('no valid resources found'); } if (file_exists($outputPath) && !is_dir($outputPath)) { throw new SwaggerException(sprintf('[%s] is not a directory', $outputPath)); } elseif (!file_exists($outputPath) && !mkdir($outputPath, 0755, true)) { throw new SwaggerException(sprintf('[%s] is not writeable', $outputPath)); } if (!file_exists($outputPath . '/.gitignore')) { file_put_contents($outputPath . '/.gitignore', "*\n!.gitignore"); } $filename = $outputPath . 'api-docs.json'; if (file_put_contents($filename, \Swagger\Swagger::jsonEncode($resourceList, true))) { $this->logger('Created ' . $filename); } foreach ($output as $name => $json) { $name = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($name, DIRECTORY_SEPARATOR)); $filename = $outputPath . $name . '.json'; $this->logger('Created ' . $filename); file_put_contents($filename, $json); } $this->logger(''); }
public function call() { //The Slim application $app = $this->app; // Swager Documentation $app->group($this->path, function () use($app) { $app->get('/', function () use($app) { $swagger = new \Swagger\Swagger($this->scanPath); $resourceList = $swagger->getResourceList(); echo json_encode($resourceList); }); $app->get('/:path', function ($path) use($app) { $swagger = new \Swagger\Swagger($this->scanPath); $resourceList = $swagger->getResourceList(); if (!empty($path)) { echo $swagger->getResource('/' . $path, $this->options); } else { echo json_encode($resourceList); } }); }); // Call next middleware $this->next->call(); }
$output = array(); foreach ($swagger->getResourceNames() as $resourceName) { $json = $swagger->getResource($resourceName, $resourceOptions); $resourceName = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($resourceName, DIRECTORY_SEPARATOR)); $output[$resourceName] = $json; } if ($output) { if (file_exists($outputPath) && !is_dir($outputPath)) { throw new RuntimeException(sprintf('[%s] is not a directory', $outputPath)); } else { if (!file_exists($outputPath) && !mkdir($outputPath, 0755, true)) { throw new RuntimeException(sprintf('[%s] is not writeable', $outputPath)); } } $filename = $outputPath . 'api-docs.json'; if (file_put_contents($filename, $swagger->getResourceList($resourceListOptions))) { echo 'Created ', $filename, PHP_EOL; } if ($options['url'] == false) { $filename = $outputPath . 'index.php'; if (file_exists($filename)) { echo 'Skipped ', $filename, PHP_EOL; } else { file_put_contents($filename, "<?php\nheader('Content-Type: application/json');\nreadfile(__DIR__.'/api-docs.json');"); echo 'Created ', $filename, PHP_EOL; } } foreach ($output as $name => $json) { $name = str_replace(DIRECTORY_SEPARATOR, '-', ltrim($name, DIRECTORY_SEPARATOR)); $filename = $outputPath . $name . '.json'; echo 'Created ', $filename, PHP_EOL;