From 275422b695c59479b4fef22af90f6de0a420335a Mon Sep 17 00:00:00 2001
From: Armand Bahi <armand.bahi@veremes.com>
Date: Fri, 26 Oct 2018 16:25:52 +0200
Subject: [PATCH] Make swagger work for dev installs

---
 vas/doc/index.phtml  | 12 ++++++++----
 vas/doc/swagger.php  |  5 +++--
 vas/rest/index.phtml |  4 +++-
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/vas/doc/index.phtml b/vas/doc/index.phtml
index 086cb768..d4fedf02 100755
--- a/vas/doc/index.phtml
+++ b/vas/doc/index.phtml
@@ -1,6 +1,9 @@
 <?php
 session_start();
-require_once '../rest/conf/properties.inc';
+
+$_SERVER['VAS_PATH'] = pathinfo(dirname($_SERVER['SCRIPT_FILENAME']))['dirname'];
+
+require_once $_SERVER['VAS_PATH'] . '/rest/conf/properties.inc';
 
 function returnOverview($sFolder, $parent) {
     $aModules = array();
@@ -17,10 +20,12 @@ function returnOverview($sFolder, $parent) {
             }
         }
     }
+
     return $aModules;
 }
 
-$aOverview = returnOverview(__DIR__ . "/../rest/ws", "");
+$aOverview = returnOverview($_SERVER['VAS_PATH'] . "/rest/ws", "");
+error_log('$aOverview: '. print_r($aOverview, true));
 ?>
 
 <!DOCTYPE html>
@@ -59,7 +64,7 @@ $aOverview = returnOverview(__DIR__ . "/../rest/ws", "");
                     sToken = json.PrivateToken.token;
                 }   else {
                     sToken = code[0].outerText.split('<token>')[1].split('</token>')[0];
-                }  
+                }
                 if (sToken != "") {
                 $("input[name='token']").each(function () {
                     $(this).attr("value", sToken);
@@ -154,4 +159,3 @@ foreach ($aOverview as $key => $value) {
         </div>
     </body>
 </html>
-
diff --git a/vas/doc/swagger.php b/vas/doc/swagger.php
index 3437171a..aca8acff 100755
--- a/vas/doc/swagger.php
+++ b/vas/doc/swagger.php
@@ -1,8 +1,9 @@
 <?php
+$_SERVER['VAS_PATH'] = pathinfo(dirname($_SERVER['SCRIPT_FILENAME']))['dirname'];
 header('Content-Type: application/json');
-require_once "../rest/conf/properties.inc";
+require_once $_SERVER['VAS_PATH'] . "/rest/conf/properties.inc";
 require("vendor/autoload.php");
-$swagger = \Swagger\scan('../rest/ws/'.$_REQUEST['service']);
+$swagger = \Swagger\scan($_SERVER['VAS_PATH'] . '/rest/ws/'.$_REQUEST['service']);
 $aServer = explode("://", $properties["web_server_name"]);
 $swagger = str_replace("[service_alias]", $properties["services_alias"], $swagger);
 $swagger = str_replace("[protocol]", $aServer[0], $swagger);
diff --git a/vas/rest/index.phtml b/vas/rest/index.phtml
index 86af3b21..d4b4cffa 100755
--- a/vas/rest/index.phtml
+++ b/vas/rest/index.phtml
@@ -1,5 +1,7 @@
 <?php
 
+$_SERVER['VAS_PATH'] = pathinfo(dirname($_SERVER['SCRIPT_FILENAME']))['dirname'];
+
 require_once("class/vitis_lib/VitisError.class.inc");
 require_once("class/vmlib/cryptUtil.inc");
 require_once("conf/properties.inc");
@@ -199,4 +201,4 @@ function customErrorHandler ($errno, $errstr, $errfile, $errline, $context){
 }
 
 include ("index.vhtml");
-?>
\ No newline at end of file
+?>
-- 
GitLab