예제 #1
1
 /**
  * Show/return documentation
  *
  * Returns a ContentNegotiation view model to allow for multiple
  * representations of documentation.
  *
  * @return ViewModel
  */
 public function showAction()
 {
     $apiName = $this->params()->fromRoute('api');
     $apiVersion = $this->params()->fromRoute('version', '1');
     $serviceName = $this->params()->fromRoute('service');
     $viewModel = new ViewModel();
     $viewModel->setTemplate('zf-apigility-documentation/show');
     $viewModel->setVariable('baseUrl', $this->serverUrlViewHelper->__invoke());
     if (!$apiName) {
         $apiList = $this->apiFactory->createApiList();
         $viewModel->setVariable('apis', $apiList);
         $viewModel->setVariable('type', 'apiList');
         return $viewModel;
     }
     $api = $this->apiFactory->createApi($apiName, $apiVersion);
     if (!$serviceName) {
         $viewModel->setVariable('documentation', $api);
         $viewModel->setVariable('type', 'api');
         return $viewModel;
     }
     $service = $this->apiFactory->createService($api, $serviceName);
     $viewModel->setVariable('documentation', $service);
     $viewModel->setVariable('type', 'service');
     return $viewModel;
 }
 /**
  * List available APIs
  *
  * @return ViewModel
  */
 public function listAction()
 {
     $apis = $this->apiFactory->createApiList();
     $viewModel = new ViewModel(['apis' => $apis]);
     $viewModel->setTemplate('zf-apigility-documentation-swagger/list');
     return $viewModel;
 }
 /**
  * @return ViewModel
  */
 public function showAction()
 {
     $apiName = $this->params()->fromRoute('api');
     $apiVersion = $this->params()->fromRoute('version', '1');
     $viewModel = new ViewModel(['api' => $apiName]);
     $viewModel->setTemplate('zf-apigility-documentation-blueprint/api');
     $viewModel->setTerminal(true);
     $api = $this->apiFactory->createApi($apiName, $apiVersion);
     $viewModel->setVariable('documentation', $api);
     $viewModel->setVariable('type', 'api');
     return $viewModel;
 }
예제 #4
1
 public function testCreateRpcService()
 {
     $docConfig = (include __DIR__ . '/TestAsset/module-config/documentation.config.php');
     $api = $this->apiFactory->createApi('Test', 1);
     $service = $this->apiFactory->createService($api, 'Ping');
     $this->assertInstanceOf('ZF\\Apigility\\Documentation\\Service', $service);
     $this->assertEquals('Ping', $service->getName());
     $this->assertEquals($docConfig['Test\\V1\\Rpc\\Ping\\Controller']['description'], $service->getDescription());
     $ops = $service->getOperations();
     $this->assertCount(1, $ops);
     foreach ($ops as $operation) {
         $this->assertInstanceOf('ZF\\Apigility\\Documentation\\Operation', $operation);
         $statusCodes = $operation->getResponseStatusCodes();
         switch ($operation->getHttpMethod()) {
             case 'GET':
                 $this->assertEquals($docConfig['Test\\V1\\Rpc\\Ping\\Controller']['GET']['description'], $operation->getDescription());
                 $this->assertEquals($docConfig['Test\\V1\\Rpc\\Ping\\Controller']['GET']['request'], $operation->getRequestDescription());
                 $this->assertEquals($docConfig['Test\\V1\\Rpc\\Ping\\Controller']['GET']['response'], $operation->getResponseDescription());
                 $this->assertFalse($operation->requiresAuthorization());
                 $this->assertContainsStatusCodes(['406', '415', '200'], $statusCodes);
                 break;
             default:
                 $this->fail('Unexpected HTTP method encountered: ' . $operation->getHttpMethod());
                 break;
         }
     }
 }
예제 #5
1
 public function testGetFieldsForEntityMethods()
 {
     $api = $this->apiFactory->createApi('Test', 1);
     $service = $this->apiFactory->createService($api, 'EntityFields');
     $this->assertEquals('EntityFields', $service->getName());
     $this->assertCount(1, $service->getFields('PUT'));
 }