2015-04-06 10:03:15 +00:00
|
|
|
<?php
|
2017-04-03 07:47:57 +00:00
|
|
|
require_once(__DIR__ . '/SwaggerClient-php/vendor/autoload.php');
|
2015-04-06 10:03:15 +00:00
|
|
|
|
2015-06-10 13:18:48 +00:00
|
|
|
// show error reporting
|
2015-06-10 15:53:56 +00:00
|
|
|
//ini_set('display_errors', 1);
|
|
|
|
//error_reporting(~0);
|
2015-06-10 13:18:48 +00:00
|
|
|
|
2015-06-27 14:54:37 +00:00
|
|
|
// to debug report
|
|
|
|
print Swagger\Client\Configuration::toDebugReport();
|
|
|
|
|
|
|
|
// to change temp folder path
|
2015-06-26 15:55:51 +00:00
|
|
|
Swagger\Client\Configuration::getDefaultConfiguration()->setTempFolderPath('/var/tmp/php/');
|
2016-01-20 13:42:51 +00:00
|
|
|
// to enable logging
|
|
|
|
Swagger\Client\Configuration::getDefaultConfiguration()->setDebug(true);
|
|
|
|
Swagger\Client\Configuration::getDefaultConfiguration()->setDebugFile('/var/tmp/php_debug.log');
|
2015-05-26 15:20:34 +00:00
|
|
|
|
2015-04-16 15:54:55 +00:00
|
|
|
$petId = 10005; // ID of pet that needs to be fetched
|
2015-04-06 10:03:15 +00:00
|
|
|
try {
|
2015-05-31 01:49:24 +00:00
|
|
|
// get pet by id
|
2015-06-27 14:54:37 +00:00
|
|
|
//$api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2');
|
|
|
|
//$api_client->getConfig()->addDefaultHeader("test1", "value1");
|
|
|
|
//$pet_api = new Swagger\Client\PetAPI($api_client);
|
2017-04-03 07:47:57 +00:00
|
|
|
$config = new \Swagger\Client\Configuration();
|
|
|
|
$petApi = new Swagger\Client\Api\PetApi(null, $config);
|
|
|
|
$config->setTempFolderPath('/var/tmp/php/');
|
2015-05-31 03:17:59 +00:00
|
|
|
// test default header
|
2015-06-26 09:06:30 +00:00
|
|
|
//$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
|
2015-04-06 10:03:15 +00:00
|
|
|
// return Pet (model)
|
2017-04-03 07:47:57 +00:00
|
|
|
$response = $petApi->getPetById($petId);
|
2015-06-17 11:00:29 +00:00
|
|
|
// to test __toString()
|
|
|
|
print ($response);
|
2015-06-02 09:25:38 +00:00
|
|
|
|
2015-05-31 01:49:24 +00:00
|
|
|
// add pet (post json)
|
2017-04-03 07:47:57 +00:00
|
|
|
$newPetId = 10005;
|
|
|
|
$newPet = new Swagger\Client\Model\Pet;
|
|
|
|
$newPet->setId($newPetId);
|
|
|
|
$newPet->setName("PHP Unit Test");
|
2015-05-31 01:49:24 +00:00
|
|
|
// new tag
|
2017-04-03 07:47:57 +00:00
|
|
|
$tag = new Swagger\Client\Model\Tag;
|
|
|
|
$tag->setId($newPetId); // use the same id as pet
|
2015-05-31 01:49:24 +00:00
|
|
|
//$tag->name = "test php tag";
|
|
|
|
// new category
|
2015-06-12 22:01:25 +00:00
|
|
|
$category = new Swagger\Client\Model\Category;
|
2015-06-26 09:06:30 +00:00
|
|
|
$category->setId(10005); // use the same id as pet
|
2015-05-31 01:49:24 +00:00
|
|
|
//$category->name = "test php category";
|
|
|
|
|
2017-04-03 07:47:57 +00:00
|
|
|
$newPet->setTags(array($tag));
|
|
|
|
$newPet->setCategory($category);
|
2015-05-31 01:49:24 +00:00
|
|
|
|
2017-04-03 07:47:57 +00:00
|
|
|
$petApi = new Swagger\Client\Api\PetApi(null, $config);
|
2015-05-31 01:49:24 +00:00
|
|
|
// add a new pet (model)
|
2017-04-03 07:47:57 +00:00
|
|
|
$add_response = $petApi->addPet($newPet);
|
2015-05-31 01:49:24 +00:00
|
|
|
|
2015-06-27 14:54:37 +00:00
|
|
|
// test upload file (should return exception)
|
2017-04-03 07:47:57 +00:00
|
|
|
$upload_response = $petApi->uploadFile($petId, "test meta", NULL);
|
2015-06-10 15:53:56 +00:00
|
|
|
|
2015-06-27 14:54:37 +00:00
|
|
|
} catch (Swagger\Client\ApiException $e) {
|
2015-04-06 10:03:15 +00:00
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n";
|
2017-03-02 08:45:42 +00:00
|
|
|
echo 'HTTP response headers: ', print_r($e->getResponseHeaders(), true), "\n";
|
|
|
|
echo 'HTTP response body: ', print_r($e->getResponseBody(), true), "\n";
|
2015-06-02 09:25:38 +00:00
|
|
|
echo 'HTTP status code: ', $e->getCode(), "\n";
|
2015-04-06 10:03:15 +00:00
|
|
|
}
|