Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
142 changes: 138 additions & 4 deletions modules/swagger-codegen/src/main/resources/php/model.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,115 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
{{/discriminator}}

if ($data != null) {
{{#vars}}$this->container['{{name}}'] = $data['{{name}}'];{{#hasMore}}
{{/hasMore}}{{/vars}}
{{#vars}}
if (isset($data["{{name}}"])) {
$this->container['{{name}}'] = $data["{{name}}"];
}{{#hasMore}}{{/hasMore}}
{{/vars}}
}
}

/**
* 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->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->container['{{name}}'], $allowed_values))) {
$invalid_properties[] = "invalid value for '${{name}}', must be one of #{allowed_values}.";
}
{{/isEnum}}
{{#hasValidation}}
{{#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->container['{{name}}']) < {{minLength}}) {
$invalid_properties[] = "invalid value for '${{name}}', the character length must be bigger than or equal to {{{minLength}}}.";
}
{{/minLength}}
{{#maximum}}
if ($this->container['{{name}}'] > {{maximum}}) {
$invalid_properties[] = "invalid value for '${{name}}', must be smaller than or equal to {{maximum}}.";
}
{{/maximum}}
{{#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->container['{{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
*
* @return bool [description]
*/
public function valid()
{
{{#vars}}
{{#required}}
if ($this->container['{{name}}'] === null) {
return false;
}{{/required}}
{{#isEnum}}
$allowed_values = array({{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}});
if (!in_array($this->container['{{name}}'], $allowed_values))) {
return false;
}{{/isEnum}}
{{#hasValidation}}
{{#maxLength}}
if (strlen($this->container['{{name}}']) > {{maxLength}}) {
return false;
}
{{/maxLength}}
{{#minLength}}
if (strlen($this->container['{{name}}']) < {{minLength}}) {
return false;
}
{{/minLength}}
{{#maximum}}
if ($this->container['{{name}}'] > {{maximum}}) {
return false;
}
{{/maximum}}
{{#minimum}}
if ($this->container['{{name}}'] < {{minimum}}) {
return false;
}
{{/minimum}}
{{#pattern}}
if (!preg_match("{{pattern}}", $this->container['{{name}}'])) {
return false;
}
{{/pattern}}
{{/hasValidation}}
{{/vars}}
return true;
}


{{#vars}}
/**
* Gets {{name}}
Expand All @@ -168,11 +273,40 @@ 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}}) {
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 be conform to the pattern {{pattern}}.');
}
{{/pattern}}
{{/hasValidation}}
$this->container['{{name}}'] = ${{name}};

return $this;
}
{{/vars}}
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/php/SwaggerClient-php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-06T10:33:16.765+08:00
- Build date: 2016-05-07T10:11:34.658Z
- Build package: class io.swagger.codegen.languages.PhpClientCodegen

## Requirements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# EnumClass

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


12 changes: 12 additions & 0 deletions samples/client/petstore/php/SwaggerClient-php/docs/EnumTest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EnumTest

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**enum_string** | **string** | | [optional]
**enum_integer** | **int** | | [optional]
**enum_number** | **double** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function testEndpointParametersWithHttpInfo($number, $double, $string, $b
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.');
}

Expand Down
37 changes: 35 additions & 2 deletions samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,42 @@ public function __construct(array $data = null)
$this->container[$discrimintor] = static::$swaggerModelName;

if ($data != null) {
$this->container['class_name'] = $data['class_name'];
if (isset($data["class_name"])) {
$this->container['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->container['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->container['class_name'] === null) {
return false;
}

return true;
}


/**
* Gets class_name
* @return string
Expand All @@ -147,8 +180,8 @@ public function getClassName()
*/
public function setClassName($class_name)
{

$this->container['class_name'] = $class_name;

return $this;
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,32 @@ public function __construct(array $data = null)


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 parameters in the model
* return true if all passed
*
* @return bool [description]
*/
public function valid()
{
return true;
}


/**
* Returns true if offset exists. False otherwise.
* @param integer $offset Offset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,47 @@ public function __construct(array $data = null)


if ($data != null) {
$this->container['code'] = $data['code'];
$this->container['type'] = $data['type'];
$this->container['message'] = $data['message'];
if (isset($data["code"])) {
$this->container['code'] = $data["code"];
}
if (isset($data["type"])) {
$this->container['type'] = $data["type"];
}
if (isset($data["message"])) {
$this->container['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
Expand All @@ -166,8 +202,8 @@ public function getCode()
*/
public function setCode($code)
{

$this->container['code'] = $code;

return $this;
}
/**
Expand All @@ -186,8 +222,8 @@ public function getType()
*/
public function setType($type)
{

$this->container['type'] = $type;

return $this;
}
/**
Expand All @@ -206,8 +242,8 @@ public function getMessage()
*/
public function setMessage($message)
{

$this->container['message'] = $message;

return $this;
}
/**
Expand Down
Loading