mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
merged
This commit is contained in:
commit
34072faccd
@ -82,6 +82,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
typeMapping.put("map", "map");
|
typeMapping.put("map", "map");
|
||||||
typeMapping.put("array", "array");
|
typeMapping.put("array", "array");
|
||||||
typeMapping.put("list", "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("composer.mustache", packagePath.replace('/', File.separatorChar), "composer.json"));
|
||||||
supportingFiles.add(new SupportingFile("configuration.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "Configuration.php"));
|
supportingFiles.add(new SupportingFile("configuration.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "Configuration.php"));
|
||||||
|
@ -182,13 +182,10 @@ class ApiClient {
|
|||||||
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
|
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
|
||||||
|
|
||||||
# construct the http header
|
# construct the http header
|
||||||
if ($headerParams != null) {
|
$headerParams = array_merge((array)self::$default_header, (array)$headerParams);
|
||||||
# add default header
|
|
||||||
$headerParams = array_merge((array)self::$default_header, $headerParams);
|
|
||||||
|
|
||||||
foreach ($headerParams as $key => $val) {
|
foreach ($headerParams as $key => $val) {
|
||||||
$headers[] = "$key: $val";
|
$headers[] = "$key: $val";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// form data
|
// form data
|
||||||
@ -292,7 +289,9 @@ class ApiClient {
|
|||||||
} else if (is_object($data)) {
|
} else if (is_object($data)) {
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach (array_keys($data::$swaggerTypes) as $property) {
|
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;
|
$sanitized = $values;
|
||||||
} else {
|
} else {
|
||||||
@ -397,7 +396,7 @@ class ApiClient {
|
|||||||
$deserialized = $values;
|
$deserialized = $values;
|
||||||
} elseif ($class == 'DateTime') {
|
} elseif ($class == 'DateTime') {
|
||||||
$deserialized = new \DateTime($data);
|
$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);
|
settype($data, $class);
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
} else {
|
} else {
|
||||||
|
@ -187,13 +187,10 @@ class ApiClient {
|
|||||||
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
|
$this->updateParamsForAuth($headerParams, $queryParams, $authSettings);
|
||||||
|
|
||||||
# construct the http header
|
# construct the http header
|
||||||
if ($headerParams != null) {
|
$headerParams = array_merge((array)self::$default_header, (array)$headerParams);
|
||||||
# add default header
|
|
||||||
$headerParams = array_merge((array)self::$default_header, $headerParams);
|
|
||||||
|
|
||||||
foreach ($headerParams as $key => $val) {
|
foreach ($headerParams as $key => $val) {
|
||||||
$headers[] = "$key: $val";
|
$headers[] = "$key: $val";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// form data
|
// form data
|
||||||
@ -297,7 +294,9 @@ class ApiClient {
|
|||||||
} else if (is_object($data)) {
|
} else if (is_object($data)) {
|
||||||
$values = array();
|
$values = array();
|
||||||
foreach (array_keys($data::$swaggerTypes) as $property) {
|
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;
|
$sanitized = $values;
|
||||||
} else {
|
} else {
|
||||||
@ -402,7 +401,7 @@ class ApiClient {
|
|||||||
$deserialized = $values;
|
$deserialized = $values;
|
||||||
} elseif ($class == 'DateTime') {
|
} elseif ($class == 'DateTime') {
|
||||||
$deserialized = new \DateTime($data);
|
$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);
|
settype($data, $class);
|
||||||
$deserialized = $data;
|
$deserialized = $data;
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,8 +12,11 @@ require_once('SwaggerClient-php/SwaggerClient.php');
|
|||||||
|
|
||||||
$petId = 10005; // ID of pet that needs to be fetched
|
$petId = 10005; // ID of pet that needs to be fetched
|
||||||
try {
|
try {
|
||||||
|
// get pet by id
|
||||||
//$pet_api = new SwaggerClient\PetAPI($api_client);
|
//$pet_api = new SwaggerClient\PetAPI($api_client);
|
||||||
$pet_api = new SwaggerClient\PetAPI();
|
$pet_api = new SwaggerClient\PetAPI();
|
||||||
|
// test default header
|
||||||
|
$pet_api->getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903");
|
||||||
// return Pet (model)
|
// return Pet (model)
|
||||||
$response = $pet_api->getPetById($petId);
|
$response = $pet_api->getPetById($petId);
|
||||||
var_dump($response);
|
var_dump($response);
|
||||||
@ -21,11 +24,33 @@ try {
|
|||||||
// test upload file (exception)
|
// test upload file (exception)
|
||||||
$upload_response = $pet_api->uploadFile($petId, "test meta", NULL);
|
$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 'Caught exception: ', $e->getMessage(), "\n";
|
||||||
echo 'HTTP response headers: ', $e->getResponseHeaders(), "\n";
|
echo 'HTTP response headers: ', $e->getResponseHeaders(), "\n";
|
||||||
echo 'HTTP response body: ', $e->getResponseBody(), "\n";
|
echo 'HTTP response body: ', $e->getResponseBody(), "\n";
|
||||||
echo 'HTTP status code: ', $e->getCode(), "\n";
|
echo 'HTTP status code: ', $e->getCode(), "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user