コード例 #1
0
 /**
  * Display Swagger API page.
  *
  * @return \Response
  */
 public function api()
 {
     if (config('l5-swagger.generate_always')) {
         Generator::generateDocs();
     }
     if (config('l5-swagger.proxy')) {
         $proxy = Request::server('REMOTE_ADDR');
         Request::setTrustedProxies([$proxy]);
     }
     $extras = [];
     if (array_key_exists('validatorUrl', config('l5-swagger'))) {
         // This allows for a null value, since this has potentially
         // desirable side effects for swagger. See the view for more
         // details.
         $extras['validatorUrl'] = config('l5-swagger.validatorUrl');
     }
     // Need the / at the end to avoid CORS errors on Homestead systems.
     $response = Response::make(view('l5-swagger::index', ['apiKey' => config('l5-swagger.api.auth_token'), 'apiKeyVar' => config('l5-swagger.api.key_var'), 'securityDefinition' => config('l5-swagger.api.security_definition'), 'apiKeyInject' => config('l5-swagger.api.key_inject'), 'secure' => Request::secure(), 'urlToDocs' => route('l5-swagger.docs', config('l5-swagger.paths.docs_json', 'api-docs.json')), 'requestHeaders' => config('l5-swagger.headers.request'), 'docExpansion' => config('l5-swagger.docExpansion'), 'highlightThreshold' => config('l5-swagger.highlightThreshold')], $extras), 200);
     $headersView = config('l5-swagger.headers.view');
     if (is_array($headersView) and !empty($headersView)) {
         foreach ($headersView as $key => $value) {
             $response->header($key, $value);
         }
     }
     return $response;
 }
コード例 #2
0
 /** @test */
 public function can_generate_api_json_file()
 {
     $this->setAnnotationsPath();
     \L5Swagger\Generator::generateDocs();
     $this->assertTrue(file_exists($this->jsonDocsFile()));
     $this->visit(route('l5-swagger.docs'))->see('L5 Swagger API')->assertResponseOk();
 }
コード例 #3
0
 /** @test */
 public function can_generate_api_json_file_with_changed_base_path()
 {
     $this->setAnnotationsPath();
     $cfg = config('l5-swagger');
     $cfg['paths']['base'] = '/new/api/base/path';
     config(['l5-swagger' => $cfg]);
     \L5Swagger\Generator::generateDocs();
     $this->assertTrue(file_exists($this->jsonDocsFile()));
     $this->visit(route('l5-swagger.docs'))->see('L5 Swagger API')->see('/new/api/base/path')->assertResponseOk();
 }
コード例 #4
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->info('Regenerating docs');
     Generator::generateDocs();
 }