Skip to content

Commit

Permalink
[PHP] Improve validation on empty arrays (#7686)
Browse files Browse the repository at this point in the history
* Api should throw exception if an empty array is passed

* Update samples

- bin/php-petstore.sh
- bin/security/php-petstore.sh
  • Loading branch information
ackintosh authored and wing328 committed Feb 22, 2018
1 parent 6a81829 commit 14e1e19
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ use {{invokerPackage}}\ObjectSerializer;
{{#allParams}}
{{#required}}
// verify the required parameter '{{paramName}}' is set
if (${{paramName}} === null) {
if (${{paramName}} === null || (is_array(${{paramName}}) && count(${{paramName}}) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter ${{paramName}} when calling {{operationId}}'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Method | HTTP request | Description
To test class name in snake case

To test class name in snake case

### Example
```php
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function ($exception) {
protected function testSpecialTagsRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling testSpecialTags'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ function ($exception) {
protected function testClientModelRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling testClientModel'
);
Expand Down Expand Up @@ -1535,7 +1535,7 @@ function ($exception) {
protected function testEndpointParametersRequest($number, $double, $pattern_without_delimiter, $byte, $integer = null, $int32 = null, $int64 = null, $float = null, $string = null, $binary = null, $date = null, $date_time = null, $password = null, $callback = null)
{
// verify the required parameter 'number' is set
if ($number === null) {
if ($number === null || (is_array($number) && count($number) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $number when calling testEndpointParameters'
);
Expand All @@ -1548,7 +1548,7 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with
}

// verify the required parameter 'double' is set
if ($double === null) {
if ($double === null || (is_array($double) && count($double) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $double when calling testEndpointParameters'
);
Expand All @@ -1561,7 +1561,7 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with
}

// verify the required parameter 'pattern_without_delimiter' is set
if ($pattern_without_delimiter === null) {
if ($pattern_without_delimiter === null || (is_array($pattern_without_delimiter) && count($pattern_without_delimiter) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $pattern_without_delimiter when calling testEndpointParameters'
);
Expand All @@ -1571,7 +1571,7 @@ protected function testEndpointParametersRequest($number, $double, $pattern_with
}

// verify the required parameter 'byte' is set
if ($byte === null) {
if ($byte === null || (is_array($byte) && count($byte) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $byte when calling testEndpointParameters'
);
Expand Down Expand Up @@ -2161,7 +2161,7 @@ function ($exception) {
protected function testInlineAdditionalPropertiesRequest($param)
{
// verify the required parameter 'param' is set
if ($param === null) {
if ($param === null || (is_array($param) && count($param) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $param when calling testInlineAdditionalProperties'
);
Expand Down Expand Up @@ -2386,13 +2386,13 @@ function ($exception) {
protected function testJsonFormDataRequest($param, $param2)
{
// verify the required parameter 'param' is set
if ($param === null) {
if ($param === null || (is_array($param) && count($param) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $param when calling testJsonFormData'
);
}
// verify the required parameter 'param2' is set
if ($param2 === null) {
if ($param2 === null || (is_array($param2) && count($param2) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $param2 when calling testJsonFormData'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function ($exception) {
protected function testClassnameRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling testClassname'
);
Expand Down
16 changes: 8 additions & 8 deletions samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function ($exception) {
protected function addPetRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling addPet'
);
Expand Down Expand Up @@ -454,7 +454,7 @@ function ($exception) {
protected function deletePetRequest($pet_id, $api_key = null)
{
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $pet_id when calling deletePet'
);
Expand Down Expand Up @@ -724,7 +724,7 @@ function ($exception) {
protected function findPetsByStatusRequest($status)
{
// verify the required parameter 'status' is set
if ($status === null) {
if ($status === null || (is_array($status) && count($status) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $status when calling findPetsByStatus'
);
Expand Down Expand Up @@ -989,7 +989,7 @@ function ($exception) {
protected function findPetsByTagsRequest($tags)
{
// verify the required parameter 'tags' is set
if ($tags === null) {
if ($tags === null || (is_array($tags) && count($tags) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $tags when calling findPetsByTags'
);
Expand Down Expand Up @@ -1254,7 +1254,7 @@ function ($exception) {
protected function getPetByIdRequest($pet_id)
{
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $pet_id when calling getPetById'
);
Expand Down Expand Up @@ -1484,7 +1484,7 @@ function ($exception) {
protected function updatePetRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling updatePet'
);
Expand Down Expand Up @@ -1718,7 +1718,7 @@ function ($exception) {
protected function updatePetWithFormRequest($pet_id, $name = null, $status = null)
{
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $pet_id when calling updatePetWithForm'
);
Expand Down Expand Up @@ -2002,7 +2002,7 @@ function ($exception) {
protected function uploadFileRequest($pet_id, $additional_metadata = null, $file = null)
{
// verify the required parameter 'pet_id' is set
if ($pet_id === null) {
if ($pet_id === null || (is_array($pet_id) && count($pet_id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $pet_id when calling uploadFile'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function ($exception) {
protected function deleteOrderRequest($order_id)
{
// verify the required parameter 'order_id' is set
if ($order_id === null) {
if ($order_id === null || (is_array($order_id) && count($order_id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $order_id when calling deleteOrder'
);
Expand Down Expand Up @@ -735,7 +735,7 @@ function ($exception) {
protected function getOrderByIdRequest($order_id)
{
// verify the required parameter 'order_id' is set
if ($order_id === null) {
if ($order_id === null || (is_array($order_id) && count($order_id) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $order_id when calling getOrderById'
);
Expand Down Expand Up @@ -1004,7 +1004,7 @@ function ($exception) {
protected function placeOrderRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling placeOrder'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function ($exception) {
protected function createUserRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling createUser'
);
Expand Down Expand Up @@ -445,7 +445,7 @@ function ($exception) {
protected function createUsersWithArrayInputRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling createUsersWithArrayInput'
);
Expand Down Expand Up @@ -665,7 +665,7 @@ function ($exception) {
protected function createUsersWithListInputRequest($body)
{
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling createUsersWithListInput'
);
Expand Down Expand Up @@ -885,7 +885,7 @@ function ($exception) {
protected function deleteUserRequest($username)
{
// verify the required parameter 'username' is set
if ($username === null) {
if ($username === null || (is_array($username) && count($username) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $username when calling deleteUser'
);
Expand Down Expand Up @@ -1147,7 +1147,7 @@ function ($exception) {
protected function getUserByNameRequest($username)
{
// verify the required parameter 'username' is set
if ($username === null) {
if ($username === null || (is_array($username) && count($username) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $username when calling getUserByName'
);
Expand Down Expand Up @@ -1414,13 +1414,13 @@ function ($exception) {
protected function loginUserRequest($username, $password)
{
// verify the required parameter 'username' is set
if ($username === null) {
if ($username === null || (is_array($username) && count($username) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $username when calling loginUser'
);
}
// verify the required parameter 'password' is set
if ($password === null) {
if ($password === null || (is_array($password) && count($password) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $password when calling loginUser'
);
Expand Down Expand Up @@ -1856,13 +1856,13 @@ function ($exception) {
protected function updateUserRequest($username, $body)
{
// verify the required parameter 'username' is set
if ($username === null) {
if ($username === null || (is_array($username) && count($username) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $username when calling updateUser'
);
}
// verify the required parameter 'body' is set
if ($body === null) {
if ($body === null || (is_array($body) && count($body) === 0)) {
throw new \InvalidArgumentException(
'Missing the required parameter $body when calling updateUser'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ public function testDefaultValues()
* test invalid argument
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Missing the required parameter $status when calling findPetsByStatus
*/
public function testInvalidArgument()
{
Expand Down

0 comments on commit 14e1e19

Please sign in to comment.