Beispiel #1
0
use Illuminate\Support\Facades\File;
use Swagger\Swagger;
$app->get(config('swagger-lume.routes.docs'), function ($page = 'api-docs.json') {
    $filePath = config('swagger-lume.paths.docs') . "/{$page}";
    if (File::extension($filePath) === '') {
        $filePath .= '.json';
    }
    if (!File::exists($filePath)) {
        App::abort(404, "Cannot find {$filePath}");
    }
    $content = File::get($filePath);
    return new Response($content, 200, ['Content-Type' => 'application/json']);
});
$app->get(config('swagger-lume.routes.api'), function () {
    if (config('swagger-lume.generate_always')) {
        \SwaggerLume\Generator::generateDocs();
    }
    if (config('swagger-lume.proxy')) {
        $proxy = (new Request())->server('REMOTE_ADDR');
        (new Request())->setTrustedProxies([$proxy]);
    }
    $extras = [];
    $conf = config('swagger-lume');
    if (array_key_exists('validatorUrl', $conf)) {
        // This allows for a null value, since this has potentially
        // desirable side effects for swagger.  See the view for more
        // details.
        $extras['validatorUrl'] = $conf['validatorUrl'];
    }
    //need the / at the end to avoid CORS errors on Homestead systems.
    $response = new Response(view('swagger-lume::index', ['apiKeyPrefix' => config('swagger-lume.api.auth_token_prefix'), 'apiKey' => config('swagger-lume.api.auth_token'), 'apiKeyVar' => config('swagger-lume.api.key_var'), 'apiKeyInject' => config('swagger-lume.api.key_inject'), 'secure' => (new Request())->secure(), 'urlToDocs' => url(config('swagger-lume.routes.docs')), 'requestHeaders' => config('swagger-lume.headers.request')], $extras), 200);
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $this->info('Regenerating docs');
     Generator::generateDocs();
 }