forked from loafle/openapi-generator-original
Merge branch 'php-fix-array-handling-2' of https://github.com/arnested/swagger-codegen into arnested-php-fix-array-handling-2
Conflicts: modules/swagger-codegen/src/main/resources/php/model.mustache samples/client/petstore/php/SwaggerClient-php/README.md samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
namespace {{modelPackage}};
|
||||
|
||||
use \ArrayAccess;
|
||||
|
||||
/**
|
||||
* {{classname}} Class Doc Comment
|
||||
*
|
||||
@@ -62,7 +63,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
{{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
|
||||
static function swaggerTypes() {
|
||||
return self::$swaggerTypes{{#parentSchema}} + parent::swaggerTypes(){{/parentSchema}};
|
||||
}
|
||||
@@ -75,7 +76,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
{{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
|
||||
static function attributeMap() {
|
||||
return {{#parentSchema}}parent::attributeMap() + {{/parentSchema}}self::$attributeMap;
|
||||
}
|
||||
@@ -88,7 +89,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
{{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}},
|
||||
{{/hasMore}}{{/vars}}
|
||||
);
|
||||
|
||||
|
||||
static function setters() {
|
||||
return {{#parentSchema}}parent::setters() + {{/parentSchema}}self::$setters;
|
||||
}
|
||||
@@ -126,13 +127,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
* Associative array for storing property values
|
||||
* @var mixed[]
|
||||
*/
|
||||
protected $container = array({{#vars}}
|
||||
/**
|
||||
* $container['{{{name}}}']{{#description}} {{{description}}}{{/description}}
|
||||
* @var {{datatype}}
|
||||
*/
|
||||
'{{{name}}}' => {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}},
|
||||
{{/vars}});
|
||||
protected $container = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -140,19 +135,19 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
{
|
||||
{{#parentSchema}}parent::__construct($data);{{/parentSchema}}
|
||||
{{#discriminator}}// Initialize discriminator property with the model name.
|
||||
{{#parentSchema}}
|
||||
parent::__construct($data);
|
||||
|
||||
{{/parentSchema}}
|
||||
{{#vars}}
|
||||
$this->container['{{name}}'] = isset($data['{{name}}']) ? $data['{{name}}'] : {{#defaultValue}}{{{defaultValue}}}{{/defaultValue}}{{^defaultValue}}null{{/defaultValue}};
|
||||
{{/vars}}
|
||||
{{#discriminator}}
|
||||
|
||||
// Initialize discriminator property with the model name.
|
||||
$discrimintor = array_search('{{discriminator}}', self::$attributeMap);
|
||||
$this->container[$discrimintor] = static::$swaggerModelName;
|
||||
{{/discriminator}}
|
||||
|
||||
if ($data != null) {
|
||||
{{#vars}}
|
||||
if (isset($data["{{name}}"])) {
|
||||
$this->container['{{name}}'] = $data["{{name}}"];
|
||||
}{{#hasMore}}{{/hasMore}}
|
||||
{{/vars}}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -258,6 +253,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}imple
|
||||
}
|
||||
|
||||
{{#vars}}
|
||||
|
||||
/**
|
||||
* Gets {{name}}
|
||||
* @return {{datatype}}
|
||||
|
||||
@@ -850,6 +850,9 @@ definitions:
|
||||
properties:
|
||||
className:
|
||||
type: string
|
||||
color:
|
||||
type: string
|
||||
default: 'red'
|
||||
AnimalFarm:
|
||||
type: array
|
||||
items:
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
# 200Response
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**name** | **int** | | [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)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**class_name** | **string** | |
|
||||
**color** | **string** | | [optional] [default to 'red']
|
||||
|
||||
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
# InlineResponse200
|
||||
|
||||
## Properties
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**tags** | [**\Swagger\Client\Model\Tag[]**](Tag.md) | | [optional]
|
||||
**id** | **int** | |
|
||||
**category** | **object** | | [optional]
|
||||
**status** | **string** | pet status in the store | [optional]
|
||||
**name** | **string** | | [optional]
|
||||
**photo_urls** | **string[]** | | [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)
|
||||
|
||||
|
||||
@@ -1,375 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* InlineResponse200
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2016 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
namespace Swagger\Client\Model;
|
||||
|
||||
use \ArrayAccess;
|
||||
/**
|
||||
* InlineResponse200 Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @description
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class InlineResponse200 implements ArrayAccess
|
||||
{
|
||||
/**
|
||||
* Array of property to type mappings. Used for (de)serialization
|
||||
* @var string[]
|
||||
*/
|
||||
static $swaggerTypes = array(
|
||||
'tags' => '\Swagger\Client\Model\Tag[]',
|
||||
'id' => 'int',
|
||||
'category' => 'object',
|
||||
'status' => 'string',
|
||||
'name' => 'string',
|
||||
'photo_urls' => 'string[]'
|
||||
);
|
||||
|
||||
static function swaggerTypes() {
|
||||
return self::$swaggerTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of attributes where the key is the local name, and the value is the original name
|
||||
* @var string[]
|
||||
*/
|
||||
static $attributeMap = array(
|
||||
'tags' => 'tags',
|
||||
'id' => 'id',
|
||||
'category' => 'category',
|
||||
'status' => 'status',
|
||||
'name' => 'name',
|
||||
'photo_urls' => 'photoUrls'
|
||||
);
|
||||
|
||||
static function attributeMap() {
|
||||
return self::$attributeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of attributes to setter functions (for deserialization of responses)
|
||||
* @var string[]
|
||||
*/
|
||||
static $setters = array(
|
||||
'tags' => 'setTags',
|
||||
'id' => 'setId',
|
||||
'category' => 'setCategory',
|
||||
'status' => 'setStatus',
|
||||
'name' => 'setName',
|
||||
'photo_urls' => 'setPhotoUrls'
|
||||
);
|
||||
|
||||
static function setters() {
|
||||
return self::$setters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Array of attributes to getter functions (for serialization of requests)
|
||||
* @var string[]
|
||||
*/
|
||||
static $getters = array(
|
||||
'tags' => 'getTags',
|
||||
'id' => 'getId',
|
||||
'category' => 'getCategory',
|
||||
'status' => 'getStatus',
|
||||
'name' => 'getName',
|
||||
'photo_urls' => 'getPhotoUrls'
|
||||
);
|
||||
|
||||
static function getters() {
|
||||
return self::$getters;
|
||||
}
|
||||
|
||||
const STATUS_AVAILABLE = 'available';
|
||||
const STATUS_PENDING = 'pending';
|
||||
const STATUS_SOLD = 'sold';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Gets allowable values of the enum
|
||||
* @return string[]
|
||||
*/
|
||||
public function getStatusAllowableValues() {
|
||||
return [
|
||||
self::STATUS_AVAILABLE,
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_SOLD,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* $tags
|
||||
* @var \Swagger\Client\Model\Tag[]
|
||||
*/
|
||||
protected $tags;
|
||||
|
||||
/**
|
||||
* $id
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* $category
|
||||
* @var object
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
/**
|
||||
* $status pet status in the store
|
||||
* @var string
|
||||
*/
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* $name
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* $photo_urls
|
||||
* @var string[]
|
||||
*/
|
||||
protected $photo_urls;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param mixed[] $data Associated array of property value initalizing the model
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
{
|
||||
|
||||
if ($data != null) {
|
||||
$this->tags = $data["tags"];
|
||||
$this->id = $data["id"];
|
||||
$this->category = $data["category"];
|
||||
$this->status = $data["status"];
|
||||
$this->name = $data["name"];
|
||||
$this->photo_urls = $data["photo_urls"];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets tags.
|
||||
* @return \Swagger\Client\Model\Tag[]
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets tags.
|
||||
* @param \Swagger\Client\Model\Tag[] $tags
|
||||
* @return $this
|
||||
*/
|
||||
public function setTags($tags)
|
||||
{
|
||||
|
||||
$this->tags = $tags;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets id.
|
||||
* @return int
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets id.
|
||||
* @param int $id
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets category.
|
||||
* @return object
|
||||
*/
|
||||
public function getCategory()
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets category.
|
||||
* @param object $category
|
||||
* @return $this
|
||||
*/
|
||||
public function setCategory($category)
|
||||
{
|
||||
|
||||
$this->category = $category;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets status.
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets status.
|
||||
* @param string $status pet status in the store
|
||||
* @return $this
|
||||
*/
|
||||
public function setStatus($status)
|
||||
{
|
||||
$allowed_values = array("available", "pending", "sold");
|
||||
if (!in_array($status, $allowed_values)) {
|
||||
throw new \InvalidArgumentException("Invalid value for 'status', must be one of 'available', 'pending', 'sold'");
|
||||
}
|
||||
$this->status = $status;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets name.
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets name.
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets photo_urls.
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPhotoUrls()
|
||||
{
|
||||
return $this->photo_urls;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets photo_urls.
|
||||
* @param string[] $photo_urls
|
||||
* @return $this
|
||||
*/
|
||||
public function setPhotoUrls($photo_urls)
|
||||
{
|
||||
|
||||
$this->photo_urls = $photo_urls;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if offset exists. False otherwise.
|
||||
* @param integer $offset Offset
|
||||
* @return boolean
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
{
|
||||
return isset($this->$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets offset.
|
||||
* @param integer $offset Offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
{
|
||||
return $this->$offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value based on offset.
|
||||
* @param integer $offset Offset
|
||||
* @param mixed $value Value to be set
|
||||
* @return void
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
{
|
||||
$this->$offset = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets offset.
|
||||
* @param integer $offset Offset
|
||||
* @return void
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
{
|
||||
unset($this->$offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string presentation of the object.
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
if (defined('JSON_PRETTY_PRINT')) {
|
||||
return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -256,7 +256,7 @@ class ObjectSerializer
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) {
|
||||
} elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) {
|
||||
settype($data, $class);
|
||||
return $data;
|
||||
} elseif ($class === '\SplFileObject') {
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* InlineResponse200Test
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Class
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
/**
|
||||
* Copyright 2016 SmartBear Software
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen
|
||||
* Please update the test case below to test the model.
|
||||
*/
|
||||
|
||||
namespace Swagger\Client\Model;
|
||||
|
||||
/**
|
||||
* InlineResponse200Test Class Doc Comment
|
||||
*
|
||||
* @category Class
|
||||
* @description
|
||||
* @package Swagger\Client
|
||||
* @author http://github.com/swagger-api/swagger-codegen
|
||||
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2
|
||||
* @link https://github.com/swagger-api/swagger-codegen
|
||||
*/
|
||||
class InlineResponse200Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Setup before running each test case
|
||||
*/
|
||||
public static function setUpBeforeClass() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up after running each test case
|
||||
*/
|
||||
public static function tearDownAfterClass() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test InlineResponse200
|
||||
*/
|
||||
public function testInlineResponse200() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -450,6 +450,20 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
|
||||
// test if default values works
|
||||
public function testDefaultValues()
|
||||
{
|
||||
// add some animals to the farm to make sure the ArrayAccess
|
||||
// interface works
|
||||
$dog = new Swagger\Client\Model\Dog();
|
||||
$animal = new Swagger\Client\Model\Animal();
|
||||
|
||||
// assert we can look up the animals in the farm by array
|
||||
// indices (let's try a random order)
|
||||
$this->assertSame('red', $dog->getColor());
|
||||
$this->assertSame('red', $animal->getColor());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user