Пример #1
0
 public function testBasics()
 {
     $swagger = new Swagger();
     $swagger->setBasePath('/api');
     $swagger->setHost('http://example.com');
     $swagger->setVersion('2.1');
     $this->assertEquals('/api', $swagger->getBasePath());
     $this->assertEquals('http://example.com', $swagger->getHost());
     $this->assertEquals('2.1', $swagger->getVersion());
     $this->assertEquals(['swagger' => '2.1', 'host' => 'http://example.com', 'basePath' => '/api'], $swagger->toArray());
 }
Пример #2
0
 /**
  * @param Request $request
  */
 public function run(Request $request)
 {
     $routes = $this->generateRoutes();
     $response = new Response();
     $context = new RequestContext($this->uri->getBasepath());
     $matcher = new UrlMatcher($routes, $context);
     $prefs = $this->service->getPreferenceLoader()->getSystemPreferences();
     try {
         $match = $matcher->match($this->getDestination());
         $main = print_r($match, true);
         $route = $match['_route'];
         $css = [];
         $scripts = [];
         switch ($route) {
             case 'json':
                 $repo = $this->service->getResourceRepository();
                 $module = $this->findModuleBySlug($match['module']);
                 if ($module !== null && $module['model'] !== null) {
                     $components = parse_url($prefs->getApiUrl() . $module['slug']);
                     $prefs = $this->service->getPreferenceLoader()->getSystemPreferences();
                     $model = $module['model'];
                     $filename = sprintf('/packages/%s/api.json', $model->getName());
                     $json = Json::decode($repo->get($filename)->getBody());
                     $swagger = new Swagger($json);
                     $swagger->getInfo()->setVersion($prefs->getApiVersion());
                     $swagger->setHost($components['host']);
                     $swagger->setBasePath($components['path']);
                     $swagger->getSchemes()->add($components['scheme']);
                     $swagger->getConsumes()->add('application/vnd.api+json');
                     $swagger->getProduces()->add('application/vnd.api+json');
                     $response = new JsonResponse($swagger->toArray());
                     $response->setEncodingOptions(Json::HEX_TAG | Json::HEX_APOS | Json::HEX_AMP | Json::HEX_QUOT | Json::UNESCAPED_SLASHES);
                     return $response;
                 }
                 break;
             case 'reference':
             case 'module':
                 $current = '';
                 $content = $main;
                 if ($route == 'module') {
                     $scripts = ['/assets/jquery-migrate/jquery-migrate.min.js', '/assets/swagger-ui/dist/lib/jquery.slideto.min.js', '/assets/swagger-ui/dist/lib/jquery.wiggle.min.js', '/assets/swagger-ui/dist/lib/jquery.ba-bbq.min.js', '/assets/swagger-ui/dist/lib/handlebars-2.0.0.js', '/assets/swagger-ui/dist/lib/underscore-min.js', '/assets/swagger-ui/dist/lib/backbone-min.js', '/assets/swagger-ui/dist/swagger-ui.min.js', '/assets/swagger-ui/dist/lib/highlight.7.3.pack.js', '/assets/swagger-ui/dist/lib/jsoneditor.min.js', '/assets/swagger-ui/dist/lib/marked.js'];
                     $css = ['/assets/swagger-ui/dist/css/screen.css'];
                     $current = $match['module'];
                     $content = $this->render('/keeko/developer-app/templates/api.twig', ['base' => $this->getBaseUrl(), 'url' => $this->getBaseUrl() . '/reference/' . $match['module'] . '.json', 'module' => $this->findModuleBySlug($match['module'])]);
                 } else {
                     $content = $this->render('/keeko/developer-app/templates/reference/index.twig');
                 }
                 $main = $this->render('/keeko/developer-app/templates/reference.twig', ['base' => $this->getBaseUrl(), 'content' => $content, 'modules' => $this->loadModules(), 'current' => $current]);
                 break;
             case 'index':
                 $main = $this->render('/keeko/developer-app/templates/index.twig', ['plattform_name' => $prefs->getPlattformName(), 'base' => $this->getBaseUrl()]);
                 break;
             case 'area':
             case 'topic':
                 $current = isset($match['topic']) ? $match['topic'] : 'index';
                 $content = $this->render(sprintf('/keeko/developer-app/templates/%s/%s.twig', $match['area'], $current), ['base' => $this->getBaseUrl(), 'api_url' => $prefs->getApiUrl()]);
                 $main = $this->render(sprintf('/keeko/developer-app/templates/%s.twig', $match['area']), ['content' => $content, 'menu' => $this->getMenu($match['area']), 'current' => $current, 'base' => $this->getBaseUrl()]);
                 break;
         }
         $response->setContent($this->render('/keeko/developer-app/templates/main.twig', ['plattform_name' => $prefs->getPlattformName(), 'root' => $this->getBaseUrl(), 'base' => $this->getBaseUrl(), 'destination' => $this->getDestination(), 'styles' => $css, 'scripts' => $scripts, 'main' => $main]));
     } catch (ResourceNotFoundException $e) {
         $response->setStatusCode(Response::HTTP_NOT_FOUND);
     }
     return $response;
 }