diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 5a97244bfe8..6255a59d8e0 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -76,9 +76,7 @@ class {{classname}} { // verify the required parameter '{{paramName}}' is set if (${{paramName}} === null) { throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}'); ->>>>>>> temporary folder setting - } - {{/required}}{{/allParams}} + }{{/required}}{{/allParams}} // parse inputs $resourcePath = "{{path}}"; diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index 9b8307f6ec4..df4ddc0b4f0 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -78,6 +78,10 @@ class {{classname}} implements ArrayAccess { * @return $this */ 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}}; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index 6971e090465..3620252ea51 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -72,7 +72,7 @@ class PetApi { */ public function updatePet($body) { - + // parse inputs $resourcePath = "/pet"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -133,7 +133,7 @@ class PetApi { */ public function addPet($body) { - + // parse inputs $resourcePath = "/pet"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -194,7 +194,7 @@ class PetApi { */ public function findPetsByStatus($status) { - + // parse inputs $resourcePath = "/pet/findByStatus"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -264,7 +264,7 @@ class PetApi { */ public function findPetsByTags($tags) { - + // parse inputs $resourcePath = "/pet/findByTags"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -333,13 +333,11 @@ class PetApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function getPetById($pet_id) { - // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); } - - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -419,13 +417,11 @@ class PetApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function updatePetWithForm($pet_id, $name, $status) { - // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); } - - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -493,13 +489,11 @@ class PetApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function deletePet($api_key, $pet_id) { - // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); } - - + // parse inputs $resourcePath = "/pet/{petId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -565,13 +559,11 @@ class PetApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function uploadFile($pet_id, $additional_metadata, $file) { - // verify the required parameter 'pet_id' is set if ($pet_id === null) { throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); } - - + // parse inputs $resourcePath = "/pet/{petId}/uploadImage"; $resourcePath = str_replace("{format}", "json", $resourcePath); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index a132b3e3ef5..9947628fdf6 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -71,7 +71,7 @@ class StoreApi { */ public function getInventory() { - + // parse inputs $resourcePath = "/store/inventory"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -142,7 +142,7 @@ class StoreApi { */ public function placeOrder($body) { - + // parse inputs $resourcePath = "/store/order"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -209,13 +209,11 @@ class StoreApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function getOrderById($order_id) { - // verify the required parameter 'order_id' is set if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); } - - + // parse inputs $resourcePath = "/store/order/{orderId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -283,13 +281,11 @@ class StoreApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteOrder($order_id) { - // verify the required parameter 'order_id' is set if ($order_id === null) { throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); } - - + // parse inputs $resourcePath = "/store/order/{orderId}"; $resourcePath = str_replace("{format}", "json", $resourcePath); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index 62204e182e7..d0b98f348e3 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -72,7 +72,7 @@ class UserApi { */ public function createUser($body) { - + // parse inputs $resourcePath = "/user"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -130,7 +130,7 @@ class UserApi { */ public function createUsersWithArrayInput($body) { - + // parse inputs $resourcePath = "/user/createWithArray"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -188,7 +188,7 @@ class UserApi { */ public function createUsersWithListInput($body) { - + // parse inputs $resourcePath = "/user/createWithList"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -247,7 +247,7 @@ class UserApi { */ public function loginUser($username, $password) { - + // parse inputs $resourcePath = "/user/login"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -316,7 +316,7 @@ class UserApi { */ public function logoutUser() { - + // parse inputs $resourcePath = "/user/logout"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -369,13 +369,11 @@ class UserApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function getUserByName($username) { - // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); } - - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -444,13 +442,11 @@ class UserApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function updateUser($username, $body) { - // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); } - - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath); @@ -512,13 +508,11 @@ class UserApi { * @throws \Swagger\Client\ApiException on non-2xx response */ public function deleteUser($username) { - // verify the required parameter 'username' is set if ($username === null) { throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); } - - + // parse inputs $resourcePath = "/user/{username}"; $resourcePath = str_replace("{format}", "json", $resourcePath); diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php index eb6603043df..02b3d3cde0f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -79,6 +79,7 @@ class Category implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -97,6 +98,7 @@ class Category implements ArrayAccess { * @return $this */ public function setName($name) { + $this->name = $name; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php index bcea02d9686..9b20b159ab9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -111,6 +111,7 @@ class Order implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -129,6 +130,7 @@ class Order implements ArrayAccess { * @return $this */ public function setPetId($pet_id) { + $this->pet_id = $pet_id; return $this; } @@ -147,6 +149,7 @@ class Order implements ArrayAccess { * @return $this */ public function setQuantity($quantity) { + $this->quantity = $quantity; return $this; } @@ -165,6 +168,7 @@ class Order implements ArrayAccess { * @return $this */ public function setShipDate($ship_date) { + $this->ship_date = $ship_date; return $this; } @@ -183,6 +187,10 @@ class Order implements ArrayAccess { * @return $this */ 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; return $this; } @@ -201,6 +209,7 @@ class Order implements ArrayAccess { * @return $this */ public function setComplete($complete) { + $this->complete = $complete; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php index 2e6947144c9..03c5b173532 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -111,6 +111,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -129,6 +130,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setCategory($category) { + $this->category = $category; return $this; } @@ -147,6 +149,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setName($name) { + $this->name = $name; return $this; } @@ -165,6 +168,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setPhotoUrls($photo_urls) { + $this->photo_urls = $photo_urls; return $this; } @@ -183,6 +187,7 @@ class Pet implements ArrayAccess { * @return $this */ public function setTags($tags) { + $this->tags = $tags; return $this; } @@ -201,6 +206,10 @@ class Pet implements ArrayAccess { * @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; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php index bdd133810c5..279618ac3be 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -79,6 +79,7 @@ class Tag implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -97,6 +98,7 @@ class Tag implements ArrayAccess { * @return $this */ public function setName($name) { + $this->name = $name; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php index 160d93e8f58..7dd45220cf9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -127,6 +127,7 @@ class User implements ArrayAccess { * @return $this */ public function setId($id) { + $this->id = $id; return $this; } @@ -145,6 +146,7 @@ class User implements ArrayAccess { * @return $this */ public function setUsername($username) { + $this->username = $username; return $this; } @@ -163,6 +165,7 @@ class User implements ArrayAccess { * @return $this */ public function setFirstName($first_name) { + $this->first_name = $first_name; return $this; } @@ -181,6 +184,7 @@ class User implements ArrayAccess { * @return $this */ public function setLastName($last_name) { + $this->last_name = $last_name; return $this; } @@ -199,6 +203,7 @@ class User implements ArrayAccess { * @return $this */ public function setEmail($email) { + $this->email = $email; return $this; } @@ -217,6 +222,7 @@ class User implements ArrayAccess { * @return $this */ public function setPassword($password) { + $this->password = $password; return $this; } @@ -235,6 +241,7 @@ class User implements ArrayAccess { * @return $this */ public function setPhone($phone) { + $this->phone = $phone; return $this; } @@ -253,6 +260,7 @@ class User implements ArrayAccess { * @return $this */ public function setUserStatus($user_status) { + $this->user_status = $user_status; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/OrderApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/OrderApiTest.php new file mode 100644 index 00000000000..7672667a235 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/tests/OrderApiTest.php @@ -0,0 +1,38 @@ +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"); + } + +} + +?> +