add enum support for model property

This commit is contained in:
wing328 2015-07-02 16:17:36 +08:00
parent 38149173ff
commit 71a22141bf
11 changed files with 93 additions and 41 deletions

View File

@ -76,9 +76,7 @@ class {{classname}} {
// verify the required parameter '{{paramName}}' is set // verify the required parameter '{{paramName}}' is set
if (${{paramName}} === null) { if (${{paramName}} === null) {
throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}'); throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
>>>>>>> temporary folder setting }{{/required}}{{/allParams}}
}
{{/required}}{{/allParams}}
// parse inputs // parse inputs
$resourcePath = "{{path}}"; $resourcePath = "{{path}}";

View File

@ -78,6 +78,10 @@ class {{classname}} implements ArrayAccess {
* @return $this * @return $this
*/ */
public function {{setter}}(${{name}}) { public function {{setter}}(${{name}}) {
{{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
if (!in_array(${{{name}}}, $allowed_values)) {
throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}");
}{{/isEnum}}
$this->{{name}} = ${{name}}; $this->{{name}} = ${{name}};
return $this; return $this;
} }

View File

@ -333,13 +333,11 @@ class PetApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function getPetById($pet_id) { public function getPetById($pet_id) {
// verify the required parameter 'pet_id' is set // verify the required parameter 'pet_id' is set
if ($pet_id === null) { if ($pet_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById');
} }
// parse inputs // parse inputs
$resourcePath = "/pet/{petId}"; $resourcePath = "/pet/{petId}";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);
@ -419,13 +417,11 @@ class PetApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function updatePetWithForm($pet_id, $name, $status) { public function updatePetWithForm($pet_id, $name, $status) {
// verify the required parameter 'pet_id' is set // verify the required parameter 'pet_id' is set
if ($pet_id === null) { if ($pet_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm');
} }
// parse inputs // parse inputs
$resourcePath = "/pet/{petId}"; $resourcePath = "/pet/{petId}";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);
@ -493,13 +489,11 @@ class PetApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function deletePet($api_key, $pet_id) { public function deletePet($api_key, $pet_id) {
// verify the required parameter 'pet_id' is set // verify the required parameter 'pet_id' is set
if ($pet_id === null) { if ($pet_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet');
} }
// parse inputs // parse inputs
$resourcePath = "/pet/{petId}"; $resourcePath = "/pet/{petId}";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);
@ -565,13 +559,11 @@ class PetApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function uploadFile($pet_id, $additional_metadata, $file) { public function uploadFile($pet_id, $additional_metadata, $file) {
// verify the required parameter 'pet_id' is set // verify the required parameter 'pet_id' is set
if ($pet_id === null) { if ($pet_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile');
} }
// parse inputs // parse inputs
$resourcePath = "/pet/{petId}/uploadImage"; $resourcePath = "/pet/{petId}/uploadImage";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);

View File

@ -209,13 +209,11 @@ class StoreApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function getOrderById($order_id) { public function getOrderById($order_id) {
// verify the required parameter 'order_id' is set // verify the required parameter 'order_id' is set
if ($order_id === null) { if ($order_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById');
} }
// parse inputs // parse inputs
$resourcePath = "/store/order/{orderId}"; $resourcePath = "/store/order/{orderId}";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);
@ -283,13 +281,11 @@ class StoreApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function deleteOrder($order_id) { public function deleteOrder($order_id) {
// verify the required parameter 'order_id' is set // verify the required parameter 'order_id' is set
if ($order_id === null) { if ($order_id === null) {
throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder');
} }
// parse inputs // parse inputs
$resourcePath = "/store/order/{orderId}"; $resourcePath = "/store/order/{orderId}";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);

View File

@ -369,13 +369,11 @@ class UserApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function getUserByName($username) { public function getUserByName($username) {
// verify the required parameter 'username' is set // verify the required parameter 'username' is set
if ($username === null) { if ($username === null) {
throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName');
} }
// parse inputs // parse inputs
$resourcePath = "/user/{username}"; $resourcePath = "/user/{username}";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);
@ -444,13 +442,11 @@ class UserApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function updateUser($username, $body) { public function updateUser($username, $body) {
// verify the required parameter 'username' is set // verify the required parameter 'username' is set
if ($username === null) { if ($username === null) {
throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser');
} }
// parse inputs // parse inputs
$resourcePath = "/user/{username}"; $resourcePath = "/user/{username}";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);
@ -512,13 +508,11 @@ class UserApi {
* @throws \Swagger\Client\ApiException on non-2xx response * @throws \Swagger\Client\ApiException on non-2xx response
*/ */
public function deleteUser($username) { public function deleteUser($username) {
// verify the required parameter 'username' is set // verify the required parameter 'username' is set
if ($username === null) { if ($username === null) {
throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser');
} }
// parse inputs // parse inputs
$resourcePath = "/user/{username}"; $resourcePath = "/user/{username}";
$resourcePath = str_replace("{format}", "json", $resourcePath); $resourcePath = str_replace("{format}", "json", $resourcePath);

View File

@ -79,6 +79,7 @@ class Category implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
return $this; return $this;
} }
@ -97,6 +98,7 @@ class Category implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setName($name) { public function setName($name) {
$this->name = $name; $this->name = $name;
return $this; return $this;
} }

View File

@ -111,6 +111,7 @@ class Order implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
return $this; return $this;
} }
@ -129,6 +130,7 @@ class Order implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setPetId($pet_id) { public function setPetId($pet_id) {
$this->pet_id = $pet_id; $this->pet_id = $pet_id;
return $this; return $this;
} }
@ -147,6 +149,7 @@ class Order implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setQuantity($quantity) { public function setQuantity($quantity) {
$this->quantity = $quantity; $this->quantity = $quantity;
return $this; return $this;
} }
@ -165,6 +168,7 @@ class Order implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setShipDate($ship_date) { public function setShipDate($ship_date) {
$this->ship_date = $ship_date; $this->ship_date = $ship_date;
return $this; return $this;
} }
@ -183,6 +187,10 @@ class Order implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setStatus($status) { public function setStatus($status) {
$allowed_values = array("placed", "approved", "delivered");
if (!in_array($status, $allowed_values)) {
throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'placed', 'approved', 'delivered'");
}
$this->status = $status; $this->status = $status;
return $this; return $this;
} }
@ -201,6 +209,7 @@ class Order implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setComplete($complete) { public function setComplete($complete) {
$this->complete = $complete; $this->complete = $complete;
return $this; return $this;
} }

View File

@ -111,6 +111,7 @@ class Pet implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
return $this; return $this;
} }
@ -129,6 +130,7 @@ class Pet implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setCategory($category) { public function setCategory($category) {
$this->category = $category; $this->category = $category;
return $this; return $this;
} }
@ -147,6 +149,7 @@ class Pet implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setName($name) { public function setName($name) {
$this->name = $name; $this->name = $name;
return $this; return $this;
} }
@ -165,6 +168,7 @@ class Pet implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setPhotoUrls($photo_urls) { public function setPhotoUrls($photo_urls) {
$this->photo_urls = $photo_urls; $this->photo_urls = $photo_urls;
return $this; return $this;
} }
@ -183,6 +187,7 @@ class Pet implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setTags($tags) { public function setTags($tags) {
$this->tags = $tags; $this->tags = $tags;
return $this; return $this;
} }
@ -201,6 +206,10 @@ class Pet implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setStatus($status) { 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; $this->status = $status;
return $this; return $this;
} }

View File

@ -79,6 +79,7 @@ class Tag implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
return $this; return $this;
} }
@ -97,6 +98,7 @@ class Tag implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setName($name) { public function setName($name) {
$this->name = $name; $this->name = $name;
return $this; return $this;
} }

View File

@ -127,6 +127,7 @@ class User implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setId($id) { public function setId($id) {
$this->id = $id; $this->id = $id;
return $this; return $this;
} }
@ -145,6 +146,7 @@ class User implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setUsername($username) { public function setUsername($username) {
$this->username = $username; $this->username = $username;
return $this; return $this;
} }
@ -163,6 +165,7 @@ class User implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setFirstName($first_name) { public function setFirstName($first_name) {
$this->first_name = $first_name; $this->first_name = $first_name;
return $this; return $this;
} }
@ -181,6 +184,7 @@ class User implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setLastName($last_name) { public function setLastName($last_name) {
$this->last_name = $last_name; $this->last_name = $last_name;
return $this; return $this;
} }
@ -199,6 +203,7 @@ class User implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setEmail($email) { public function setEmail($email) {
$this->email = $email; $this->email = $email;
return $this; return $this;
} }
@ -217,6 +222,7 @@ class User implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setPassword($password) { public function setPassword($password) {
$this->password = $password; $this->password = $password;
return $this; return $this;
} }
@ -235,6 +241,7 @@ class User implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setPhone($phone) { public function setPhone($phone) {
$this->phone = $phone; $this->phone = $phone;
return $this; return $this;
} }
@ -253,6 +260,7 @@ class User implements ArrayAccess {
* @return $this * @return $this
*/ */
public function setUserStatus($user_status) { public function setUserStatus($user_status) {
$this->user_status = $user_status; $this->user_status = $user_status;
return $this; return $this;
} }

View File

@ -0,0 +1,38 @@
<?php
require_once('autoload.php');
class OrderApiTest extends \PHPUnit_Framework_TestCase
{
// add a new pet (id 10005) to ensure the pet object is available for all the tests
public static function setUpBeforeClass() {
// for error reporting (need to run with php5.3 to get no warning)
//ini_set('display_errors', 1);
//error_reporting(~0);
}
// test get inventory
public function testOrder()
{
// initialize the API client
$order = new Swagger\Client\Model\Order();
$order->setStatus("placed");
$this->assertSame("placed", $order->getStatus());
}
/**
* @expectedException InvalidArgumentException
*/
public function testOrderException()
{
// initialize the API client
$order = new Swagger\Client\Model\Order();
$order->setStatus("invalid_value");
}
}
?>