コード例 #1
0
ファイル: PetstoreTest.php プロジェクト: rodsouto/swizzle
 /**
  * Build service description from remote docs.
  * @return ServiceDescription
  */
 public function testServiceBuild()
 {
     $builder = new Swizzle('pets', 'Swagger Pet store');
     //$builder->verbose( STDERR );
     $builder->registerCommandClass('', '\\Loco\\Utils\\Swizzle\\Command\\StrictCommand');
     $builder->setBaseUrl('http://petstore.swagger.wordnik.com/api');
     $builder->build('http://petstore.swagger.wordnik.com/api/api-docs');
     //die( $builder->toJson() );
     $service = $builder->getServiceDescription();
     $this->assertCount(6, $service->getModels());
     $this->assertCount(20, $service->getOperations());
     return $service;
 }
コード例 #2
0
ファイル: loco.php プロジェクト: rodsouto/swizzle
#!/usr/bin/env php
<?php 
/**
 * Swizzle example.
 * Pulls down the Loco API and outputs the Guzzle service description.
 */
// All we need is the Swizzle class.
require __DIR__ . '/../vendor/autoload.php';
use Loco\Utils\Swizzle\Swizzle;
// Intialize service with name and description
$builder = new Swizzle('loco', 'Loco REST API');
// show progress messages in output
$builder->verbose(STDERR);
// Register custom Guzzle response classes - such things are meaningless to Swagger.
// These classes don't have have to exist in this runtime, they just go into the service definition.
$builder->registerResponseClass('exportArchive', '\\Loco\\Http\\Response\\ZipResponse');
// Register custom Guzzle command class to use instead of default OperationCommand
// Passing empty command name, so it is used for all.
$builder->registerCommandClass('', '\\Loco\\Http\\LocoCommand');
// Now we're ready to build from a live endpoint
// This must be a Valid Swagger JSON resource listing.
$builder->build('https://localise.biz/api/swagger');
// export service description to PHP source:
echo $builder->export();
コード例 #3
0
ファイル: petstore.php プロジェクト: rodsouto/swizzle
#!/usr/bin/env php
<?php 
/**
 * Swizzle example.
 * Pulls down the Official Swagger example API and outputs the Guzzle service description.
 * @see http://petstore.swagger.wordnik.com/
 */
// All we need is the Swizzle class.
require __DIR__ . '/../vendor/autoload.php';
use Loco\Utils\Swizzle\Swizzle;
// Intialize service with name and description
$builder = new Swizzle('pets', 'Swagger Pet Store');
// show progress messages in output
$builder->verbose(STDERR);
// Now we're ready to build from a live endpoint
// This must be a Valid Swagger JSON resource listing.
$builder->build('http://petstore.swagger.wordnik.com/api/api-docs');
// export service description to JSON:
echo $builder->toJson();
コード例 #4
0
ファイル: SwizzleTest.php プロジェクト: rodsouto/swizzle
 /**
  * Test failure when response type falls back to an unregistered class
  * @depends testServiceConstruct
  * @expectedException \Exception
  */
 public function testUnregisteredResponseClassFails(Swizzle $builder)
 {
     // mock an operation with a bad response class
     $api = array('path' => '/test/bad_class', 'operations' => array(array('type' => 'BadClass')));
     $builder->addApi($api);
 }