<?php
include __DIR__.'/../vendor/autoload.php';

use Swagger\Swagger;

$swagger = new Swagger(__DIR__.'/../../../../application/controllers/ws');
header('Content-Type: application/json');

if(!isset($_REQUEST['option']) && $_SERVER['PHP_SELF'] != 'index.php') {
    $content = explode('index.php',$_SERVER['PHP_SELF']);
    if(isset($content[1]) && !empty($content[1])){
        $_REQUEST['option'] = $content[1];
    }
}

if(!isset($_REQUEST['option'])) {
    echo $swagger->getResourceList(['output' => 'json']);
} else {
    $option = str_replace('/','',$_REQUEST['option']);
    if(in_array('/'.$option, $swagger->getResourceNames())){
        echo $swagger->getResource('/'.$option, [
            'output' => 'json',
            'defaultBasePath' => 'https://'.$_SERVER['HTTP_HOST'].'/index.php'
        ]);
    }
}