This commit is contained in:
Tony Tam 2015-06-05 00:51:52 -07:00
commit 34072faccd
4 changed files with 41 additions and 17 deletions

View File

@ -82,6 +82,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("map", "map");
typeMapping.put("array", "array");
typeMapping.put("list", "array");
typeMapping.put("object", "object");
supportingFiles.add(new SupportingFile("composer.mustache", packagePath.replace('/', File.separatorChar), "composer.json"));
supportingFiles.add(new SupportingFile("configuration.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "Configuration.php"));

View File

@ -182,13 +182,10 @@ class ApiClient {
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
# construct the http header
if ($headerParams != null) {
# add default header
$headerParams = array_merge((array)self::$default_header, $headerParams);
$headerParams = array_merge((array)self::$default_header, (array)$headerParams);
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
// form data
@ -292,7 +289,9 @@ class ApiClient {
} else if (is_object($data)) {
$values = array();
foreach (array_keys($data::$swaggerTypes) as $property) {
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$property);
if ($data->$property !== null) {
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$property);
}
}
$sanitized = $values;
} else {
@ -397,7 +396,7 @@ class ApiClient {
$deserialized = $values;
} elseif ($class == 'DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool'))) {
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
settype($data, $class);
$deserialized = $data;
} else {

View File

@ -187,13 +187,10 @@ class ApiClient {
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
# construct the http header
if ($headerParams != null) {
# add default header
$headerParams = array_merge((array)self::$default_header, $headerParams);
$headerParams = array_merge((array)self::$default_header, (array)$headerParams);
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
foreach ($headerParams as $key => $val) {
$headers[] = "$key: $val";
}
// form data
@ -297,7 +294,9 @@ class ApiClient {
} else if (is_object($data)) {
$values = array();
foreach (array_keys($data::$swaggerTypes) as $property) {
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$property);
if ($data->$property !== null) {
$values[$data::$attributeMap[$property]] = $this->sanitizeForSerialization($data->$property);
}
}
$sanitized = $values;
} else {
@ -402,7 +401,7 @@ class ApiClient {
$deserialized = $values;
} elseif ($class == 'DateTime') {
$deserialized = new \DateTime($data);
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool'))) {
} elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool', 'object'))) {
settype($data, $class);
$deserialized = $data;
} else {

View File

@ -12,8 +12,11 @@ require_once('SwaggerClient-php/SwaggerClient.php');
$petId = 10005; // ID of pet that needs to be fetched
try {
// get pet by id
//$pet_api = new SwaggerClient\PetAPI($api_client);
$pet_api = new SwaggerClient\PetAPI();
// test default header
$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
// return Pet (model)
$response = $pet_api->getPetById($petId);
var_dump($response);
@ -21,11 +24,33 @@ try {
// test upload file (exception)
$upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
} catch (SwaggerClient\ApiException $e) {
// add pet (post json)
$new_pet_id = 10005;
$new_pet = new SwaggerClient\models\Pet;
$new_pet->id = $new_pet_id;
$new_pet->name = "PHP Unit Test";
// new tag
$tag= new SwaggerClient\models\Tag;
$tag->id = $new_pet_id; // use the same id as pet
//$tag->name = "test php tag";
// new category
$category = new SwaggerClient\models\Category;
$category->id = 0; // use the same id as pet
//$category->name = "test php category";
$new_pet->tags = array($tag);
$new_pet->category = $category;
$pet_api = new SwaggerClient\PetAPI();
// add a new pet (model)
$add_response = $pet_api->addPet($new_pet);
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
echo 'HTTP response headers: ', $e->getResponseHeaders(), "\n";
echo 'HTTP response body: ', $e->getResponseBody(), "\n";
echo 'HTTP status code: ', $e->getCode(), "\n";
}
?>