コード例 #1
0
ファイル: PetstoreTest.php プロジェクト: gossi/swagger
 public function testExternalDocs()
 {
     $filename = __DIR__ . '/fixtures/petstore-with-external-docs.json';
     $swagger = Swagger::fromFile($filename);
     $this->assertEquals($this->fileToArray($filename), $swagger->toArray());
     $external = $swagger->getExternalDocs();
     $this->assertEquals('find more info here', $external->getDescription());
     $this->assertEquals('https://swagger.io/about', $external->getUrl());
     $info = $swagger->getInfo();
     $this->assertEquals('1.0.0', $info->getVersion());
     $this->assertEquals('Swagger Petstore', $info->getTitle());
     $this->assertEquals('A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification', $info->getDescription());
     $this->assertEquals('http://swagger.io/terms/', $info->getTerms());
     $this->assertEquals('1.0.1', $info->setVersion('1.0.1')->getVersion());
     $this->assertEquals('Pets', $info->setTitle('Pets')->getTitle());
     $this->assertEquals('desc', $info->setDescription('desc')->getDescription());
     $this->assertEquals('T-O-S', $info->setTerms('T-O-S')->getTerms());
     $contact = $info->getContact();
     $this->assertEquals('Swagger API Team', $contact->getName());
     $this->assertEquals('*****@*****.**', $contact->getEmail());
     $this->assertEquals('http://swagger.io', $contact->getUrl());
     $this->assertEquals('Swaggers', $contact->setName('Swaggers')->getName());
     $this->assertEquals('*****@*****.**', $contact->setEmail('*****@*****.**')->getEmail());
     $this->assertEquals('https://swagger.io', $contact->setUrl('https://swagger.io')->getUrl());
     $license = $info->getLicense();
     $this->assertEquals('MIT', $license->getName());
     $this->assertEquals('http://github.com/gruntjs/grunt/blob/master/LICENSE-MIT', $license->getUrl());
     $this->assertEquals('APL', $license->setName('APL')->getName());
     $this->assertEquals('https://www.apache.org/licenses/LICENSE-2.0', $license->setUrl('https://www.apache.org/licenses/LICENSE-2.0')->getUrl());
 }
コード例 #2
0
ファイル: SwaggerTest.php プロジェクト: gossi/swagger
 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());
 }
コード例 #3
0
ファイル: CollectionsTest.php プロジェクト: gossi/swagger
 public function testPaths()
 {
     $swagger = new Swagger();
     $paths = $swagger->getPaths();
     $this->assertTrue($paths instanceof Paths);
     $this->assertEquals(0, $paths->size());
     $this->assertFalse($paths->has('/pets'));
     $pets = new Path('/pets');
     $paths->add($pets);
     $this->assertEquals(1, $paths->size());
     $this->assertTrue($paths->has('/pets'));
     $this->assertTrue($paths->get('/pets') instanceof Path);
     $this->assertSame($pets, $paths->get('/pets'));
     $this->assertTrue($paths->contains($pets));
     $this->assertTrue(is_array($paths->toArray()['/pets']));
     $paths->remove('/pets');
     $this->assertEquals(0, $paths->size());
     $this->assertFalse($paths->has('/pets'));
 }
コード例 #4
0
ファイル: SecurityTest.php プロジェクト: gossi/swagger
 public function testSecurityDefinitions()
 {
     $filename = __DIR__ . '/fixtures/security-definitions.json';
     $swagger = Swagger::fromFile($filename);
     $this->assertEquals($this->fileToArray($filename), $swagger->toArray());
     $definitions = $swagger->getSecurityDefinitions();
     $oauth = $definitions->get('OauthSecurity');
     $this->assertEquals('oauth2', $oauth->getType());
     $this->assertEquals('accessCode', $oauth->getFlow());
     $this->assertEquals('https://oauth.simple.api/authorization', $oauth->getAuthorizationUrl());
     $this->assertEquals('https://oauth.simple.api/token', $oauth->getTokenUrl());
     $this->assertEquals(['admin' => 'Admin scope', 'user' => 'User scope'], $oauth->getScopes()->toArray());
     $this->assertTrue($definitions->has('MediaSecurity'));
     $this->assertTrue($definitions->has('LegacySecurity'));
     $definitions->remove('LegacySecurity');
     $this->assertFalse($definitions->has('LegacySecurity'));
 }
コード例 #5
0
ファイル: ModuleInstaller.php プロジェクト: keeko/framework
 private function updateApi(Module $model, ModuleSchema $module, $actions)
 {
     $repo = $this->service->getResourceRepository();
     $filename = sprintf('/packages/%s/api.json', $model->getName());
     if (!$repo->contains($filename)) {
         return;
     }
     // delete every api existent for the given module prior to create the new ones
     ApiQuery::create()->filterByActionId(array_values($actions))->delete();
     // 		$extensions = $this->service->getExtensionRegistry()->getExtensionsByPackage('keeko.api', $model->getName());
     $json = Json::decode($repo->get($filename)->getBody());
     $swagger = new Swagger($json);
     foreach ($swagger->getPaths() as $path) {
         /* @var $path Path */
         foreach (Swagger::$METHODS as $method) {
             if ($path->hasOperation($method)) {
                 $op = $path->getOperation($method);
                 $actionName = $op->getOperationId();
                 if (!isset($actions[$actionName])) {
                     continue;
                 }
                 // find required parameters
                 $required = [];
                 foreach ($op->getParameters() as $param) {
                     /* @var $param Parameter */
                     if ($param->getIn() == 'path' && $param->getRequired()) {
                         $required[] = $param->getName();
                     }
                 }
                 // 					$prefix = isset($extensions[$actionName])
                 // 						? $extensions[$actionName]
                 // 						: $module->getSlug();
                 $prefix = $module->getSlug();
                 $fullPath = str_replace('//', '/', $prefix . '/' . $path->getPath());
                 $api = new Api();
                 $api->setMethod($method);
                 $api->setRoute($fullPath);
                 $api->setActionId($actions[$actionName]);
                 $api->setRequiredParams(implode(',', $required));
                 $api->save();
             }
         }
     }
     $model->setApi(true);
     $model->save();
 }
コード例 #6
0
ファイル: KeekoTest.php プロジェクト: gossi/swagger
 public function testUser()
 {
     $filename = __DIR__ . '/fixtures/keeko-user.json';
     $swagger = Swagger::fromFile($filename);
     $this->assertEquals($this->fileToArray($filename), $swagger->toArray());
 }
コード例 #7
0
 private function loadModules()
 {
     if (!empty($this->modules)) {
         return $this->modules;
     }
     $modules = [];
     $models = ModuleQuery::create()->filterByApi(true)->find();
     $repo = $this->service->getResourceRepository();
     foreach ($models as $model) {
         $package = $this->service->getPackageManager()->getPackage($model->getName());
         $filename = sprintf('/packages/%s/api.json', $model->getName());
         if ($repo->contains($filename)) {
             $routes = [];
             $json = Json::decode($repo->get($filename)->getBody());
             $swagger = new Swagger($json);
             foreach ($swagger->getPaths() as $path) {
                 /* @var $path Path */
                 foreach (Swagger::$METHODS as $method) {
                     if ($path->hasOperation($method)) {
                         $op = $path->getOperation($method);
                         $actionName = $op->getOperationId();
                         $routes[str_replace('-', '_', $actionName)] = ['method' => $method, 'path' => $path->getPath()];
                     }
                 }
             }
             $modules[] = ['title' => $model->getTitle(), 'slug' => $package->getKeeko()->getModule()->getSlug(), 'model' => $model, 'routes' => $routes];
         }
     }
     $this->modules = $modules;
     return $modules;
 }