forked from loafle/openapi-generator-original
update php to handle object type and add more test case
This commit is contained in:
@@ -241,6 +241,9 @@ class ObjectSerializer
|
|||||||
$values[] = self::deserialize($value, $subClass);
|
$values[] = self::deserialize($value, $subClass);
|
||||||
}
|
}
|
||||||
$deserialized = $values;
|
$deserialized = $values;
|
||||||
|
} elseif ($class === 'object') {
|
||||||
|
settype($data, 'array');
|
||||||
|
$deserialized = $data;
|
||||||
} elseif ($class === '\DateTime') {
|
} elseif ($class === '\DateTime') {
|
||||||
$deserialized = new \DateTime($data);
|
$deserialized = new \DateTime($data);
|
||||||
} elseif (in_array($class, array({{&primitives}}))) {
|
} elseif (in_array($class, array({{&primitives}}))) {
|
||||||
|
|||||||
@@ -353,6 +353,35 @@
|
|||||||
"name": {
|
"name": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "doggie"
|
"example": "doggie"
|
||||||
|
},
|
||||||
|
"photoUrls": {
|
||||||
|
"type": "array",
|
||||||
|
"xml": {
|
||||||
|
"name": "photoUrl",
|
||||||
|
"wrapped": true
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"tags": {
|
||||||
|
"type": "array",
|
||||||
|
"xml": {
|
||||||
|
"name": "tag",
|
||||||
|
"wrapped": true
|
||||||
|
},
|
||||||
|
"items": {
|
||||||
|
"$ref": "#/definitions/Tag"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "pet status in the store",
|
||||||
|
"enum": [
|
||||||
|
"available",
|
||||||
|
"pending",
|
||||||
|
"sold"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,9 +51,12 @@ class InlineResponse200 implements ArrayAccess
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
static $swaggerTypes = array(
|
static $swaggerTypes = array(
|
||||||
|
'tags' => '\Swagger\Client\Model\Tag[]',
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'category' => 'object',
|
'category' => 'object',
|
||||||
'name' => 'string'
|
'status' => 'string',
|
||||||
|
'name' => 'string',
|
||||||
|
'photo_urls' => 'string[]'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,9 +64,12 @@ class InlineResponse200 implements ArrayAccess
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
static $attributeMap = array(
|
static $attributeMap = array(
|
||||||
|
'tags' => 'tags',
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'category' => 'category',
|
'category' => 'category',
|
||||||
'name' => 'name'
|
'status' => 'status',
|
||||||
|
'name' => 'name',
|
||||||
|
'photo_urls' => 'photoUrls'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,9 +77,12 @@ class InlineResponse200 implements ArrayAccess
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
static $setters = array(
|
static $setters = array(
|
||||||
|
'tags' => 'setTags',
|
||||||
'id' => 'setId',
|
'id' => 'setId',
|
||||||
'category' => 'setCategory',
|
'category' => 'setCategory',
|
||||||
'name' => 'setName'
|
'status' => 'setStatus',
|
||||||
|
'name' => 'setName',
|
||||||
|
'photo_urls' => 'setPhotoUrls'
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,12 +90,21 @@ class InlineResponse200 implements ArrayAccess
|
|||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
static $getters = array(
|
static $getters = array(
|
||||||
|
'tags' => 'getTags',
|
||||||
'id' => 'getId',
|
'id' => 'getId',
|
||||||
'category' => 'getCategory',
|
'category' => 'getCategory',
|
||||||
'name' => 'getName'
|
'status' => 'getStatus',
|
||||||
|
'name' => 'getName',
|
||||||
|
'photo_urls' => 'getPhotoUrls'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $tags
|
||||||
|
* @var \Swagger\Client\Model\Tag[]
|
||||||
|
*/
|
||||||
|
protected $tags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $id
|
* $id
|
||||||
* @var int
|
* @var int
|
||||||
@@ -99,12 +117,24 @@ class InlineResponse200 implements ArrayAccess
|
|||||||
*/
|
*/
|
||||||
protected $category;
|
protected $category;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $status pet status in the store
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $name
|
* $name
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* $photo_urls
|
||||||
|
* @var string[]
|
||||||
|
*/
|
||||||
|
protected $photo_urls;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@@ -113,12 +143,36 @@ class InlineResponse200 implements ArrayAccess
|
|||||||
public function __construct(array $data = null)
|
public function __construct(array $data = null)
|
||||||
{
|
{
|
||||||
if ($data != null) {
|
if ($data != null) {
|
||||||
|
$this->tags = $data["tags"];
|
||||||
$this->id = $data["id"];
|
$this->id = $data["id"];
|
||||||
$this->category = $data["category"];
|
$this->category = $data["category"];
|
||||||
|
$this->status = $data["status"];
|
||||||
$this->name = $data["name"];
|
$this->name = $data["name"];
|
||||||
|
$this->photo_urls = $data["photo_urls"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets tags
|
||||||
|
* @return \Swagger\Client\Model\Tag[]
|
||||||
|
*/
|
||||||
|
public function getTags()
|
||||||
|
{
|
||||||
|
return $this->tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets tags
|
||||||
|
* @param \Swagger\Client\Model\Tag[] $tags
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setTags($tags)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->tags = $tags;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets id
|
* Gets id
|
||||||
* @return int
|
* @return int
|
||||||
@@ -161,6 +215,30 @@ class InlineResponse200 implements ArrayAccess
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets status
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getStatus()
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets status
|
||||||
|
* @param string $status pet status in the store
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setStatus($status)
|
||||||
|
{
|
||||||
|
$allowed_values = array("available", "pending", "sold");
|
||||||
|
if (!in_array($status, $allowed_values)) {
|
||||||
|
throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'available', 'pending', 'sold'");
|
||||||
|
}
|
||||||
|
$this->status = $status;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets name
|
* Gets name
|
||||||
* @return string
|
* @return string
|
||||||
@@ -182,6 +260,27 @@ class InlineResponse200 implements ArrayAccess
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets photo_urls
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getPhotoUrls()
|
||||||
|
{
|
||||||
|
return $this->photo_urls;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets photo_urls
|
||||||
|
* @param string[] $photo_urls
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setPhotoUrls($photo_urls)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->photo_urls = $photo_urls;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if offset exists. False otherwise.
|
* Returns true if offset exists. False otherwise.
|
||||||
* @param integer $offset Offset
|
* @param integer $offset Offset
|
||||||
|
|||||||
@@ -241,6 +241,9 @@ class ObjectSerializer
|
|||||||
$values[] = self::deserialize($value, $subClass);
|
$values[] = self::deserialize($value, $subClass);
|
||||||
}
|
}
|
||||||
$deserialized = $values;
|
$deserialized = $values;
|
||||||
|
} elseif ($class === 'object') {
|
||||||
|
settype($data, 'array');
|
||||||
|
$deserialized = $data;
|
||||||
} elseif ($class === '\DateTime') {
|
} elseif ($class === '\DateTime') {
|
||||||
$deserialized = new \DateTime($data);
|
$deserialized = new \DateTime($data);
|
||||||
} elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) {
|
} elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) {
|
||||||
|
|||||||
@@ -110,8 +110,31 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame($response->getTags()[0]->getId(), $pet_id);
|
$this->assertSame($response->getTags()[0]->getId(), $pet_id);
|
||||||
$this->assertSame($response->getTags()[0]->getName(), 'test php tag');
|
$this->assertSame($response->getTags()[0]->getName(), 'test php tag');
|
||||||
}
|
}
|
||||||
|
|
||||||
// test getPetById with a Pet object (id 10005)
|
// test getPetById with a Pet object (id 10005)
|
||||||
|
public function testGetPetByIdInObject()
|
||||||
|
{
|
||||||
|
// initialize the API client without host
|
||||||
|
$pet_id = 10005; // ID of pet that needs to be fetched
|
||||||
|
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||||
|
$pet_api->getApiClient()->getConfig()->setApiKey('api_key', '111222333444555');
|
||||||
|
// return Pet (inline model)
|
||||||
|
$response = $pet_api->getPetByIdInObject($pet_id);
|
||||||
|
$this->assertInstanceOf('Swagger\Client\Model\InlineResponse200', $response);
|
||||||
|
$this->assertSame($response->getId(), $pet_id);
|
||||||
|
$this->assertSame($response->getName(), 'PHP Unit Test');
|
||||||
|
$this->assertSame($response->getPhotoUrls()[0], 'http://test_php_unit_test.com');
|
||||||
|
|
||||||
|
// category is type "object"
|
||||||
|
$this->assertInternalType('array', $response->getCategory());
|
||||||
|
$this->assertSame($response->getCategory()['id'], $pet_id);
|
||||||
|
$this->assertSame($response->getCategory()['name'], 'test php category');
|
||||||
|
|
||||||
|
$this->assertSame($response->getTags()[0]->getId(), $pet_id);
|
||||||
|
$this->assertSame($response->getTags()[0]->getName(), 'test php tag');
|
||||||
|
}
|
||||||
|
|
||||||
|
// test getPetByIdWithHttpInfo with a Pet object (id 10005)
|
||||||
public function testGetPetByIdWithHttpInfo()
|
public function testGetPetByIdWithHttpInfo()
|
||||||
{
|
{
|
||||||
// initialize the API client without host
|
// initialize the API client without host
|
||||||
|
|||||||
@@ -5,47 +5,61 @@ require_once('autoload.php');
|
|||||||
class StoreApiTest extends \PHPUnit_Framework_TestCase
|
class StoreApiTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
// add a new pet (id 10005) to ensure the pet object is available for all the tests
|
// add a new pet (id 10005) to ensure the pet object is available for all the tests
|
||||||
public static function setUpBeforeClass() {
|
public static function setUpBeforeClass() {
|
||||||
// for error reporting (need to run with php5.3 to get no warning)
|
// for error reporting (need to run with php5.3 to get no warning)
|
||||||
//ini_set('display_errors', 1);
|
//ini_set('display_errors', 1);
|
||||||
//error_reporting(~0);
|
//error_reporting(~0);
|
||||||
// new pet
|
// new pet
|
||||||
$new_pet_id = 10005;
|
$new_pet_id = 10005;
|
||||||
$new_pet = new Swagger\Client\Model\Pet;
|
$new_pet = new Swagger\Client\Model\Pet;
|
||||||
$new_pet->setId($new_pet_id);
|
$new_pet->setId($new_pet_id);
|
||||||
$new_pet->setName("PHP Unit Test");
|
$new_pet->setName("PHP Unit Test");
|
||||||
$new_pet->setStatus("available");
|
$new_pet->setStatus("available");
|
||||||
// new tag
|
// new tag
|
||||||
$tag= new Swagger\Client\Model\Tag;
|
$tag= new Swagger\Client\Model\Tag;
|
||||||
$tag->setId($new_pet_id); // use the same id as pet
|
$tag->setId($new_pet_id); // use the same id as pet
|
||||||
$tag->setName("test php tag");
|
$tag->setName("test php tag");
|
||||||
// new category
|
// new category
|
||||||
$category = new Swagger\Client\Model\Category;
|
$category = new Swagger\Client\Model\Category;
|
||||||
$category->setId($new_pet_id); // use the same id as pet
|
$category->setId($new_pet_id); // use the same id as pet
|
||||||
$category->setName("test php category");
|
$category->setName("test php category");
|
||||||
|
|
||||||
$new_pet->setTags(array($tag));
|
$new_pet->setTags(array($tag));
|
||||||
$new_pet->setCategory($category);
|
$new_pet->setCategory($category);
|
||||||
|
|
||||||
$pet_api = new Swagger\Client\Api\PetAPI();
|
$pet_api = new Swagger\Client\Api\PetAPI();
|
||||||
// add a new pet (model)
|
// add a new pet (model)
|
||||||
$add_response = $pet_api->addPet($new_pet);
|
$add_response = $pet_api->addPet($new_pet);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test get inventory
|
// test get inventory
|
||||||
public function testGetInventory()
|
public function testGetInventory()
|
||||||
{
|
{
|
||||||
// initialize the API client
|
// initialize the API client
|
||||||
$config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2');
|
$config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2');
|
||||||
$api_client = new Swagger\Client\ApiClient($config);
|
$api_client = new Swagger\Client\ApiClient($config);
|
||||||
$store_api = new Swagger\Client\Api\StoreAPI($api_client);
|
$store_api = new Swagger\Client\Api\StoreAPI($api_client);
|
||||||
// get inventory
|
// get inventory
|
||||||
$get_response = $store_api->getInventory();
|
$get_response = $store_api->getInventory();
|
||||||
|
|
||||||
$this->assertInternalType("int", $get_response['available']);
|
$this->assertInternalType("array", $get_response);
|
||||||
|
$this->assertInternalType("int", $get_response['available']);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// test get inventory
|
||||||
|
public function testGetInventoryInObject()
|
||||||
|
{
|
||||||
|
// initialize the API client
|
||||||
|
//$config = (new Swagger\Client\Configuration())->setHost('http://petstore.swagger.io/v2');
|
||||||
|
$api_client = new Swagger\Client\ApiClient();
|
||||||
|
$store_api = new Swagger\Client\Api\StoreAPI($api_client);
|
||||||
|
// get inventory
|
||||||
|
$get_response = $store_api->getInventoryInObject();
|
||||||
|
|
||||||
|
$this->assertInternalType("array", $get_response);
|
||||||
|
$this->assertInternalType("int", $get_response['available']);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user