Esempio n. 1
0
 /**
  * Generate fresh filesystem documents for all entries found in the library.
  *
  * @param string $host Hostname of system serving swagger documents (without protocol)
  * @return void
  */
 public function makedocs($host)
 {
     // make same configuration as used by the API availble inside the lib
     require ROOT . DS . 'config/routes.php';
     if (Configure::read('Swagger')) {
         $this->config = Hash::merge(AppController::$defaultConfig, Configure::read('Swagger'));
     }
     $this->out('Crawl-generating swagger documents...');
     SwaggerTools::makeDocs($host);
     $this->out('Command completed successfully.');
 }
Esempio n. 2
0
 /**
  * Index action used to produce a JSON response containing either a swagger
  * document (if a valid id argument is passed) or a list with links to all
  * aavailable documents (if defined in the library).
  *
  * @param string $id Name of swagger document to generate/serve
  * @throws \InvalidArgumentException
  * @return void
  */
 public function index($id = null)
 {
     if (!$id) {
         $this->jsonResponse($this->getJsonDocumentList());
         return;
     }
     if (!isset($this->config['library'])) {
         throw new \InvalidArgumentException('Swagger configuration file does not contain a library section');
     }
     if (!array_key_exists($id, $this->config['library'])) {
         throw new \InvalidArgumentException("Swagger configuration file does not contain a document definition for '{$id}'");
     }
     $document = SwaggerTools::getSwaggerDocument($id, $this->request->host());
     $this->jsonResponse($document);
 }