diff --git a/src/Jlapp/Swaggervel/SwaggervelServiceProvider.php b/src/Jlapp/Swaggervel/SwaggervelServiceProvider.php index 44b7572..3ca3b13 100644 --- a/src/Jlapp/Swaggervel/SwaggervelServiceProvider.php +++ b/src/Jlapp/Swaggervel/SwaggervelServiceProvider.php @@ -1,24 +1,32 @@ -package('jlapp/swaggervel'); - - $this->commands(array('Jlapp\Swaggervel\InstallerCommand')); - - require_once __DIR__ .'/routes.php'; - } - -} +package('jlapp/swaggervel'); + + $this->commands(array('Jlapp\Swaggervel\InstallerCommand')); + + $configPath = app_path() . "/config/packages/jlapp/swaggervel"; + Config::addNamespace('swaggervel', $configPath); + + $configFiles = File::glob($configPath . "/*.php"); + foreach ($configFiles as $file) { + $configName = pathinfo($file, PATHINFO_FILENAME); + + require __DIR__ .'/routes.php'; + } + } +} diff --git a/src/Jlapp/Swaggervel/routes.php b/src/Jlapp/Swaggervel/routes.php index 43cc10b..c517047 100644 --- a/src/Jlapp/Swaggervel/routes.php +++ b/src/Jlapp/Swaggervel/routes.php @@ -2,10 +2,10 @@ use Swagger\Swagger; -Route::any(Config::get('swaggervel::app.doc-route').'/{page?}', function($page='api-docs.json') { - $filePath = Config::get('swaggervel::app.doc-dir') . "/{$page}"; +Route::any(Config::get("swaggervel::$configName.doc-route").'/{page?}', function($page='api-docs.json') use ($configName) { + $filePath = Config::get("swaggervel::$configName.doc-dir") . "/{$page}"; - if (File::extension($filePath) === "") { + if (File::extension($filePath) !== "json") { $filePath .= ".json"; } if (!File::Exists($filePath)) { @@ -18,10 +18,10 @@ )); }); -Route::get('api-docs', function() { - if (Config::get('swaggervel::app.generateAlways')) { - $appDir = base_path()."/".Config::get('swaggervel::app.app-dir'); - $docDir = Config::get('swaggervel::app.doc-dir'); +Route::get(Config::get("swaggervel::$configName.api-docs-route"), function() use ($configName) { + if (Config::get("swaggervel::$configName.generateAlways")) { + $appDir = base_path()."/".Config::get("swaggervel::$configName.app-dir"); + $docDir = Config::get("swaggervel::$configName.doc-dir"); if (!File::exists($docDir) || is_writable($docDir)) { // delete all existing documentation @@ -31,10 +31,10 @@ File::makeDirectory($docDir); - $defaultBasePath = Config::get('swaggervel::app.default-base-path'); - $defaultApiVersion = Config::get('swaggervel::app.default-api-version'); - $defaultSwaggerVersion = Config::get('swaggervel::app.default-swagger-version'); - $excludeDirs = Config::get('swaggervel::app.excludes'); + $defaultBasePath = Config::get("swaggervel::$configName.default-base-path"); + $defaultApiVersion = Config::get("swaggervel::$configName.default-api-version"); + $defaultSwaggerVersion = Config::get("swaggervel::$configName.default-swagger-version"); + $excludeDirs = Config::get("swaggervel::$configName.excludes"); $swagger = new Swagger($appDir, $excludeDirs); @@ -67,7 +67,7 @@ } } - if (Config::get('swaggervel::app.behind-reverse-proxy')) { + if (Config::get("swaggervel::$configName.behind-reverse-proxy")) { $proxy = Request::server('REMOTE_ADDR'); Request::setTrustedProxies(array($proxy)); } @@ -79,14 +79,15 @@ $response = Response::make( View::make('swaggervel::index', array( 'secure' => Request::secure(), - 'urlToDocs' => url(Config::get('swaggervel::app.doc-route')), - 'requestHeaders' => Config::get('swaggervel::app.requestHeaders') ) - ), + 'apiKey' => Config::get("swaggervel::$configName.api-key"), + 'urlToDocs' => url(Config::get("swaggervel::$configName.doc-route")), + 'requestHeaders' => Config::get("swaggervel::$configName.requestHeaders"), + )), 200 ); - if (Config::has('swaggervel::app.viewHeaders')) { - foreach (Config::get('swaggervel::app.viewHeaders') as $key => $value) { + if (Config::has("swaggervel::$configName.viewHeaders")) { + foreach (Config::get("swaggervel::$configName.viewHeaders") as $key => $value) { $response->header($key, $value); } } diff --git a/src/config/app.php b/src/config/app.php index 890ffbf..1fef6c9 100644 --- a/src/config/app.php +++ b/src/config/app.php @@ -21,6 +21,13 @@ */ 'doc-route' => 'docs', + /* + |-------------------------------------------------------------------------- + | Relative path to access documentation. + |-------------------------------------------------------------------------- + */ + 'api-docs-route' => 'api-docs', + /* |-------------------------------------------------------------------------- | Absolute path to directory containing the swagger annotations are stored. diff --git a/src/views/index.blade.php b/src/views/index.blade.php index 271e252..48b1d70 100644 --- a/src/views/index.blade.php +++ b/src/views/index.blade.php @@ -65,7 +65,7 @@ log("key: " + key); if (key && key.trim() != "") { log("added key " + key); - window.authorizations.add("key", new ApiKeyAuthorization("{{Config::get('swaggervel::app.api-key')}}", key, "query")); + window.authorizations.add("key", new ApiKeyAuthorization("{{ $apiKey }}", key, "query")); } else { window.authorizations.remove("key"); }