From c8f2715edcfa668adabfb7dbc28cc7dfaf0aa61e Mon Sep 17 00:00:00 2001 From: abcsun Date: Wed, 4 May 2016 14:52:12 +0800 Subject: [PATCH 1/6] fix the minLength validation --- modules/swagger-codegen/src/main/resources/php/api.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index c0401940b48..0fc827faa90 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -131,7 +131,7 @@ use \{{invokerPackage}}\ObjectSerializer; } {{/maxLength}} {{#minLength}} - if (strlen(${{paramName}}) > {{minLength}}) { + if (strlen(${{paramName}}) < {{minLength}}) { throw new \InvalidArgumentException('invalid length for "${{paramName}}" when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.'); } {{/minLength}} From f4ef2b0325de715f9cb8d1cec6755e8166955e94 Mon Sep 17 00:00:00 2001 From: abcsun Date: Wed, 4 May 2016 16:56:56 +0800 Subject: [PATCH 2/6] add valid function and validation to each setter --- .../src/main/resources/php/model.mustache | 80 ++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index 6f292e854af..f230286a120 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -127,10 +127,60 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA {{/discriminator}} if ($data != null) { - {{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}} - {{/hasMore}}{{/vars}} + {{#vars}} + if (isset($data["{{name}}"])) { + $this->{{name}} = $data["{{name}}"]; + }{{#hasMore}}{{/hasMore}} + {{/vars}} } } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + {{#vars}} + {{#required}} + if ($this->{{name}} === null) { + return false; + } + {{/required}} + {{#hasValidation}} + {{#maxLength}} + if (strlen($this->{{name}}) > {{maxLength}}) { + return false; + } + {{/maxLength}} + {{#minLength}} + if (strlen($this->{{name}}) < {{minLength}}) { + return false; + } + {{/minLength}} + {{#maximum}} + if ($this->{{name}} > {{maximum}}) { + return false; + } + {{/maximum}} + {{#minimum}} + if ($this->{{name}} < {{minimum}}) { + return false; + } + {{/minimum}} + {{#pattern}} + if (!preg_match("{{pattern}}", $this->{{name}})) { + return false; + } + {{/pattern}} + {{/hasValidation}} + {{/vars}} + return true; + } + + {{#vars}} /** * Gets {{name}} @@ -152,6 +202,32 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA 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}} + {{#hasValidation}} + {{#maxLength}} + if (strlen(${{name}}) > {{maxLength}}) { + throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maxLength}}.'); + }{{/maxLength}} + {{#minLength}} + if (strlen(${{name}}) < {{minLength}}) { + throw new \InvalidArgumentException('invalid length for ${{name}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minLength}}.'); + } + {{/minLength}} + {{#maximum}} + if (${{name}} > {{maximum}}) { + throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be smaller than or equal to {{maximum}}.'); + } + {{/maximum}} + {{#minimum}} + if (${{name}} < {{minimum}}) { + throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be bigger than or equal to {{minimum}}.'); + } + {{/minimum}} + {{#pattern}} + if (!preg_match("{{pattern}}", ${{name}})) { + throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{pattern}}.'); + } + {{/pattern}} + {{/hasValidation}} $this->{{name}} = ${{name}}; return $this; } From 22ea2d87e092ee151bbd142f181b9c6624987401 Mon Sep 17 00:00:00 2001 From: abcsun Date: Thu, 5 May 2016 11:41:14 +0800 Subject: [PATCH 3/6] add validation to model --- .../src/main/resources/php/model.mustache | 64 +++- .../petstore/php/SwaggerClient-php/README.md | 2 +- .../php/SwaggerClient-php/lib/Api/FakeApi.php | 2 +- .../SwaggerClient-php/lib/Model/Animal.php | 41 ++- .../lib/Model/ApiResponse.php | 53 +++- .../php/SwaggerClient-php/lib/Model/Cat.php | 35 ++- .../SwaggerClient-php/lib/Model/Category.php | 44 ++- .../php/SwaggerClient-php/lib/Model/Dog.php | 35 ++- .../lib/Model/FormatTest.php | 281 +++++++++++++++++- .../lib/Model/Model200Response.php | 35 ++- .../lib/Model/ModelReturn.php | 35 ++- .../php/SwaggerClient-php/lib/Model/Name.php | 59 +++- .../php/SwaggerClient-php/lib/Model/Order.php | 86 +++++- .../php/SwaggerClient-php/lib/Model/Pet.php | 98 +++++- .../lib/Model/SpecialModelName.php | 35 ++- .../php/SwaggerClient-php/lib/Model/Tag.php | 44 ++- .../php/SwaggerClient-php/lib/Model/User.php | 98 +++++- 17 files changed, 987 insertions(+), 60 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index f230286a120..f4f415cd4a4 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -135,6 +135,51 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA } } + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + {{#vars}}{{#required}} + if ($this->{{name}} === null) { + $invalid_properties[] = "'${{name}}' can't be null"; + }{{/required}} + {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); + if (!in_array($this->{{name}}, $allowed_values))) { + $invalid_properties[] = "invalid value for '${{name}}', must be one of #{allowed_values}."; + }{{/isEnum}} + {{#hasValidation}} + {{#maxLength}} + if (strlen($this->{{name}}) > {{maxLength}}) { + $invalid_properties[] = "invalid value for '${{name}}', the character length must be smaller than or equal to {{{maxLength}}}."; + } + {{/maxLength}} + {{#minLength}} + if (strlen($this->{{name}}) < {{minLength}}) { + $invalid_properties[] = "invalid value for '${{name}}', the character length must be bigger than or equal to {{{minLength}}}."; + } + {{/minLength}} + {{#maximum}} + if ($this->{{name}} > {{maximum}}) { + $invalid_properties[] = "invalid value for '${{name}}', must be smaller than or equal to {{maximum}}."; + } + {{/maximum}} + {{#minimum}} + if ($this->{{name}} < {{minimum}}) { + $invalid_properties[] = "invalid value for '${{name}}', must be bigger than or equal to {{minimum}}."; + } + {{/minimum}} + {{#pattern}} + if (!preg_match("{{pattern}}", $this->{{name}})) { + $invalid_properties[] = "invalid value for '${{name}}', must be conform to the pattern {{pattern}}."; + } + {{/pattern}}{{/hasValidation}}{{/vars}} + return $invalid_properties; + } + /** * validate all the parameters in the model * return true if all passed @@ -143,12 +188,14 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA */ public function valid() { - {{#vars}} - {{#required}} + {{#vars}}{{#required}} if ($this->{{name}} === null) { return false; - } - {{/required}} + }{{/required}} + {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); + if (!in_array($this->{{name}}, $allowed_values))) { + return false; + }{{/isEnum}} {{#hasValidation}} {{#maxLength}} if (strlen($this->{{name}}) > {{maxLength}}) { @@ -174,9 +221,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA if (!preg_match("{{pattern}}", $this->{{name}})) { return false; } - {{/pattern}} - {{/hasValidation}} - {{/vars}} + {{/pattern}}{{/hasValidation}}{{/vars}} return true; } @@ -224,10 +269,9 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA {{/minimum}} {{#pattern}} if (!preg_match("{{pattern}}", ${{name}})) { - throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must conform to the pattern {{pattern}}.'); + throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be conform to the pattern {{pattern}}.'); } - {{/pattern}} - {{/hasValidation}} + {{/pattern}}{{/hasValidation}} $this->{{name}} = ${{name}}; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index e7d9b552b04..c202495f7ac 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -5,7 +5,7 @@ This PHP package is automatically generated by the [Swagger Codegen](https://git - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-04-29T03:01:58.276Z +- Build date: 2016-05-05T03:40:26.342Z - Build package: class io.swagger.codegen.languages.PhpClientCodegen ## Requirements diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index ee15a10d025..8fefa934058 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -198,7 +198,7 @@ class FakeApi if (strlen($password) > 64) { throw new \InvalidArgumentException('invalid length for "$password" when calling FakeApi.testEndpointParameters, must be smaller than or equal to 64.'); } - if (strlen($password) > 10) { + if (strlen($password) < 10) { throw new \InvalidArgumentException('invalid length for "$password" when calling FakeApi.testEndpointParameters, must be bigger than or equal to 10.'); } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php index 3f01e789547..82d29699f8a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php @@ -118,9 +118,47 @@ class Animal implements ArrayAccess $this->{$discrimintor} = static::$swaggerModelName; if ($data != null) { - $this->class_name = $data["class_name"]; + if (isset($data["class_name"])) { + $this->class_name = $data["class_name"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + if ($this->class_name === null) { + $invalid_properties[] = "'$class_name' can't be null"; + } + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + if ($this->class_name === null) { + return false; + } + + + return true; + } + + /** * Gets class_name * @return string @@ -138,6 +176,7 @@ class Animal implements ArrayAccess public function setClassName($class_name) { + $this->class_name = $class_name; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php index 4f467a5aab5..e6e7b7bcd84 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php @@ -133,11 +133,55 @@ class ApiResponse implements ArrayAccess if ($data != null) { - $this->code = $data["code"]; - $this->type = $data["type"]; - $this->message = $data["message"]; + if (isset($data["code"])) { + $this->code = $data["code"]; + } + if (isset($data["type"])) { + $this->type = $data["type"]; + } + if (isset($data["message"])) { + $this->message = $data["message"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + + + + + return true; + } + + /** * Gets code * @return int @@ -155,6 +199,7 @@ class ApiResponse implements ArrayAccess public function setCode($code) { + $this->code = $code; return $this; } @@ -175,6 +220,7 @@ class ApiResponse implements ArrayAccess public function setType($type) { + $this->type = $type; return $this; } @@ -195,6 +241,7 @@ class ApiResponse implements ArrayAccess public function setMessage($message) { + $this->message = $message; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php index e0eaf7a106d..4bc0f89d9e2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php @@ -115,9 +115,41 @@ class Cat extends Animal implements ArrayAccess parent::__construct($data); if ($data != null) { - $this->declawed = $data["declawed"]; + if (isset($data["declawed"])) { + $this->declawed = $data["declawed"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + return true; + } + + /** * Gets declawed * @return bool @@ -135,6 +167,7 @@ class Cat extends Animal implements ArrayAccess public function setDeclawed($declawed) { + $this->declawed = $declawed; return $this; } 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 fb6eed3af29..55b391feabd 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -124,10 +124,48 @@ class Category implements ArrayAccess if ($data != null) { - $this->id = $data["id"]; - $this->name = $data["name"]; + if (isset($data["id"])) { + $this->id = $data["id"]; + } + if (isset($data["name"])) { + $this->name = $data["name"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + + + return true; + } + + /** * Gets id * @return int @@ -145,6 +183,7 @@ class Category implements ArrayAccess public function setId($id) { + $this->id = $id; return $this; } @@ -165,6 +204,7 @@ class Category implements ArrayAccess public function setName($name) { + $this->name = $name; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php index 6fd43d3a944..d092850ab79 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php @@ -115,9 +115,41 @@ class Dog extends Animal implements ArrayAccess parent::__construct($data); if ($data != null) { - $this->breed = $data["breed"]; + if (isset($data["breed"])) { + $this->breed = $data["breed"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + return true; + } + + /** * Gets breed * @return string @@ -135,6 +167,7 @@ class Dog extends Animal implements ArrayAccess public function setBreed($breed) { + $this->breed = $breed; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php index 7bfe30c0ef7..6f5c75d28eb 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -214,20 +214,220 @@ class FormatTest implements ArrayAccess if ($data != null) { - $this->integer = $data["integer"]; - $this->int32 = $data["int32"]; - $this->int64 = $data["int64"]; - $this->number = $data["number"]; - $this->float = $data["float"]; - $this->double = $data["double"]; - $this->string = $data["string"]; - $this->byte = $data["byte"]; - $this->binary = $data["binary"]; - $this->date = $data["date"]; - $this->date_time = $data["date_time"]; - $this->password = $data["password"]; + if (isset($data["integer"])) { + $this->integer = $data["integer"]; + } + if (isset($data["int32"])) { + $this->int32 = $data["int32"]; + } + if (isset($data["int64"])) { + $this->int64 = $data["int64"]; + } + if (isset($data["number"])) { + $this->number = $data["number"]; + } + if (isset($data["float"])) { + $this->float = $data["float"]; + } + if (isset($data["double"])) { + $this->double = $data["double"]; + } + if (isset($data["string"])) { + $this->string = $data["string"]; + } + if (isset($data["byte"])) { + $this->byte = $data["byte"]; + } + if (isset($data["binary"])) { + $this->binary = $data["binary"]; + } + if (isset($data["date"])) { + $this->date = $data["date"]; + } + if (isset($data["date_time"])) { + $this->date_time = $data["date_time"]; + } + if (isset($data["password"])) { + $this->password = $data["password"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + if ($this->integer > 100.0) { + $invalid_properties[] = "invalid value for '$integer', must be smaller than or equal to 100.0."; + } + if ($this->integer < 10.0) { + $invalid_properties[] = "invalid value for '$integer', must be bigger than or equal to 10.0."; + } + + + if ($this->int32 > 200.0) { + $invalid_properties[] = "invalid value for '$int32', must be smaller than or equal to 200.0."; + } + if ($this->int32 < 20.0) { + $invalid_properties[] = "invalid value for '$int32', must be bigger than or equal to 20.0."; + } + + + + if ($this->number === null) { + $invalid_properties[] = "'$number' can't be null"; + } + + if ($this->number > 543.2) { + $invalid_properties[] = "invalid value for '$number', must be smaller than or equal to 543.2."; + } + if ($this->number < 32.1) { + $invalid_properties[] = "invalid value for '$number', must be bigger than or equal to 32.1."; + } + + + if ($this->float > 987.6) { + $invalid_properties[] = "invalid value for '$float', must be smaller than or equal to 987.6."; + } + if ($this->float < 54.3) { + $invalid_properties[] = "invalid value for '$float', must be bigger than or equal to 54.3."; + } + + + if ($this->double > 123.4) { + $invalid_properties[] = "invalid value for '$double', must be smaller than or equal to 123.4."; + } + if ($this->double < 67.8) { + $invalid_properties[] = "invalid value for '$double', must be bigger than or equal to 67.8."; + } + + + if (!preg_match("/[a-z]/i", $this->string)) { + $invalid_properties[] = "invalid value for '$string', must be conform to the pattern /[a-z]/i."; + } + + if ($this->byte === null) { + $invalid_properties[] = "'$byte' can't be null"; + } + + + + + if ($this->date === null) { + $invalid_properties[] = "'$date' can't be null"; + } + + + + + if ($this->password === null) { + $invalid_properties[] = "'$password' can't be null"; + } + + if (strlen($this->password) > 64) { + $invalid_properties[] = "invalid value for '$password', the character length must be smaller than or equal to 64."; + } + if (strlen($this->password) < 10) { + $invalid_properties[] = "invalid value for '$password', the character length must be bigger than or equal to 10."; + } + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + if ($this->integer > 100.0) { + return false; + } + if ($this->integer < 10.0) { + return false; + } + + + if ($this->int32 > 200.0) { + return false; + } + if ($this->int32 < 20.0) { + return false; + } + + + + if ($this->number === null) { + return false; + } + + if ($this->number > 543.2) { + return false; + } + if ($this->number < 32.1) { + return false; + } + + + if ($this->float > 987.6) { + return false; + } + if ($this->float < 54.3) { + return false; + } + + + if ($this->double > 123.4) { + return false; + } + if ($this->double < 67.8) { + return false; + } + + + if (!preg_match("/[a-z]/i", $this->string)) { + return false; + } + + if ($this->byte === null) { + return false; + } + + + + + if ($this->date === null) { + return false; + } + + + + + if ($this->password === null) { + return false; + } + + if (strlen($this->password) > 64) { + return false; + } + if (strlen($this->password) < 10) { + return false; + } + + return true; + } + + /** * Gets integer * @return int @@ -245,6 +445,14 @@ class FormatTest implements ArrayAccess public function setInteger($integer) { + + if ($integer > 100.0) { + throw new \InvalidArgumentException('invalid value for $integer when calling FormatTest., must be smaller than or equal to 100.0.'); + } + if ($integer < 10.0) { + throw new \InvalidArgumentException('invalid value for $integer when calling FormatTest., must be bigger than or equal to 10.0.'); + } + $this->integer = $integer; return $this; } @@ -265,6 +473,14 @@ class FormatTest implements ArrayAccess public function setInt32($int32) { + + if ($int32 > 200.0) { + throw new \InvalidArgumentException('invalid value for $int32 when calling FormatTest., must be smaller than or equal to 200.0.'); + } + if ($int32 < 20.0) { + throw new \InvalidArgumentException('invalid value for $int32 when calling FormatTest., must be bigger than or equal to 20.0.'); + } + $this->int32 = $int32; return $this; } @@ -285,6 +501,7 @@ class FormatTest implements ArrayAccess public function setInt64($int64) { + $this->int64 = $int64; return $this; } @@ -305,6 +522,14 @@ class FormatTest implements ArrayAccess public function setNumber($number) { + + if ($number > 543.2) { + throw new \InvalidArgumentException('invalid value for $number when calling FormatTest., must be smaller than or equal to 543.2.'); + } + if ($number < 32.1) { + throw new \InvalidArgumentException('invalid value for $number when calling FormatTest., must be bigger than or equal to 32.1.'); + } + $this->number = $number; return $this; } @@ -325,6 +550,14 @@ class FormatTest implements ArrayAccess public function setFloat($float) { + + if ($float > 987.6) { + throw new \InvalidArgumentException('invalid value for $float when calling FormatTest., must be smaller than or equal to 987.6.'); + } + if ($float < 54.3) { + throw new \InvalidArgumentException('invalid value for $float when calling FormatTest., must be bigger than or equal to 54.3.'); + } + $this->float = $float; return $this; } @@ -345,6 +578,14 @@ class FormatTest implements ArrayAccess public function setDouble($double) { + + if ($double > 123.4) { + throw new \InvalidArgumentException('invalid value for $double when calling FormatTest., must be smaller than or equal to 123.4.'); + } + if ($double < 67.8) { + throw new \InvalidArgumentException('invalid value for $double when calling FormatTest., must be bigger than or equal to 67.8.'); + } + $this->double = $double; return $this; } @@ -365,6 +606,11 @@ class FormatTest implements ArrayAccess public function setString($string) { + + if (!preg_match("/[a-z]/i", $string)) { + throw new \InvalidArgumentException('invalid value for $string when calling FormatTest., must be conform to the pattern /[a-z]/i.'); + } + $this->string = $string; return $this; } @@ -385,6 +631,7 @@ class FormatTest implements ArrayAccess public function setByte($byte) { + $this->byte = $byte; return $this; } @@ -405,6 +652,7 @@ class FormatTest implements ArrayAccess public function setBinary($binary) { + $this->binary = $binary; return $this; } @@ -425,6 +673,7 @@ class FormatTest implements ArrayAccess public function setDate($date) { + $this->date = $date; return $this; } @@ -445,6 +694,7 @@ class FormatTest implements ArrayAccess public function setDateTime($date_time) { + $this->date_time = $date_time; return $this; } @@ -465,6 +715,13 @@ class FormatTest implements ArrayAccess public function setPassword($password) { + if (strlen($password) > 64) { + throw new \InvalidArgumentException('invalid length for $password when calling FormatTest., must be smaller than or equal to 64.'); + } + if (strlen($password) < 10) { + throw new \InvalidArgumentException('invalid length for $password when calling FormatTest., must be bigger than or equal to 10.'); + } + $this->password = $password; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php index 8d62f9531ec..1ee9011b8f7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php @@ -115,9 +115,41 @@ class Model200Response implements ArrayAccess if ($data != null) { - $this->name = $data["name"]; + if (isset($data["name"])) { + $this->name = $data["name"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + return true; + } + + /** * Gets name * @return int @@ -135,6 +167,7 @@ class Model200Response implements ArrayAccess public function setName($name) { + $this->name = $name; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php index d4660e118fd..d15f82a5057 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php @@ -115,9 +115,41 @@ class ModelReturn implements ArrayAccess if ($data != null) { - $this->return = $data["return"]; + if (isset($data["return"])) { + $this->return = $data["return"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + return true; + } + + /** * Gets return * @return int @@ -135,6 +167,7 @@ class ModelReturn implements ArrayAccess public function setReturn($return) { + $this->return = $return; return $this; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php index 9e1c4b92762..991ab945b4e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php @@ -133,11 +133,61 @@ class Name implements ArrayAccess if ($data != null) { - $this->name = $data["name"]; - $this->snake_case = $data["snake_case"]; - $this->property = $data["property"]; + if (isset($data["name"])) { + $this->name = $data["name"]; + } + if (isset($data["snake_case"])) { + $this->snake_case = $data["snake_case"]; + } + if (isset($data["property"])) { + $this->property = $data["property"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + if ($this->name === null) { + $invalid_properties[] = "'$name' can't be null"; + } + + + + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + if ($this->name === null) { + return false; + } + + + + + + + return true; + } + + /** * Gets name * @return int @@ -155,6 +205,7 @@ class Name implements ArrayAccess public function setName($name) { + $this->name = $name; return $this; } @@ -175,6 +226,7 @@ class Name implements ArrayAccess public function setSnakeCase($snake_case) { + $this->snake_case = $snake_case; return $this; } @@ -195,6 +247,7 @@ class Name implements ArrayAccess public function setProperty($property) { + $this->property = $property; 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 7ee5c124d2c..a7b6b22f4c7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -160,14 +160,82 @@ class Order implements ArrayAccess if ($data != null) { - $this->id = $data["id"]; - $this->pet_id = $data["pet_id"]; - $this->quantity = $data["quantity"]; - $this->ship_date = $data["ship_date"]; - $this->status = $data["status"]; - $this->complete = $data["complete"]; + if (isset($data["id"])) { + $this->id = $data["id"]; + } + if (isset($data["pet_id"])) { + $this->pet_id = $data["pet_id"]; + } + if (isset($data["quantity"])) { + $this->quantity = $data["quantity"]; + } + if (isset($data["ship_date"])) { + $this->ship_date = $data["ship_date"]; + } + if (isset($data["status"])) { + $this->status = $data["status"]; + } + if (isset($data["complete"])) { + $this->complete = $data["complete"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + + + + + + + $allowed_values = array("placed", "approved", "delivered"); + if (!in_array($this->status, $allowed_values))) { + $invalid_properties[] = "invalid value for '$status', must be one of #{allowed_values}."; + } + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + + + + + + + $allowed_values = array("placed", "approved", "delivered"); + if (!in_array($this->status, $allowed_values))) { + return false; + } + + + + return true; + } + + /** * Gets id * @return int @@ -185,6 +253,7 @@ class Order implements ArrayAccess public function setId($id) { + $this->id = $id; return $this; } @@ -205,6 +274,7 @@ class Order implements ArrayAccess public function setPetId($pet_id) { + $this->pet_id = $pet_id; return $this; } @@ -225,6 +295,7 @@ class Order implements ArrayAccess public function setQuantity($quantity) { + $this->quantity = $quantity; return $this; } @@ -245,6 +316,7 @@ class Order implements ArrayAccess public function setShipDate($ship_date) { + $this->ship_date = $ship_date; return $this; } @@ -268,6 +340,7 @@ class Order implements ArrayAccess 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; } @@ -288,6 +361,7 @@ class Order implements ArrayAccess 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 3a9e46cd3fb..319d23a839e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -160,14 +160,94 @@ class Pet implements ArrayAccess if ($data != null) { - $this->id = $data["id"]; - $this->category = $data["category"]; - $this->name = $data["name"]; - $this->photo_urls = $data["photo_urls"]; - $this->tags = $data["tags"]; - $this->status = $data["status"]; + if (isset($data["id"])) { + $this->id = $data["id"]; + } + if (isset($data["category"])) { + $this->category = $data["category"]; + } + if (isset($data["name"])) { + $this->name = $data["name"]; + } + if (isset($data["photo_urls"])) { + $this->photo_urls = $data["photo_urls"]; + } + if (isset($data["tags"])) { + $this->tags = $data["tags"]; + } + if (isset($data["status"])) { + $this->status = $data["status"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + + + if ($this->name === null) { + $invalid_properties[] = "'$name' can't be null"; + } + + + if ($this->photo_urls === null) { + $invalid_properties[] = "'$photo_urls' can't be null"; + } + + + + + $allowed_values = array("available", "pending", "sold"); + if (!in_array($this->status, $allowed_values))) { + $invalid_properties[] = "invalid value for '$status', must be one of #{allowed_values}."; + } + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + + + if ($this->name === null) { + return false; + } + + + if ($this->photo_urls === null) { + return false; + } + + + + + $allowed_values = array("available", "pending", "sold"); + if (!in_array($this->status, $allowed_values))) { + return false; + } + + return true; + } + + /** * Gets id * @return int @@ -185,6 +265,7 @@ class Pet implements ArrayAccess public function setId($id) { + $this->id = $id; return $this; } @@ -205,6 +286,7 @@ class Pet implements ArrayAccess public function setCategory($category) { + $this->category = $category; return $this; } @@ -225,6 +307,7 @@ class Pet implements ArrayAccess public function setName($name) { + $this->name = $name; return $this; } @@ -245,6 +328,7 @@ class Pet implements ArrayAccess public function setPhotoUrls($photo_urls) { + $this->photo_urls = $photo_urls; return $this; } @@ -265,6 +349,7 @@ class Pet implements ArrayAccess public function setTags($tags) { + $this->tags = $tags; return $this; } @@ -288,6 +373,7 @@ class Pet implements ArrayAccess 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/SpecialModelName.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php index fb748811cf2..200470d99d2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php @@ -115,9 +115,41 @@ class SpecialModelName implements ArrayAccess if ($data != null) { - $this->special_property_name = $data["special_property_name"]; + if (isset($data["special_property_name"])) { + $this->special_property_name = $data["special_property_name"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + return true; + } + + /** * Gets special_property_name * @return int @@ -135,6 +167,7 @@ class SpecialModelName implements ArrayAccess public function setSpecialPropertyName($special_property_name) { + $this->special_property_name = $special_property_name; 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 4bb56401c48..e493bdfd3e3 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -124,10 +124,48 @@ class Tag implements ArrayAccess if ($data != null) { - $this->id = $data["id"]; - $this->name = $data["name"]; + if (isset($data["id"])) { + $this->id = $data["id"]; + } + if (isset($data["name"])) { + $this->name = $data["name"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + + + return true; + } + + /** * Gets id * @return int @@ -145,6 +183,7 @@ class Tag implements ArrayAccess public function setId($id) { + $this->id = $id; return $this; } @@ -165,6 +204,7 @@ class Tag implements ArrayAccess 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 da9cc20ff4c..3b09cea0fd2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -178,16 +178,90 @@ class User implements ArrayAccess if ($data != null) { - $this->id = $data["id"]; - $this->username = $data["username"]; - $this->first_name = $data["first_name"]; - $this->last_name = $data["last_name"]; - $this->email = $data["email"]; - $this->password = $data["password"]; - $this->phone = $data["phone"]; - $this->user_status = $data["user_status"]; + if (isset($data["id"])) { + $this->id = $data["id"]; + } + if (isset($data["username"])) { + $this->username = $data["username"]; + } + if (isset($data["first_name"])) { + $this->first_name = $data["first_name"]; + } + if (isset($data["last_name"])) { + $this->last_name = $data["last_name"]; + } + if (isset($data["email"])) { + $this->email = $data["email"]; + } + if (isset($data["password"])) { + $this->password = $data["password"]; + } + if (isset($data["phone"])) { + $this->phone = $data["phone"]; + } + if (isset($data["user_status"])) { + $this->user_status = $data["user_status"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + + + + + + + + + + + + + + + + + + return $invalid_properties; + } + + /** + * validate all the parameters in the model + * return true if all passed + * + * @return bool [description] + */ + public function valid() + { + + + + + + + + + + + + + + + + + + return true; + } + + /** * Gets id * @return int @@ -205,6 +279,7 @@ class User implements ArrayAccess public function setId($id) { + $this->id = $id; return $this; } @@ -225,6 +300,7 @@ class User implements ArrayAccess public function setUsername($username) { + $this->username = $username; return $this; } @@ -245,6 +321,7 @@ class User implements ArrayAccess public function setFirstName($first_name) { + $this->first_name = $first_name; return $this; } @@ -265,6 +342,7 @@ class User implements ArrayAccess public function setLastName($last_name) { + $this->last_name = $last_name; return $this; } @@ -285,6 +363,7 @@ class User implements ArrayAccess public function setEmail($email) { + $this->email = $email; return $this; } @@ -305,6 +384,7 @@ class User implements ArrayAccess public function setPassword($password) { + $this->password = $password; return $this; } @@ -325,6 +405,7 @@ class User implements ArrayAccess public function setPhone($phone) { + $this->phone = $phone; return $this; } @@ -345,6 +426,7 @@ class User implements ArrayAccess public function setUserStatus($user_status) { + $this->user_status = $user_status; return $this; } From df1d36cf4799d32d0045ebf4f5d3646fcaf81929 Mon Sep 17 00:00:00 2001 From: abcsun Date: Sat, 7 May 2016 15:55:38 +0800 Subject: [PATCH 4/6] modify the properties from container array --- .../src/main/resources/php/model.mustache | 28 ++++---- .../petstore/php/SwaggerClient-php/README.md | 2 +- .../SwaggerClient-php/lib/Model/Animal.php | 4 +- .../SwaggerClient-php/lib/Model/EnumTest.php | 12 ++-- .../lib/Model/FormatTest.php | 68 +++++++++---------- .../php/SwaggerClient-php/lib/Model/Name.php | 4 +- .../php/SwaggerClient-php/lib/Model/Order.php | 4 +- .../php/SwaggerClient-php/lib/Model/Pet.php | 12 ++-- 8 files changed, 67 insertions(+), 67 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index c62a7a14e43..34aaa63393c 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -164,36 +164,36 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple { $invalid_properties = array(); {{#vars}}{{#required}} - if ($this->{{name}} === null) { + if ($this->container['{{name}}'] === null) { $invalid_properties[] = "'${{name}}' can't be null"; }{{/required}} {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); - if (!in_array($this->{{name}}, $allowed_values))) { + if (!in_array($this->container['{{name}}'], $allowed_values))) { $invalid_properties[] = "invalid value for '${{name}}', must be one of #{allowed_values}."; }{{/isEnum}} {{#hasValidation}} {{#maxLength}} - if (strlen($this->{{name}}) > {{maxLength}}) { + if (strlen($this->container['{{name}}']) > {{maxLength}}) { $invalid_properties[] = "invalid value for '${{name}}', the character length must be smaller than or equal to {{{maxLength}}}."; } {{/maxLength}} {{#minLength}} - if (strlen($this->{{name}}) < {{minLength}}) { + if (strlen($this->container['{{name}}']) < {{minLength}}) { $invalid_properties[] = "invalid value for '${{name}}', the character length must be bigger than or equal to {{{minLength}}}."; } {{/minLength}} {{#maximum}} - if ($this->{{name}} > {{maximum}}) { + if ($this->container['{{name}}'] > {{maximum}}) { $invalid_properties[] = "invalid value for '${{name}}', must be smaller than or equal to {{maximum}}."; } {{/maximum}} {{#minimum}} - if ($this->{{name}} < {{minimum}}) { + if ($this->container['{{name}}'] < {{minimum}}) { $invalid_properties[] = "invalid value for '${{name}}', must be bigger than or equal to {{minimum}}."; } {{/minimum}} {{#pattern}} - if (!preg_match("{{pattern}}", $this->{{name}})) { + if (!preg_match("{{pattern}}", $this->container['{{name}}'])) { $invalid_properties[] = "invalid value for '${{name}}', must be conform to the pattern {{pattern}}."; } {{/pattern}}{{/hasValidation}}{{/vars}} @@ -209,36 +209,36 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple public function valid() { {{#vars}}{{#required}} - if ($this->{{name}} === null) { + if ($this->container['{{name}}'] === null) { return false; }{{/required}} {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); - if (!in_array($this->{{name}}, $allowed_values))) { + if (!in_array($this->container['{{name}}'], $allowed_values))) { return false; }{{/isEnum}} {{#hasValidation}} {{#maxLength}} - if (strlen($this->{{name}}) > {{maxLength}}) { + if (strlen($this->container['{{name}}']) > {{maxLength}}) { return false; } {{/maxLength}} {{#minLength}} - if (strlen($this->{{name}}) < {{minLength}}) { + if (strlen($this->container['{{name}}']) < {{minLength}}) { return false; } {{/minLength}} {{#maximum}} - if ($this->{{name}} > {{maximum}}) { + if ($this->container['{{name}}'] > {{maximum}}) { return false; } {{/maximum}} {{#minimum}} - if ($this->{{name}} < {{minimum}}) { + if ($this->container['{{name}}'] < {{minimum}}) { return false; } {{/minimum}} {{#pattern}} - if (!preg_match("{{pattern}}", $this->{{name}})) { + if (!preg_match("{{pattern}}", $this->container['{{name}}'])) { return false; } {{/pattern}}{{/hasValidation}}{{/vars}} diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index e581145b26d..5917dc8a7d9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -5,7 +5,7 @@ This PHP package is automatically generated by the [Swagger Codegen](https://git - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-05-07T07:39:11.271Z +- Build date: 2016-05-07T07:50:05.452Z - Build package: class io.swagger.codegen.languages.PhpClientCodegen ## Requirements diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php index 032d74d40e5..7c25695056e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php @@ -143,7 +143,7 @@ class Animal implements ArrayAccess { $invalid_properties = array(); - if ($this->class_name === null) { + if ($this->container['class_name'] === null) { $invalid_properties[] = "'$class_name' can't be null"; } @@ -160,7 +160,7 @@ class Animal implements ArrayAccess public function valid() { - if ($this->class_name === null) { + if ($this->container['class_name'] === null) { return false; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php index 2498f862968..dce42791a04 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php @@ -206,17 +206,17 @@ class EnumTest implements ArrayAccess $invalid_properties = array(); $allowed_values = array("UPPER", "lower"); - if (!in_array($this->enum_string, $allowed_values))) { + if (!in_array($this->container['enum_string'], $allowed_values))) { $invalid_properties[] = "invalid value for '$enum_string', must be one of #{allowed_values}."; } $allowed_values = array("1", "-1"); - if (!in_array($this->enum_integer, $allowed_values))) { + if (!in_array($this->container['enum_integer'], $allowed_values))) { $invalid_properties[] = "invalid value for '$enum_integer', must be one of #{allowed_values}."; } $allowed_values = array("1.1", "-1.2"); - if (!in_array($this->enum_number, $allowed_values))) { + if (!in_array($this->container['enum_number'], $allowed_values))) { $invalid_properties[] = "invalid value for '$enum_number', must be one of #{allowed_values}."; } @@ -233,17 +233,17 @@ class EnumTest implements ArrayAccess { $allowed_values = array("UPPER", "lower"); - if (!in_array($this->enum_string, $allowed_values))) { + if (!in_array($this->container['enum_string'], $allowed_values))) { return false; } $allowed_values = array("1", "-1"); - if (!in_array($this->enum_integer, $allowed_values))) { + if (!in_array($this->container['enum_integer'], $allowed_values))) { return false; } $allowed_values = array("1.1", "-1.2"); - if (!in_array($this->enum_number, $allowed_values))) { + if (!in_array($this->container['enum_number'], $allowed_values))) { return false; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php index d34dd167d32..7ab03733625 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -297,63 +297,63 @@ class FormatTest implements ArrayAccess $invalid_properties = array(); - if ($this->integer > 100.0) { + if ($this->container['integer'] > 100.0) { $invalid_properties[] = "invalid value for '$integer', must be smaller than or equal to 100.0."; } - if ($this->integer < 10.0) { + if ($this->container['integer'] < 10.0) { $invalid_properties[] = "invalid value for '$integer', must be bigger than or equal to 10.0."; } - if ($this->int32 > 200.0) { + if ($this->container['int32'] > 200.0) { $invalid_properties[] = "invalid value for '$int32', must be smaller than or equal to 200.0."; } - if ($this->int32 < 20.0) { + if ($this->container['int32'] < 20.0) { $invalid_properties[] = "invalid value for '$int32', must be bigger than or equal to 20.0."; } - if ($this->number === null) { + if ($this->container['number'] === null) { $invalid_properties[] = "'$number' can't be null"; } - if ($this->number > 543.2) { + if ($this->container['number'] > 543.2) { $invalid_properties[] = "invalid value for '$number', must be smaller than or equal to 543.2."; } - if ($this->number < 32.1) { + if ($this->container['number'] < 32.1) { $invalid_properties[] = "invalid value for '$number', must be bigger than or equal to 32.1."; } - if ($this->float > 987.6) { + if ($this->container['float'] > 987.6) { $invalid_properties[] = "invalid value for '$float', must be smaller than or equal to 987.6."; } - if ($this->float < 54.3) { + if ($this->container['float'] < 54.3) { $invalid_properties[] = "invalid value for '$float', must be bigger than or equal to 54.3."; } - if ($this->double > 123.4) { + if ($this->container['double'] > 123.4) { $invalid_properties[] = "invalid value for '$double', must be smaller than or equal to 123.4."; } - if ($this->double < 67.8) { + if ($this->container['double'] < 67.8) { $invalid_properties[] = "invalid value for '$double', must be bigger than or equal to 67.8."; } - if (!preg_match("/[a-z]/i", $this->string)) { + if (!preg_match("/[a-z]/i", $this->container['string'])) { $invalid_properties[] = "invalid value for '$string', must be conform to the pattern /[a-z]/i."; } - if ($this->byte === null) { + if ($this->container['byte'] === null) { $invalid_properties[] = "'$byte' can't be null"; } - if ($this->date === null) { + if ($this->container['date'] === null) { $invalid_properties[] = "'$date' can't be null"; } @@ -362,14 +362,14 @@ class FormatTest implements ArrayAccess - if ($this->password === null) { + if ($this->container['password'] === null) { $invalid_properties[] = "'$password' can't be null"; } - if (strlen($this->password) > 64) { + if (strlen($this->container['password']) > 64) { $invalid_properties[] = "invalid value for '$password', the character length must be smaller than or equal to 64."; } - if (strlen($this->password) < 10) { + if (strlen($this->container['password']) < 10) { $invalid_properties[] = "invalid value for '$password', the character length must be bigger than or equal to 10."; } @@ -386,63 +386,63 @@ class FormatTest implements ArrayAccess { - if ($this->integer > 100.0) { + if ($this->container['integer'] > 100.0) { return false; } - if ($this->integer < 10.0) { + if ($this->container['integer'] < 10.0) { return false; } - if ($this->int32 > 200.0) { + if ($this->container['int32'] > 200.0) { return false; } - if ($this->int32 < 20.0) { + if ($this->container['int32'] < 20.0) { return false; } - if ($this->number === null) { + if ($this->container['number'] === null) { return false; } - if ($this->number > 543.2) { + if ($this->container['number'] > 543.2) { return false; } - if ($this->number < 32.1) { + if ($this->container['number'] < 32.1) { return false; } - if ($this->float > 987.6) { + if ($this->container['float'] > 987.6) { return false; } - if ($this->float < 54.3) { + if ($this->container['float'] < 54.3) { return false; } - if ($this->double > 123.4) { + if ($this->container['double'] > 123.4) { return false; } - if ($this->double < 67.8) { + if ($this->container['double'] < 67.8) { return false; } - if (!preg_match("/[a-z]/i", $this->string)) { + if (!preg_match("/[a-z]/i", $this->container['string'])) { return false; } - if ($this->byte === null) { + if ($this->container['byte'] === null) { return false; } - if ($this->date === null) { + if ($this->container['date'] === null) { return false; } @@ -451,14 +451,14 @@ class FormatTest implements ArrayAccess - if ($this->password === null) { + if ($this->container['password'] === null) { return false; } - if (strlen($this->password) > 64) { + if (strlen($this->container['password']) > 64) { return false; } - if (strlen($this->password) < 10) { + if (strlen($this->container['password']) < 10) { return false; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php index 5d162500889..53d12898bd7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php @@ -166,7 +166,7 @@ class Name implements ArrayAccess { $invalid_properties = array(); - if ($this->name === null) { + if ($this->container['name'] === null) { $invalid_properties[] = "'$name' can't be null"; } @@ -187,7 +187,7 @@ class Name implements ArrayAccess public function valid() { - if ($this->name === null) { + if ($this->container['name'] === null) { return false; } 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 9928ddeea0b..15638a9e3a3 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -229,7 +229,7 @@ class Order implements ArrayAccess $allowed_values = array("placed", "approved", "delivered"); - if (!in_array($this->status, $allowed_values))) { + if (!in_array($this->container['status'], $allowed_values))) { $invalid_properties[] = "invalid value for '$status', must be one of #{allowed_values}."; } @@ -256,7 +256,7 @@ class Order implements ArrayAccess $allowed_values = array("placed", "approved", "delivered"); - if (!in_array($this->status, $allowed_values))) { + if (!in_array($this->container['status'], $allowed_values))) { return false; } 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 8fc13a04052..4025707d369 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -224,12 +224,12 @@ class Pet implements ArrayAccess - if ($this->name === null) { + if ($this->container['name'] === null) { $invalid_properties[] = "'$name' can't be null"; } - if ($this->photo_urls === null) { + if ($this->container['photo_urls'] === null) { $invalid_properties[] = "'$photo_urls' can't be null"; } @@ -237,7 +237,7 @@ class Pet implements ArrayAccess $allowed_values = array("available", "pending", "sold"); - if (!in_array($this->status, $allowed_values))) { + if (!in_array($this->container['status'], $allowed_values))) { $invalid_properties[] = "invalid value for '$status', must be one of #{allowed_values}."; } @@ -257,12 +257,12 @@ class Pet implements ArrayAccess - if ($this->name === null) { + if ($this->container['name'] === null) { return false; } - if ($this->photo_urls === null) { + if ($this->container['photo_urls'] === null) { return false; } @@ -270,7 +270,7 @@ class Pet implements ArrayAccess $allowed_values = array("available", "pending", "sold"); - if (!in_array($this->status, $allowed_values))) { + if (!in_array($this->container['status'], $allowed_values))) { return false; } From 9efef02d5f21e67f13c169574f84e45dd4ada911 Mon Sep 17 00:00:00 2001 From: abcsun Date: Sat, 7 May 2016 18:12:28 +0800 Subject: [PATCH 5/6] formate the module.mustache --- .../src/main/resources/php/model.mustache | 36 ++++--- .../petstore/php/SwaggerClient-php/README.md | 2 +- .../SwaggerClient-php/lib/Model/Animal.php | 8 -- .../lib/Model/AnimalFarm.php | 2 - .../lib/Model/ApiResponse.php | 23 +---- .../php/SwaggerClient-php/lib/Model/Cat.php | 9 +- .../SwaggerClient-php/lib/Model/Category.php | 16 +--- .../php/SwaggerClient-php/lib/Model/Dog.php | 9 +- .../SwaggerClient-php/lib/Model/EnumClass.php | 2 - .../SwaggerClient-php/lib/Model/EnumTest.php | 13 +-- .../lib/Model/FormatTest.php | 93 +++---------------- .../lib/Model/Model200Response.php | 9 +- .../lib/Model/ModelReturn.php | 9 +- .../php/SwaggerClient-php/lib/Model/Name.php | 22 +---- .../php/SwaggerClient-php/lib/Model/Order.php | 40 +------- .../php/SwaggerClient-php/lib/Model/Pet.php | 40 +------- .../lib/Model/SpecialModelName.php | 9 +- .../php/SwaggerClient-php/lib/Model/Tag.php | 16 +--- .../php/SwaggerClient-php/lib/Model/User.php | 58 ++---------- 19 files changed, 68 insertions(+), 348 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index 34aaa63393c..d17c76c137e 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -163,14 +163,18 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple public function list_invalid_properties() { $invalid_properties = array(); - {{#vars}}{{#required}} + {{#vars}} + {{#required}} if ($this->container['{{name}}'] === null) { $invalid_properties[] = "'${{name}}' can't be null"; - }{{/required}} - {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); + } + {{/required}} + {{#isEnum}} + $allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); if (!in_array($this->container['{{name}}'], $allowed_values))) { $invalid_properties[] = "invalid value for '${{name}}', must be one of #{allowed_values}."; - }{{/isEnum}} + } + {{/isEnum}} {{#hasValidation}} {{#maxLength}} if (strlen($this->container['{{name}}']) > {{maxLength}}) { @@ -196,7 +200,9 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple if (!preg_match("{{pattern}}", $this->container['{{name}}'])) { $invalid_properties[] = "invalid value for '${{name}}', must be conform to the pattern {{pattern}}."; } - {{/pattern}}{{/hasValidation}}{{/vars}} + {{/pattern}} + {{/hasValidation}} + {{/vars}} return $invalid_properties; } @@ -208,11 +214,13 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple */ public function valid() { - {{#vars}}{{#required}} + {{#vars}} + {{#required}} if ($this->container['{{name}}'] === null) { return false; }{{/required}} - {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); + {{#isEnum}} + $allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); if (!in_array($this->container['{{name}}'], $allowed_values))) { return false; }{{/isEnum}} @@ -241,7 +249,9 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple if (!preg_match("{{pattern}}", $this->container['{{name}}'])) { return false; } - {{/pattern}}{{/hasValidation}}{{/vars}} + {{/pattern}} + {{/hasValidation}} + {{/vars}} return true; } @@ -263,11 +273,12 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple */ public function {{setter}}(${{name}}) { - {{#isEnum}}$allowed_values = array({{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); + {{#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}} - + } + {{/isEnum}} {{#hasValidation}} {{#maxLength}} if (strlen(${{name}}) > {{maxLength}}) { @@ -292,7 +303,8 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple if (!preg_match("{{pattern}}", ${{name}})) { throw new \InvalidArgumentException('invalid value for ${{name}} when calling {{classname}}.{{operationId}}, must be conform to the pattern {{pattern}}.'); } - {{/pattern}}{{/hasValidation}} + {{/pattern}} + {{/hasValidation}} $this->container['{{name}}'] = ${{name}}; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index 5917dc8a7d9..6aea5f66866 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -5,7 +5,7 @@ This PHP package is automatically generated by the [Swagger Codegen](https://git - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-05-07T07:50:05.452Z +- Build date: 2016-05-07T10:11:34.658Z - Build package: class io.swagger.codegen.languages.PhpClientCodegen ## Requirements diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php index 7c25695056e..e537ef93414 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php @@ -142,12 +142,9 @@ class Animal implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - if ($this->container['class_name'] === null) { $invalid_properties[] = "'$class_name' can't be null"; } - - return $invalid_properties; } @@ -159,11 +156,9 @@ class Animal implements ArrayAccess */ public function valid() { - if ($this->container['class_name'] === null) { return false; } - return true; } @@ -185,9 +180,6 @@ class Animal implements ArrayAccess */ public function setClassName($class_name) { - - - $this->container['class_name'] = $class_name; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php index 394c146e532..dc7190652bc 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php @@ -130,7 +130,6 @@ class AnimalFarm implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - return $invalid_properties; } @@ -142,7 +141,6 @@ class AnimalFarm implements ArrayAccess */ public function valid() { - return true; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php index 1f087295322..0c7e225d120 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php @@ -165,13 +165,6 @@ class ApiResponse implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - - - - - return $invalid_properties; } @@ -183,12 +176,11 @@ class ApiResponse implements ArrayAccess */ public function valid() { - - - - + + + return true; } @@ -210,9 +202,6 @@ class ApiResponse implements ArrayAccess */ public function setCode($code) { - - - $this->container['code'] = $code; return $this; @@ -233,9 +222,6 @@ class ApiResponse implements ArrayAccess */ public function setType($type) { - - - $this->container['type'] = $type; return $this; @@ -256,9 +242,6 @@ class ApiResponse implements ArrayAccess */ public function setMessage($message) { - - - $this->container['message'] = $message; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php index 929560e001e..e40d5e969bf 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php @@ -139,9 +139,6 @@ class Cat extends Animal implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - return $invalid_properties; } @@ -153,8 +150,7 @@ class Cat extends Animal implements ArrayAccess */ public function valid() { - - + return true; } @@ -176,9 +172,6 @@ class Cat extends Animal implements ArrayAccess */ public function setDeclawed($declawed) { - - - $this->container['declawed'] = $declawed; return $this; 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 26d37a15e4a..99c309f6c7e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -152,11 +152,6 @@ class Category implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - - - return $invalid_properties; } @@ -168,10 +163,9 @@ class Category implements ArrayAccess */ public function valid() { - - - + + return true; } @@ -193,9 +187,6 @@ class Category implements ArrayAccess */ public function setId($id) { - - - $this->container['id'] = $id; return $this; @@ -216,9 +207,6 @@ class Category implements ArrayAccess */ public function setName($name) { - - - $this->container['name'] = $name; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php index 7a106519a81..9999bbba51c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php @@ -139,9 +139,6 @@ class Dog extends Animal implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - return $invalid_properties; } @@ -153,8 +150,7 @@ class Dog extends Animal implements ArrayAccess */ public function valid() { - - + return true; } @@ -176,9 +172,6 @@ class Dog extends Animal implements ArrayAccess */ public function setBreed($breed) { - - - $this->container['breed'] = $breed; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php index 6996674e02e..00b4a894af0 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php @@ -130,7 +130,6 @@ class EnumClass implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - return $invalid_properties; } @@ -142,7 +141,6 @@ class EnumClass implements ArrayAccess */ public function valid() { - return true; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php index dce42791a04..50d0069dea2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php @@ -204,22 +204,18 @@ class EnumTest implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - $allowed_values = array("UPPER", "lower"); if (!in_array($this->container['enum_string'], $allowed_values))) { $invalid_properties[] = "invalid value for '$enum_string', must be one of #{allowed_values}."; } - $allowed_values = array("1", "-1"); if (!in_array($this->container['enum_integer'], $allowed_values))) { $invalid_properties[] = "invalid value for '$enum_integer', must be one of #{allowed_values}."; } - $allowed_values = array("1.1", "-1.2"); if (!in_array($this->container['enum_number'], $allowed_values))) { $invalid_properties[] = "invalid value for '$enum_number', must be one of #{allowed_values}."; } - return $invalid_properties; } @@ -231,7 +227,7 @@ class EnumTest implements ArrayAccess */ public function valid() { - + $allowed_values = array("UPPER", "lower"); if (!in_array($this->container['enum_string'], $allowed_values))) { return false; @@ -246,7 +242,6 @@ class EnumTest implements ArrayAccess if (!in_array($this->container['enum_number'], $allowed_values))) { return false; } - return true; } @@ -271,8 +266,6 @@ class EnumTest implements ArrayAccess if (!in_array($enum_string, $allowed_values)) { throw new \InvalidArgumentException("Invalid value for 'enum_string', must be one of 'UPPER', 'lower'"); } - - $this->container['enum_string'] = $enum_string; return $this; @@ -297,8 +290,6 @@ class EnumTest implements ArrayAccess if (!in_array($enum_integer, $allowed_values)) { throw new \InvalidArgumentException("Invalid value for 'enum_integer', must be one of '1', '-1'"); } - - $this->container['enum_integer'] = $enum_integer; return $this; @@ -323,8 +314,6 @@ class EnumTest implements ArrayAccess if (!in_array($enum_number, $allowed_values)) { throw new \InvalidArgumentException("Invalid value for 'enum_number', must be one of '1.1', '-1.2'"); } - - $this->container['enum_number'] = $enum_number; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php index 7ab03733625..7a99d042353 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -295,84 +295,57 @@ class FormatTest implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - if ($this->container['integer'] > 100.0) { $invalid_properties[] = "invalid value for '$integer', must be smaller than or equal to 100.0."; } if ($this->container['integer'] < 10.0) { $invalid_properties[] = "invalid value for '$integer', must be bigger than or equal to 10.0."; } - - if ($this->container['int32'] > 200.0) { $invalid_properties[] = "invalid value for '$int32', must be smaller than or equal to 200.0."; } if ($this->container['int32'] < 20.0) { $invalid_properties[] = "invalid value for '$int32', must be bigger than or equal to 20.0."; } - - - if ($this->container['number'] === null) { $invalid_properties[] = "'$number' can't be null"; } - if ($this->container['number'] > 543.2) { $invalid_properties[] = "invalid value for '$number', must be smaller than or equal to 543.2."; } if ($this->container['number'] < 32.1) { $invalid_properties[] = "invalid value for '$number', must be bigger than or equal to 32.1."; } - - if ($this->container['float'] > 987.6) { $invalid_properties[] = "invalid value for '$float', must be smaller than or equal to 987.6."; } if ($this->container['float'] < 54.3) { $invalid_properties[] = "invalid value for '$float', must be bigger than or equal to 54.3."; } - - if ($this->container['double'] > 123.4) { $invalid_properties[] = "invalid value for '$double', must be smaller than or equal to 123.4."; } if ($this->container['double'] < 67.8) { $invalid_properties[] = "invalid value for '$double', must be bigger than or equal to 67.8."; } - - if (!preg_match("/[a-z]/i", $this->container['string'])) { $invalid_properties[] = "invalid value for '$string', must be conform to the pattern /[a-z]/i."; } - if ($this->container['byte'] === null) { $invalid_properties[] = "'$byte' can't be null"; } - - - - if ($this->container['date'] === null) { $invalid_properties[] = "'$date' can't be null"; } - - - - - - if ($this->container['password'] === null) { $invalid_properties[] = "'$password' can't be null"; } - if (strlen($this->container['password']) > 64) { $invalid_properties[] = "invalid value for '$password', the character length must be smaller than or equal to 64."; } if (strlen($this->container['password']) < 10) { $invalid_properties[] = "invalid value for '$password', the character length must be bigger than or equal to 10."; } - return $invalid_properties; } @@ -384,8 +357,8 @@ class FormatTest implements ArrayAccess */ public function valid() { - - + + if ($this->container['integer'] > 100.0) { return false; } @@ -393,7 +366,7 @@ class FormatTest implements ArrayAccess return false; } - + if ($this->container['int32'] > 200.0) { return false; } @@ -401,12 +374,11 @@ class FormatTest implements ArrayAccess return false; } - if ($this->container['number'] === null) { return false; } - + if ($this->container['number'] > 543.2) { return false; } @@ -414,7 +386,7 @@ class FormatTest implements ArrayAccess return false; } - + if ($this->container['float'] > 987.6) { return false; } @@ -422,7 +394,7 @@ class FormatTest implements ArrayAccess return false; } - + if ($this->container['double'] > 123.4) { return false; } @@ -430,38 +402,34 @@ class FormatTest implements ArrayAccess return false; } - + if (!preg_match("/[a-z]/i", $this->container['string'])) { return false; } - if ($this->container['byte'] === null) { return false; } - - + if ($this->container['date'] === null) { return false; } - - - + + if ($this->container['password'] === null) { return false; } - + if (strlen($this->container['password']) > 64) { return false; } if (strlen($this->container['password']) < 10) { return false; } - return true; } @@ -482,8 +450,6 @@ class FormatTest implements ArrayAccess */ public function setInteger($integer) { - - if ($integer > 100.0) { throw new \InvalidArgumentException('invalid value for $integer when calling FormatTest., must be smaller than or equal to 100.0.'); @@ -491,7 +457,6 @@ class FormatTest implements ArrayAccess if ($integer < 10.0) { throw new \InvalidArgumentException('invalid value for $integer when calling FormatTest., must be bigger than or equal to 10.0.'); } - $this->container['integer'] = $integer; return $this; @@ -512,8 +477,6 @@ class FormatTest implements ArrayAccess */ public function setInt32($int32) { - - if ($int32 > 200.0) { throw new \InvalidArgumentException('invalid value for $int32 when calling FormatTest., must be smaller than or equal to 200.0.'); @@ -521,7 +484,6 @@ class FormatTest implements ArrayAccess if ($int32 < 20.0) { throw new \InvalidArgumentException('invalid value for $int32 when calling FormatTest., must be bigger than or equal to 20.0.'); } - $this->container['int32'] = $int32; return $this; @@ -542,9 +504,6 @@ class FormatTest implements ArrayAccess */ public function setInt64($int64) { - - - $this->container['int64'] = $int64; return $this; @@ -565,8 +524,6 @@ class FormatTest implements ArrayAccess */ public function setNumber($number) { - - if ($number > 543.2) { throw new \InvalidArgumentException('invalid value for $number when calling FormatTest., must be smaller than or equal to 543.2.'); @@ -574,7 +531,6 @@ class FormatTest implements ArrayAccess if ($number < 32.1) { throw new \InvalidArgumentException('invalid value for $number when calling FormatTest., must be bigger than or equal to 32.1.'); } - $this->container['number'] = $number; return $this; @@ -595,8 +551,6 @@ class FormatTest implements ArrayAccess */ public function setFloat($float) { - - if ($float > 987.6) { throw new \InvalidArgumentException('invalid value for $float when calling FormatTest., must be smaller than or equal to 987.6.'); @@ -604,7 +558,6 @@ class FormatTest implements ArrayAccess if ($float < 54.3) { throw new \InvalidArgumentException('invalid value for $float when calling FormatTest., must be bigger than or equal to 54.3.'); } - $this->container['float'] = $float; return $this; @@ -625,8 +578,6 @@ class FormatTest implements ArrayAccess */ public function setDouble($double) { - - if ($double > 123.4) { throw new \InvalidArgumentException('invalid value for $double when calling FormatTest., must be smaller than or equal to 123.4.'); @@ -634,7 +585,6 @@ class FormatTest implements ArrayAccess if ($double < 67.8) { throw new \InvalidArgumentException('invalid value for $double when calling FormatTest., must be bigger than or equal to 67.8.'); } - $this->container['double'] = $double; return $this; @@ -655,13 +605,10 @@ class FormatTest implements ArrayAccess */ public function setString($string) { - - if (!preg_match("/[a-z]/i", $string)) { throw new \InvalidArgumentException('invalid value for $string when calling FormatTest., must be conform to the pattern /[a-z]/i.'); } - $this->container['string'] = $string; return $this; @@ -682,9 +629,6 @@ class FormatTest implements ArrayAccess */ public function setByte($byte) { - - - $this->container['byte'] = $byte; return $this; @@ -705,9 +649,6 @@ class FormatTest implements ArrayAccess */ public function setBinary($binary) { - - - $this->container['binary'] = $binary; return $this; @@ -728,9 +669,6 @@ class FormatTest implements ArrayAccess */ public function setDate($date) { - - - $this->container['date'] = $date; return $this; @@ -751,9 +689,6 @@ class FormatTest implements ArrayAccess */ public function setDateTime($date_time) { - - - $this->container['date_time'] = $date_time; return $this; @@ -774,9 +709,6 @@ class FormatTest implements ArrayAccess */ public function setUuid($uuid) { - - - $this->container['uuid'] = $uuid; return $this; @@ -797,15 +729,12 @@ class FormatTest implements ArrayAccess */ public function setPassword($password) { - - if (strlen($password) > 64) { throw new \InvalidArgumentException('invalid length for $password when calling FormatTest., must be smaller than or equal to 64.'); } if (strlen($password) < 10) { throw new \InvalidArgumentException('invalid length for $password when calling FormatTest., must be bigger than or equal to 10.'); } - $this->container['password'] = $password; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php index 263311b9d31..6884fbaed82 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php @@ -139,9 +139,6 @@ class Model200Response implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - return $invalid_properties; } @@ -153,8 +150,7 @@ class Model200Response implements ArrayAccess */ public function valid() { - - + return true; } @@ -176,9 +172,6 @@ class Model200Response implements ArrayAccess */ public function setName($name) { - - - $this->container['name'] = $name; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php index 15298ff50eb..7f8b7e7296b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php @@ -139,9 +139,6 @@ class ModelReturn implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - return $invalid_properties; } @@ -153,8 +150,7 @@ class ModelReturn implements ArrayAccess */ public function valid() { - - + return true; } @@ -176,9 +172,6 @@ class ModelReturn implements ArrayAccess */ public function setReturn($return) { - - - $this->container['return'] = $return; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php index 53d12898bd7..9420a11796d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php @@ -165,16 +165,9 @@ class Name implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - if ($this->container['name'] === null) { $invalid_properties[] = "'$name' can't be null"; } - - - - - - return $invalid_properties; } @@ -186,15 +179,13 @@ class Name implements ArrayAccess */ public function valid() { - if ($this->container['name'] === null) { return false; } - - - + + return true; } @@ -216,9 +207,6 @@ class Name implements ArrayAccess */ public function setName($name) { - - - $this->container['name'] = $name; return $this; @@ -239,9 +227,6 @@ class Name implements ArrayAccess */ public function setSnakeCase($snake_case) { - - - $this->container['snake_case'] = $snake_case; return $this; @@ -262,9 +247,6 @@ class Name implements ArrayAccess */ public function setProperty($property) { - - - $this->container['property'] = $property; 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 15638a9e3a3..e668f6d432b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -219,22 +219,10 @@ class Order implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - - - - - - - $allowed_values = array("placed", "approved", "delivered"); if (!in_array($this->container['status'], $allowed_values))) { $invalid_properties[] = "invalid value for '$status', must be one of #{allowed_values}."; } - - - return $invalid_properties; } @@ -246,21 +234,20 @@ class Order implements ArrayAccess */ public function valid() { - - - - - + + + + + $allowed_values = array("placed", "approved", "delivered"); if (!in_array($this->container['status'], $allowed_values))) { return false; } - return true; } @@ -282,9 +269,6 @@ class Order implements ArrayAccess */ public function setId($id) { - - - $this->container['id'] = $id; return $this; @@ -305,9 +289,6 @@ class Order implements ArrayAccess */ public function setPetId($pet_id) { - - - $this->container['pet_id'] = $pet_id; return $this; @@ -328,9 +309,6 @@ class Order implements ArrayAccess */ public function setQuantity($quantity) { - - - $this->container['quantity'] = $quantity; return $this; @@ -351,9 +329,6 @@ class Order implements ArrayAccess */ public function setShipDate($ship_date) { - - - $this->container['ship_date'] = $ship_date; return $this; @@ -378,8 +353,6 @@ class Order implements ArrayAccess if (!in_array($status, $allowed_values)) { throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'placed', 'approved', 'delivered'"); } - - $this->container['status'] = $status; return $this; @@ -400,9 +373,6 @@ class Order implements ArrayAccess */ public function setComplete($complete) { - - - $this->container['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 4025707d369..c949198e642 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -219,28 +219,16 @@ class Pet implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - - - if ($this->container['name'] === null) { $invalid_properties[] = "'$name' can't be null"; } - - if ($this->container['photo_urls'] === null) { $invalid_properties[] = "'$photo_urls' can't be null"; } - - - - $allowed_values = array("available", "pending", "sold"); if (!in_array($this->container['status'], $allowed_values))) { $invalid_properties[] = "invalid value for '$status', must be one of #{allowed_values}."; } - return $invalid_properties; } @@ -252,28 +240,25 @@ class Pet implements ArrayAccess */ public function valid() { - - - + + if ($this->container['name'] === null) { return false; } - if ($this->container['photo_urls'] === null) { return false; } - - + + $allowed_values = array("available", "pending", "sold"); if (!in_array($this->container['status'], $allowed_values))) { return false; } - return true; } @@ -294,9 +279,6 @@ class Pet implements ArrayAccess */ public function setId($id) { - - - $this->container['id'] = $id; return $this; @@ -317,9 +299,6 @@ class Pet implements ArrayAccess */ public function setCategory($category) { - - - $this->container['category'] = $category; return $this; @@ -340,9 +319,6 @@ class Pet implements ArrayAccess */ public function setName($name) { - - - $this->container['name'] = $name; return $this; @@ -363,9 +339,6 @@ class Pet implements ArrayAccess */ public function setPhotoUrls($photo_urls) { - - - $this->container['photo_urls'] = $photo_urls; return $this; @@ -386,9 +359,6 @@ class Pet implements ArrayAccess */ public function setTags($tags) { - - - $this->container['tags'] = $tags; return $this; @@ -413,8 +383,6 @@ class Pet implements ArrayAccess if (!in_array($status, $allowed_values)) { throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'available', 'pending', 'sold'"); } - - $this->container['status'] = $status; return $this; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php index 680868dbd0b..0e37ecb8f46 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php @@ -139,9 +139,6 @@ class SpecialModelName implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - return $invalid_properties; } @@ -153,8 +150,7 @@ class SpecialModelName implements ArrayAccess */ public function valid() { - - + return true; } @@ -176,9 +172,6 @@ class SpecialModelName implements ArrayAccess */ public function setSpecialPropertyName($special_property_name) { - - - $this->container['special_property_name'] = $special_property_name; 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 69c853bbef3..d188cc323e4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -152,11 +152,6 @@ class Tag implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - - - return $invalid_properties; } @@ -168,10 +163,9 @@ class Tag implements ArrayAccess */ public function valid() { - - - + + return true; } @@ -193,9 +187,6 @@ class Tag implements ArrayAccess */ public function setId($id) { - - - $this->container['id'] = $id; return $this; @@ -216,9 +207,6 @@ class Tag implements ArrayAccess */ public function setName($name) { - - - $this->container['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 4ca0b8fb3e1..58cb418951e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -230,23 +230,6 @@ class User implements ArrayAccess public function list_invalid_properties() { $invalid_properties = array(); - - - - - - - - - - - - - - - - - return $invalid_properties; } @@ -258,22 +241,21 @@ class User implements ArrayAccess */ public function valid() { - - - - - - - - - + + + + + + + + return true; } @@ -295,9 +277,6 @@ class User implements ArrayAccess */ public function setId($id) { - - - $this->container['id'] = $id; return $this; @@ -318,9 +297,6 @@ class User implements ArrayAccess */ public function setUsername($username) { - - - $this->container['username'] = $username; return $this; @@ -341,9 +317,6 @@ class User implements ArrayAccess */ public function setFirstName($first_name) { - - - $this->container['first_name'] = $first_name; return $this; @@ -364,9 +337,6 @@ class User implements ArrayAccess */ public function setLastName($last_name) { - - - $this->container['last_name'] = $last_name; return $this; @@ -387,9 +357,6 @@ class User implements ArrayAccess */ public function setEmail($email) { - - - $this->container['email'] = $email; return $this; @@ -410,9 +377,6 @@ class User implements ArrayAccess */ public function setPassword($password) { - - - $this->container['password'] = $password; return $this; @@ -433,9 +397,6 @@ class User implements ArrayAccess */ public function setPhone($phone) { - - - $this->container['phone'] = $phone; return $this; @@ -456,9 +417,6 @@ class User implements ArrayAccess */ public function setUserStatus($user_status) { - - - $this->container['user_status'] = $user_status; return $this; From f30b32afc4ffd9bb94a8376db737246e7fd28a6a Mon Sep 17 00:00:00 2001 From: wing328 Date: Mon, 9 May 2016 16:32:49 +0800 Subject: [PATCH 6/6] minor fix to mustache layout --- .../src/main/resources/php/model.mustache | 15 ++--- .../petstore/php/SwaggerClient-php/README.md | 8 +-- .../php/SwaggerClient-php/docs/FakeApi.md | 18 +----- .../php/SwaggerClient-php/lib/Api/FakeApi.php | 12 +--- .../SwaggerClient-php/lib/Model/Animal.php | 6 +- .../lib/Model/AnimalFarm.php | 5 +- .../lib/Model/ApiResponse.php | 11 +--- .../php/SwaggerClient-php/lib/Model/Cat.php | 7 +-- .../SwaggerClient-php/lib/Model/Category.php | 9 +-- .../php/SwaggerClient-php/lib/Model/Dog.php | 7 +-- .../SwaggerClient-php/lib/Model/EnumClass.php | 24 ++++++- .../SwaggerClient-php/lib/Model/EnumTest.php | 62 ++++++++++++++++++- .../lib/Model/FormatTest.php | 27 +------- .../lib/Model/Model200Response.php | 7 +-- .../lib/Model/ModelReturn.php | 7 +-- .../php/SwaggerClient-php/lib/Model/Name.php | 10 +-- .../php/SwaggerClient-php/lib/Model/Order.php | 20 ++---- .../php/SwaggerClient-php/lib/Model/Pet.php | 18 ++---- .../lib/Model/SpecialModelName.php | 7 +-- .../php/SwaggerClient-php/lib/Model/Tag.php | 9 +-- .../php/SwaggerClient-php/lib/Model/User.php | 21 +------ .../lib/Tests/FakeApiTest.php | 6 +- 22 files changed, 132 insertions(+), 184 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index d17c76c137e..43e90fc6f86 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -171,7 +171,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple {{/required}} {{#isEnum}} $allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); - if (!in_array($this->container['{{name}}'], $allowed_values))) { + if (!in_array($this->container['{{name}}'], $allowed_values)) { $invalid_properties[] = "invalid value for '${{name}}', must be one of #{allowed_values}."; } {{/isEnum}} @@ -207,10 +207,10 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { @@ -218,12 +218,14 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple {{#required}} if ($this->container['{{name}}'] === null) { return false; - }{{/required}} + } + {{/required}} {{#isEnum}} $allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); - if (!in_array($this->container['{{name}}'], $allowed_values))) { + if (!in_array($this->container['{{name}}'], $allowed_values)) { return false; - }{{/isEnum}} + } + {{/isEnum}} {{#hasValidation}} {{#maxLength}} if (strlen($this->container['{{name}}']) > {{maxLength}}) { @@ -255,7 +257,6 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple return true; } - {{#vars}} /** * Gets {{name}} diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index ab81085c3ad..d781d4d1d31 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -5,7 +5,7 @@ This PHP package is automatically generated by the [Swagger Codegen](https://git - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-05-06T16:24:00.420+08:00 +- Build date: 2016-05-09T16:31:19.614+08:00 - Build package: class io.swagger.codegen.languages.PhpClientCodegen ## Requirements @@ -87,11 +87,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- -*FakeApi* | [**testEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters -假端點 -偽のエンドポイント -가짜 엔드 포인트 - +*FakeApi* | [**testEndpointParameters**](docs/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 *PetApi* | [**addPet**](docs/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store *PetApi* | [**deletePet**](docs/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**findPetsByStatus**](docs/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/FakeApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/FakeApi.md index 4acf36fa696..5988dc781b2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/FakeApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/FakeApi.md @@ -4,27 +4,15 @@ All URIs are relative to *http://petstore.swagger.io/v2* Method | HTTP request | Description ------------- | ------------- | ------------- -[**testEndpointParameters**](FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters -假端點 -偽のエンドポイント -가짜 엔드 포인트 - +[**testEndpointParameters**](FakeApi.md#testEndpointParameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 # **testEndpointParameters** > testEndpointParameters($number, $double, $string, $byte, $integer, $int32, $int64, $float, $binary, $date, $date_time, $password) -Fake endpoint for testing various parameters -假端點 -偽のエンドポイント -가짜 엔드 포인트 - - -Fake endpoint for testing various parameters -假端點 -偽のエンドポイント -가짜 엔드 포인트 +Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 +Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 ### Example ```php diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php index ee1c6b8b600..5620c82fdcd 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -93,11 +93,7 @@ class FakeApi /** * testEndpointParameters * - * Fake endpoint for testing various parameters -假端點 -偽のエンドポイント -가짜 엔드 포인트 - + * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * * @param float $number None (required) * @param double $double None (required) @@ -124,11 +120,7 @@ class FakeApi /** * testEndpointParametersWithHttpInfo * - * Fake endpoint for testing various parameters -假端點 -偽のエンドポイント -가짜 엔드 포인트 - + * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * * @param float $number None (required) * @param double $double None (required) diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php index e537ef93414..c87fe976354 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php @@ -149,21 +149,19 @@ class Animal implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { if ($this->container['class_name'] === null) { return false; } - return true; } - /** * Gets class_name * @return string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php index dc7190652bc..afd16e0a5c8 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php @@ -134,17 +134,16 @@ class AnimalFarm implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { return true; } - /** * Returns true if offset exists. False otherwise. * @param integer $offset Offset diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php index 0c7e225d120..655cb7e4b2c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php @@ -169,23 +169,16 @@ class ApiResponse implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - - - - - return true; } - /** * Gets code * @return int diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php index e40d5e969bf..31b9f153cd4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php @@ -143,19 +143,16 @@ class Cat extends Animal implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - return true; } - /** * Gets declawed * @return bool 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 99c309f6c7e..f186c7b740c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -156,21 +156,16 @@ class Category implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - - - return true; } - /** * Gets id * @return int diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php index 9999bbba51c..d14fa50ca19 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php @@ -143,19 +143,16 @@ class Dog extends Animal implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - return true; } - /** * Gets breed * @return string diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php index 66f2ba08229..f7d1457c30f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php @@ -119,9 +119,31 @@ class EnumClass implements ArrayAccess if ($data != null) { - } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + return $invalid_properties; + } + + /** + * validate all the properties in the model + * return true if all passed + * + * @return bool True if all properteis are valid + */ + public function valid() + { + return true; + } + /** * Returns true if offset exists. False otherwise. * @param integer $offset Offset diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php index 1f3213e7516..70e5e5ad961 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php @@ -184,11 +184,64 @@ class EnumTest implements ArrayAccess if ($data != null) { - $this->container['enum_string'] = $data['enum_string']; - $this->container['enum_integer'] = $data['enum_integer']; - $this->container['enum_number'] = $data['enum_number']; + if (isset($data["enum_string"])) { + $this->container['enum_string'] = $data["enum_string"]; + } + if (isset($data["enum_integer"])) { + $this->container['enum_integer'] = $data["enum_integer"]; + } + if (isset($data["enum_number"])) { + $this->container['enum_number'] = $data["enum_number"]; + } } } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function list_invalid_properties() + { + $invalid_properties = array(); + $allowed_values = array("UPPER", "lower"); + if (!in_array($this->container['enum_string'], $allowed_values)) { + $invalid_properties[] = "invalid value for '$enum_string', must be one of #{allowed_values}."; + } + $allowed_values = array("1", "-1"); + if (!in_array($this->container['enum_integer'], $allowed_values)) { + $invalid_properties[] = "invalid value for '$enum_integer', must be one of #{allowed_values}."; + } + $allowed_values = array("1.1", "-1.2"); + if (!in_array($this->container['enum_number'], $allowed_values)) { + $invalid_properties[] = "invalid value for '$enum_number', must be one of #{allowed_values}."; + } + return $invalid_properties; + } + + /** + * validate all the properties in the model + * return true if all passed + * + * @return bool True if all properteis are valid + */ + public function valid() + { + $allowed_values = array("UPPER", "lower"); + if (!in_array($this->container['enum_string'], $allowed_values)) { + return false; + } + $allowed_values = array("1", "-1"); + if (!in_array($this->container['enum_integer'], $allowed_values)) { + return false; + } + $allowed_values = array("1.1", "-1.2"); + if (!in_array($this->container['enum_number'], $allowed_values)) { + return false; + } + return true; + } + /** * Gets enum_string * @return string @@ -210,6 +263,7 @@ class EnumTest implements ArrayAccess throw new \InvalidArgumentException("Invalid value for 'enum_string', must be one of 'UPPER', 'lower'"); } $this->container['enum_string'] = $enum_string; + return $this; } /** @@ -233,6 +287,7 @@ class EnumTest implements ArrayAccess throw new \InvalidArgumentException("Invalid value for 'enum_integer', must be one of '1', '-1'"); } $this->container['enum_integer'] = $enum_integer; + return $this; } /** @@ -256,6 +311,7 @@ class EnumTest implements ArrayAccess throw new \InvalidArgumentException("Invalid value for 'enum_number', must be one of '1.1', '-1.2'"); } $this->container['enum_number'] = $enum_number; + return $this; } /** diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php index 7a99d042353..322d7623bf1 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -350,80 +350,58 @@ class FormatTest implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - if ($this->container['integer'] > 100.0) { return false; } if ($this->container['integer'] < 10.0) { return false; } - - if ($this->container['int32'] > 200.0) { return false; } if ($this->container['int32'] < 20.0) { return false; } - - if ($this->container['number'] === null) { return false; } - if ($this->container['number'] > 543.2) { return false; } if ($this->container['number'] < 32.1) { return false; } - - if ($this->container['float'] > 987.6) { return false; } if ($this->container['float'] < 54.3) { return false; } - - if ($this->container['double'] > 123.4) { return false; } if ($this->container['double'] < 67.8) { return false; } - - if (!preg_match("/[a-z]/i", $this->container['string'])) { return false; } if ($this->container['byte'] === null) { return false; } - - - if ($this->container['date'] === null) { return false; } - - - - - if ($this->container['password'] === null) { return false; } - if (strlen($this->container['password']) > 64) { return false; } @@ -433,7 +411,6 @@ class FormatTest implements ArrayAccess return true; } - /** * Gets integer * @return int diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php index 6884fbaed82..07dcae58bfa 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php @@ -143,19 +143,16 @@ class Model200Response implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - return true; } - /** * Gets name * @return int diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php index 7f8b7e7296b..78f2e6dfe99 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php @@ -143,19 +143,16 @@ class ModelReturn implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - return true; } - /** * Gets return * @return int diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php index 9420a11796d..e9f40099d6c 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php @@ -172,25 +172,19 @@ class Name implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { if ($this->container['name'] === null) { return false; } - - - - - return true; } - /** * Gets name * @return int 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 e668f6d432b..233a6abd1bc 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -220,39 +220,27 @@ class Order implements ArrayAccess { $invalid_properties = array(); $allowed_values = array("placed", "approved", "delivered"); - if (!in_array($this->container['status'], $allowed_values))) { + if (!in_array($this->container['status'], $allowed_values)) { $invalid_properties[] = "invalid value for '$status', must be one of #{allowed_values}."; } return $invalid_properties; } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - - - - - - - - $allowed_values = array("placed", "approved", "delivered"); - if (!in_array($this->container['status'], $allowed_values))) { + if (!in_array($this->container['status'], $allowed_values)) { return false; } - - return true; } - /** * Gets id * @return int 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 c949198e642..2aab87c1ab9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -226,43 +226,33 @@ class Pet implements ArrayAccess $invalid_properties[] = "'$photo_urls' can't be null"; } $allowed_values = array("available", "pending", "sold"); - if (!in_array($this->container['status'], $allowed_values))) { + if (!in_array($this->container['status'], $allowed_values)) { $invalid_properties[] = "invalid value for '$status', must be one of #{allowed_values}."; } return $invalid_properties; } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - - - if ($this->container['name'] === null) { return false; } - if ($this->container['photo_urls'] === null) { return false; } - - - - $allowed_values = array("available", "pending", "sold"); - if (!in_array($this->container['status'], $allowed_values))) { + if (!in_array($this->container['status'], $allowed_values)) { return false; } return true; } - /** * Gets id * @return int diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php index 0e37ecb8f46..00f91f201b6 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php @@ -143,19 +143,16 @@ class SpecialModelName implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - return true; } - /** * Gets special_property_name * @return int 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 d188cc323e4..c141024188b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -156,21 +156,16 @@ class Tag implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - - - return true; } - /** * Gets id * @return int 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 58cb418951e..9018e342a1d 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -234,33 +234,16 @@ class User implements ArrayAccess } /** - * validate all the parameters in the model + * validate all the properties in the model * return true if all passed * - * @return bool [description] + * @return bool True if all properteis are valid */ public function valid() { - - - - - - - - - - - - - - - - return true; } - /** * Gets id * @return int diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Tests/FakeApiTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Tests/FakeApiTest.php index 742f571fb72..dc599fbe5d7 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Tests/FakeApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Tests/FakeApiTest.php @@ -67,11 +67,7 @@ class FakeApiTest extends \PHPUnit_Framework_TestCase /** * Test case for testEndpointParameters * - * Fake endpoint for testing various parameters -假端點 -偽のエンドポイント -가짜 엔드 포인트 - + * Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 * */ public function test_testEndpointParameters() {