From 74239c422b5a7cd12592d729b259ebf374e8602f Mon Sep 17 00:00:00 2001 From: wing328 Date: Sun, 26 Jun 2016 17:41:29 +0800 Subject: [PATCH] add enum class support, merged test cases for php --- .../io/swagger/codegen/CodegenProperty.java | 5 + .../io/swagger/codegen/DefaultCodegen.java | 1 + .../src/main/resources/php/api_test.mustache | 21 +- .../src/main/resources/php/model.mustache | 325 +---------------- .../main/resources/php/model_generic.mustache | 233 +++++++++--- .../main/resources/php/model_test.mustache | 31 +- samples/client/petstore/php/LICENSE | 201 +++++++++++ .../petstore/php/SwaggerClient-php/README.md | 20 +- .../php/SwaggerClient-php/docs/Api/FakeApi.md | 47 +++ .../docs/Model/ArrayOfArrayOfNumberOnly.md | 10 + .../docs/Model/ArrayOfNumberOnly.md | 10 + .../SwaggerClient-php/docs/Model/ArrayTest.md | 1 + .../docs/Model/HasOnlyReadOnly.md | 11 + .../SwaggerClient-php/docs/Model/MapTest.md | 12 + .../docs/Model/Model200Response.md | 1 + .../docs/Model/NumberOnly.md | 10 + .../php/SwaggerClient-php/lib/Api/FakeApi.php | 88 +++++ .../lib/Model/AdditionalPropertiesClass.php | 4 + .../SwaggerClient-php/lib/Model/Animal.php | 4 + .../lib/Model/AnimalFarm.php | 4 + .../lib/Model/ApiResponse.php | 4 + .../lib/Model/ArrayOfArrayOfNumberOnly.php | 238 +++++++++++++ .../lib/Model/ArrayOfNumberOnly.php | 238 +++++++++++++ .../SwaggerClient-php/lib/Model/ArrayTest.php | 61 +++- .../php/SwaggerClient-php/lib/Model/Cat.php | 4 + .../SwaggerClient-php/lib/Model/Category.php | 4 + .../php/SwaggerClient-php/lib/Model/Dog.php | 4 + .../SwaggerClient-php/lib/Model/EnumClass.php | 162 +-------- .../SwaggerClient-php/lib/Model/EnumTest.php | 4 + .../lib/Model/FormatTest.php | 4 + .../lib/Model/HasOnlyReadOnly.php | 264 ++++++++++++++ .../SwaggerClient-php/lib/Model/MapTest.php | 336 ++++++++++++++++++ ...PropertiesAndAdditionalPropertiesClass.php | 4 + .../lib/Model/Model200Response.php | 38 +- .../lib/Model/ModelReturn.php | 4 + .../php/SwaggerClient-php/lib/Model/Name.php | 4 + .../lib/Model/NumberOnly.php | 238 +++++++++++++ .../php/SwaggerClient-php/lib/Model/Order.php | 4 + .../php/SwaggerClient-php/lib/Model/Pet.php | 4 + .../lib/Model/ReadOnlyFirst.php | 4 + .../lib/Model/SpecialModelName.php | 4 + .../php/SwaggerClient-php/lib/Model/Tag.php | 4 + .../php/SwaggerClient-php/lib/Model/User.php | 4 + .../lib/ObjectSerializer.php | 2 +- .../petstore/php/SwaggerClient-php/pom.xml | 2 +- .../SwaggerClient-php/test/Api/PetApiTest.php | 323 +++++++++++++++-- .../test/Api/StoreApiTest.php | 63 +++- .../test/Api/UserApiTest.php | 47 ++- .../test/Client/ApiClientTest.php | 126 +++++++ .../test/Client/ObjectSerializerTest.php | 87 +++++ .../test/Model/AnimalFarmTest.php | 121 ++++++- .../Model/ArrayOfArrayOfNumberOnlyTest.php | 80 +++++ .../test/Model/ArrayOfNumberOnlyTest.php | 80 +++++ .../test/Model/EnumClassTest.php | 6 +- .../test/Model/EnumTestTest.php | 12 +- .../test/Model/HasOnlyReadOnlyTest.php | 80 +++++ .../test/Model/MapTestTest.php | 80 +++++ .../test/Model/NumberOnlyTest.php | 80 +++++ .../test/Model/OrderTest.php | 179 +++++++++- .../SwaggerClient-php/test/Model/PetTest.php | 87 ++++- 60 files changed, 3511 insertions(+), 618 deletions(-) create mode 100644 samples/client/petstore/php/LICENSE create mode 100644 samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayOfArrayOfNumberOnly.md create mode 100644 samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayOfNumberOnly.md create mode 100644 samples/client/petstore/php/SwaggerClient-php/docs/Model/HasOnlyReadOnly.md create mode 100644 samples/client/petstore/php/SwaggerClient-php/docs/Model/MapTest.md create mode 100644 samples/client/petstore/php/SwaggerClient-php/docs/Model/NumberOnly.md create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/test/Client/ApiClientTest.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/test/Client/ObjectSerializerTest.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/test/Model/ArrayOfArrayOfNumberOnlyTest.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/test/Model/ArrayOfNumberOnlyTest.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/test/Model/HasOnlyReadOnlyTest.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/test/Model/MapTestTest.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/test/Model/NumberOnlyTest.php diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java index eeef7777df2..8f6f716152d 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenProperty.java @@ -45,6 +45,7 @@ public class CodegenProperty implements Cloneable { public Map vendorExtensions; public Boolean hasValidation; // true if pattern, maximum, etc are set (only used in the mustache template) public Boolean isInherited; + public String nameInCamelCase; // property name in camel case @Override public String toString() { @@ -108,6 +109,7 @@ public class CodegenProperty implements Cloneable { result = prime * result + ((isMapContainer == null) ? 0 : isMapContainer.hashCode()); result = prime * result + ((isListContainer == null) ? 0 : isListContainer.hashCode()); result = prime * result + Objects.hashCode(isInherited); + result = prime * result + Objects.hashCode(nameInCamelCase); return result; } @@ -262,6 +264,9 @@ public class CodegenProperty implements Cloneable { if (!Objects.equals(this.isInherited, other.isInherited)) { return false; } + if (!Objects.equals(this.nameInCamelCase, other.nameInCamelCase)) { + return false; + } return true; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 75f63757893..72f5f6495a7 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1296,6 +1296,7 @@ public class DefaultCodegen { property.name = toVarName(name); property.baseName = name; + property.nameInCamelCase = camelize(name, false); property.description = escapeText(p.getDescription()); property.unescapedDescription = p.getDescription(); property.getter = "get" + getterAndSetterCapitalize(name); diff --git a/modules/swagger-codegen/src/main/resources/php/api_test.mustache b/modules/swagger-codegen/src/main/resources/php/api_test.mustache index c53cd6e1ad2..4b961b3236b 100644 --- a/modules/swagger-codegen/src/main/resources/php/api_test.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api_test.mustache @@ -17,7 +17,7 @@ * Please update the test case below to test the endpoint. */ -namespace {{apiPackage}}; +namespace {{invokerPackage}}; use \{{invokerPackage}}\Configuration; use \{{invokerPackage}}\ApiClient; @@ -37,16 +37,32 @@ use \{{invokerPackage}}\ObjectSerializer; { /** - * Setup before running each test case + * Setup before running any test cases */ public static function setUpBeforeClass() { } + /** + * Setup before running each test case + */ + public function setUp() + { + + } + /** * Clean up after running each test case */ + public function tearDown() + { + + } + + /** + * Clean up after running all test cases + */ public static function tearDownAfterClass() { @@ -63,6 +79,7 @@ use \{{invokerPackage}}\ObjectSerializer; { } + {{/operation}} } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/php/model.mustache b/modules/swagger-codegen/src/main/resources/php/model.mustache index 9fc2b620ddd..3265bb343da 100644 --- a/modules/swagger-codegen/src/main/resources/php/model.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model.mustache @@ -24,6 +24,8 @@ namespace {{modelPackage}}; use \ArrayAccess; + + /** * {{classname}} Class Doc Comment * @@ -36,328 +38,7 @@ use \ArrayAccess; * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2 * @link https://github.com/swagger-api/swagger-codegen */ -class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}implements ArrayAccess -{ - /** - * The original name of the model. - * @var string - */ - protected static $swaggerModelName = '{{name}}'; +{{#isEnum}}{{>model_enum}}{{/isEnum}}{{^isEnum}}{{>model_generic}}{{/isEnum}} - /** - * Array of property to type mappings. Used for (de)serialization - * @var string[] - */ - protected static $swaggerTypes = array( - {{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}}, - {{/hasMore}}{{/vars}} - ); - - public static function swaggerTypes() - { - return self::$swaggerTypes{{#parentSchema}} + parent::swaggerTypes(){{/parentSchema}}; - } - - /** - * Array of attributes where the key is the local name, and the value is the original name - * @var string[] - */ - protected static $attributeMap = array( - {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, - {{/hasMore}}{{/vars}} - ); - - public static function attributeMap() - { - return {{#parentSchema}}parent::attributeMap() + {{/parentSchema}}self::$attributeMap; - } - - /** - * Array of attributes to setter functions (for deserialization of responses) - * @var string[] - */ - protected static $setters = array( - {{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}}, - {{/hasMore}}{{/vars}} - ); - - public static function setters() - { - return {{#parentSchema}}parent::setters() + {{/parentSchema}}self::$setters; - } - - /** - * Array of attributes to getter functions (for serialization of requests) - * @var string[] - */ - protected static $getters = array( - {{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}}, - {{/hasMore}}{{/vars}} - ); - - public static function getters() - { - return {{#parentSchema}}parent::getters() + {{/parentSchema}}self::$getters; - } - - {{#vars}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}const {{datatypeWithEnum}}_{{{name}}} = {{{value}}}; - {{/enumVars}}{{/allowableValues}}{{/isEnum}}{{/vars}} - - {{#vars}}{{#isEnum}} - /** - * Gets allowable values of the enum - * @return string[] - */ - public function {{getter}}AllowableValues() - { - return [ - {{#allowableValues}}{{#enumVars}}self::{{datatypeWithEnum}}_{{{name}}},{{^-last}} - {{/-last}}{{/enumVars}}{{/allowableValues}} - ]; - } - {{/isEnum}}{{/vars}} - - /** - * Associative array for storing property values - * @var mixed[] - */ - protected $container = array(); - - /** - * Constructor - * @param mixed[] $data Associated array of property value initalizing the model - */ - public function __construct(array $data = null) - { - {{#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}} - } - - /** - * show all the invalid properties with reasons. - * - * @return array invalid properties with reasons - */ - public function listInvalidProperties() - { - $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 properties in the model - * return true if all passed - * - * @return bool True if all properteis are valid - */ - 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}} - * @return {{datatype}} - */ - public function {{getter}}() - { - return $this->container['{{name}}']; - } - - /** - * Sets {{name}} - * @param {{datatype}} ${{name}}{{#description}} {{{description}}}{{/description}} - * @return $this - */ - public function {{setter}}(${{name}}) - { - {{#isEnum}} - $allowed_values = array({{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}); - if (!in_array(${{{name}}}, $allowed_values)) { - throw new \InvalidArgumentException("Invalid value for '{{name}}', must be one of {{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}"); - } - {{/isEnum}} - {{#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}} - /** - * Returns true if offset exists. False otherwise. - * @param integer $offset Offset - * @return boolean - */ - public function offsetExists($offset) - { - return isset($this->container[$offset]); - } - - /** - * Gets offset. - * @param integer $offset Offset - * @return mixed - */ - public function offsetGet($offset) - { - return isset($this->container[$offset]) ? $this->container[$offset] : null; - } - - /** - * Sets value based on offset. - * @param integer $offset Offset - * @param mixed $value Value to be set - * @return void - */ - public function offsetSet($offset, $value) - { - if (is_null($offset)) { - $this->container[] = $value; - } else { - $this->container[$offset] = $value; - } - } - - /** - * Unsets offset. - * @param integer $offset Offset - * @return void - */ - public function offsetUnset($offset) - { - unset($this->container[$offset]); - } - - /** - * Gets the string presentation of the object - * @return string - */ - public function __toString() - { - if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print - return json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); - } - - return json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($this)); - } -} {{/model}} {{/models}} diff --git a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache index 22f97456e04..6e4a3e03f99 100644 --- a/modules/swagger-codegen/src/main/resources/php/model_generic.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model_generic.mustache @@ -1,59 +1,65 @@ -class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayAccess +class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}implements ArrayAccess { /** - * Array of property to type mappings. Used for (de)serialization - * @var string[] - */ - static $swaggerTypes = array( + * The original name of the model. + * @var string + */ + protected static $swaggerModelName = '{{name}}'; + + /** + * Array of property to type mappings. Used for (de)serialization + * @var string[] + */ + protected static $swaggerTypes = array( {{#vars}}'{{name}}' => '{{{datatype}}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); - static function swaggerTypes() + public static function swaggerTypes() { - return self::$swaggerTypes{{#parent}} + parent::swaggerTypes(){{/parent}}; + return self::$swaggerTypes{{#parentSchema}} + parent::swaggerTypes(){{/parentSchema}}; } /** * Array of attributes where the key is the local name, and the value is the original name * @var string[] */ - static $attributeMap = array( + protected static $attributeMap = array( {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); - static function attributeMap() + public static function attributeMap() { - return {{#parent}}parent::attributeMap() + {{/parent}}self::$attributeMap; + return {{#parentSchema}}parent::attributeMap() + {{/parentSchema}}self::$attributeMap; } /** * Array of attributes to setter functions (for deserialization of responses) * @var string[] */ - static $setters = array( + protected static $setters = array( {{#vars}}'{{name}}' => '{{setter}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); - static function setters() + public static function setters() { - return {{#parent}}parent::setters() + {{/parent}}self::$setters; + return {{#parentSchema}}parent::setters() + {{/parentSchema}}self::$setters; } /** * Array of attributes to getter functions (for serialization of requests) * @var string[] */ - static $getters = array( + protected static $getters = array( {{#vars}}'{{name}}' => '{{getter}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); - static function getters() + public static function getters() { - return {{#parent}}parent::getters() + {{/parent}}self::$getters; + return {{#parentSchema}}parent::getters() + {{/parentSchema}}self::$getters; } {{#vars}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}const {{datatypeWithEnum}}_{{{name}}} = {{{value}}}; @@ -73,13 +79,11 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA } {{/isEnum}}{{/vars}} - {{#vars}} /** - * ${{name}} {{#description}}{{{description}}}{{/description}} - * @var {{datatype}} + * Associative array for storing property values + * @var mixed[] */ - protected ${{name}}{{#defaultValue}} = {{{defaultValue}}}{{/defaultValue}}; - {{/vars}} + protected $container = array(); /** * Constructor @@ -87,34 +91,175 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA */ public function __construct(array $data = null) { - {{#parent}}parent::__construct($data);{{/parent}} - if ($data != null) { - {{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}} - {{/hasMore}}{{/vars}} - } + {{#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}} } - {{#vars}} + /** - * Gets {{name}}. + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $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 properties in the model + * return true if all passed + * + * @return bool True if all properteis are valid + */ + 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}} * @return {{datatype}} */ public function {{getter}}() { - return $this->{{name}}; + return $this->container['{{name}}']; } /** - * Sets {{name}}. - * @param {{datatype}} ${{name}} {{#description}}{{{description}}}{{/description}} + * Sets {{name}} + * @param {{datatype}} ${{name}}{{#description}} {{{description}}}{{/description}} * @return $this */ 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}} - $this->{{name}} = ${{name}}; + } + {{/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}} @@ -125,7 +270,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA */ public function offsetExists($offset) { - return isset($this->$offset); + return isset($this->container[$offset]); } /** @@ -135,7 +280,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA */ public function offsetGet($offset) { - return $this->$offset; + return isset($this->container[$offset]) ? $this->container[$offset] : null; } /** @@ -146,7 +291,11 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA */ public function offsetSet($offset, $value) { - $this->$offset = $value; + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } } /** @@ -156,19 +305,19 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA */ public function offsetUnset($offset) { - unset($this->$offset); + unset($this->container[$offset]); } /** - * Gets the string presentation of the object. + * Gets the string presentation of the object * @return string */ public function __toString() { - if (defined('JSON_PRETTY_PRINT')) { + if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print return json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); - } else { - return json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($this)); } + + return json_encode(\{{invokerPackage}}\ObjectSerializer::sanitizeForSerialization($this)); } } diff --git a/modules/swagger-codegen/src/main/resources/php/model_test.mustache b/modules/swagger-codegen/src/main/resources/php/model_test.mustache index d7d93f32186..5b2a989745a 100644 --- a/modules/swagger-codegen/src/main/resources/php/model_test.mustache +++ b/modules/swagger-codegen/src/main/resources/php/model_test.mustache @@ -20,7 +20,7 @@ * Please update the test case below to test the model. */ -namespace {{modelPackage}}; +namespace {{invokerPackage}}; /** * {{classname}}Test Class Doc Comment @@ -36,16 +36,32 @@ class {{classname}}Test extends \PHPUnit_Framework_TestCase { /** - * Setup before running each test case + * Setup before running any test case */ public static function setUpBeforeClass() { } + /** + * Setup before running each test case + */ + public function setUp() + { + + } + /** * Clean up after running each test case */ + public function tearDown() + { + + } + + /** + * Clean up after running all test cases + */ public static function tearDownAfterClass() { @@ -58,6 +74,17 @@ class {{classname}}Test extends \PHPUnit_Framework_TestCase { } + +{{#vars}} + /** + * Test attribute "{{name}}" + */ + public function testProperty{{nameInCamelCase}}() + { + + } + +{{/vars}} } {{/model}} {{/models}} diff --git a/samples/client/petstore/php/LICENSE b/samples/client/petstore/php/LICENSE new file mode 100644 index 00000000000..8dada3edaf5 --- /dev/null +++ b/samples/client/petstore/php/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + 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. diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md index 4a5af697efb..4d0fb4ac521 100644 --- a/samples/client/petstore/php/SwaggerClient-php/README.md +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -4,7 +4,7 @@ This spec is mainly for testing Petstore server and contains fake endpoints, mod This PHP package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project: - API version: 1.0.0 -- Build date: 2016-06-13T23:22:10.454+02:00 +- Build date: 2016-06-26T17:14:27.763+08:00 - Build package: class io.swagger.codegen.languages.PhpClientCodegen ## Requirements @@ -87,6 +87,7 @@ All URIs are relative to *http://petstore.swagger.io/v2* Class | Method | HTTP request | Description ------------ | ------------- | ------------- | ------------- *FakeApi* | [**testEndpointParameters**](docs/Api/FakeApi.md#testendpointparameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트 +*FakeApi* | [**testEnumQueryParameters**](docs/Api/FakeApi.md#testenumqueryparameters) | **GET** /fake | To test enum query parameters *PetApi* | [**addPet**](docs/Api/PetApi.md#addpet) | **POST** /pet | Add a new pet to the store *PetApi* | [**deletePet**](docs/Api/PetApi.md#deletepet) | **DELETE** /pet/{petId} | Deletes a pet *PetApi* | [**findPetsByStatus**](docs/Api/PetApi.md#findpetsbystatus) | **GET** /pet/findByStatus | Finds Pets by status @@ -115,6 +116,8 @@ Class | Method | HTTP request | Description - [Animal](docs/Model/Animal.md) - [AnimalFarm](docs/Model/AnimalFarm.md) - [ApiResponse](docs/Model/ApiResponse.md) + - [ArrayOfArrayOfNumberOnly](docs/Model/ArrayOfArrayOfNumberOnly.md) + - [ArrayOfNumberOnly](docs/Model/ArrayOfNumberOnly.md) - [ArrayTest](docs/Model/ArrayTest.md) - [Cat](docs/Model/Cat.md) - [Category](docs/Model/Category.md) @@ -122,10 +125,13 @@ Class | Method | HTTP request | Description - [EnumClass](docs/Model/EnumClass.md) - [EnumTest](docs/Model/EnumTest.md) - [FormatTest](docs/Model/FormatTest.md) + - [HasOnlyReadOnly](docs/Model/HasOnlyReadOnly.md) + - [MapTest](docs/Model/MapTest.md) - [MixedPropertiesAndAdditionalPropertiesClass](docs/Model/MixedPropertiesAndAdditionalPropertiesClass.md) - [Model200Response](docs/Model/Model200Response.md) - [ModelReturn](docs/Model/ModelReturn.md) - [Name](docs/Model/Name.md) + - [NumberOnly](docs/Model/NumberOnly.md) - [Order](docs/Model/Order.md) - [Pet](docs/Model/Pet.md) - [ReadOnlyFirst](docs/Model/ReadOnlyFirst.md) @@ -137,6 +143,12 @@ Class | Method | HTTP request | Description ## Documentation For Authorization +## api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + ## petstore_auth - **Type**: OAuth @@ -146,12 +158,6 @@ Class | Method | HTTP request | Description - **write:pets**: modify pets in your account - **read:pets**: read your pets -## api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - ## Author diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md index 77073b42e69..3ca55218e36 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Api/FakeApi.md @@ -5,6 +5,7 @@ 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 假端點 偽のエンドポイント 가짜 엔드 포인트 +[**testEnumQueryParameters**](FakeApi.md#testEnumQueryParameters) | **GET** /fake | To test enum query parameters # **testEndpointParameters** @@ -73,3 +74,49 @@ No authorization required [[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) +# **testEnumQueryParameters** +> testEnumQueryParameters($enum_query_string, $enum_query_integer, $enum_query_double) + +To test enum query parameters + +### Example +```php +testEnumQueryParameters($enum_query_string, $enum_query_integer, $enum_query_double); +} catch (Exception $e) { + echo 'Exception when calling FakeApi->testEnumQueryParameters: ', $e->getMessage(), PHP_EOL; +} +?> +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **enum_query_string** | **string**| Query parameter enum test (string) | [optional] [default to -efg] + **enum_query_integer** | **float**| Query parameter enum test (double) | [optional] + **enum_query_double** | **double**| Query parameter enum test (double) | [optional] + +### Return type + +void (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../../README.md#documentation-for-api-endpoints) [[Back to Model list]](../../README.md#documentation-for-models) [[Back to README]](../../README.md) + diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayOfArrayOfNumberOnly.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayOfArrayOfNumberOnly.md new file mode 100644 index 00000000000..7831e189888 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayOfArrayOfNumberOnly.md @@ -0,0 +1,10 @@ +# ArrayOfArrayOfNumberOnly + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**array_array_number** | [**float[][]**](array.md) | | [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) + + diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayOfNumberOnly.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayOfNumberOnly.md new file mode 100644 index 00000000000..a32607e4201 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayOfNumberOnly.md @@ -0,0 +1,10 @@ +# ArrayOfNumberOnly + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**array_number** | **float[]** | | [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) + + diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayTest.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayTest.md index f982dc2e4c7..0f7f3a44e9e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayTest.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/ArrayTest.md @@ -6,6 +6,7 @@ Name | Type | Description | Notes **array_of_string** | **string[]** | | [optional] **array_array_of_integer** | [**int[][]**](array.md) | | [optional] **array_array_of_model** | [**\Swagger\Client\Model\ReadOnlyFirst[][]**](array.md) | | [optional] +**array_of_enum** | **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) diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/HasOnlyReadOnly.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/HasOnlyReadOnly.md new file mode 100644 index 00000000000..5e64572b781 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/HasOnlyReadOnly.md @@ -0,0 +1,11 @@ +# HasOnlyReadOnly + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**bar** | **string** | | [optional] +**foo** | **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) + + diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/MapTest.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/MapTest.md new file mode 100644 index 00000000000..731d6bd1de4 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/MapTest.md @@ -0,0 +1,12 @@ +# MapTest + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**map_map_of_string** | [**map[string,map[string,string]]**](map.md) | | [optional] +**map_map_of_enum** | [**map[string,map[string,string]]**](map.md) | | [optional] +**map_of_enum_string** | **map[string,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) + + diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/Model200Response.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/Model200Response.md index e29747a87e7..ebbea5c68af 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Model/Model200Response.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/Model200Response.md @@ -4,6 +4,7 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **name** | **int** | | [optional] +**class** | **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) diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/NumberOnly.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/NumberOnly.md new file mode 100644 index 00000000000..93a0fde7b93 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/NumberOnly.md @@ -0,0 +1,10 @@ +# NumberOnly + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**just_number** | **float** | | [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) + + 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 b916802b2ea..16cea9884d5 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/FakeApi.php @@ -295,6 +295,94 @@ class FakeApi switch ($e->getCode()) { } + throw $e; + } + } + /** + * Operation testEnumQueryParameters + * + * To test enum query parameters. + * + * @param string $enum_query_string Query parameter enum test (string) (optional, default to -efg) + * @param float $enum_query_integer Query parameter enum test (double) (optional) + * @param double $enum_query_double Query parameter enum test (double) (optional) + * + * @return void + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function testEnumQueryParameters($enum_query_string = null, $enum_query_integer = null, $enum_query_double = null) + { + list($response) = $this->testEnumQueryParametersWithHttpInfo($enum_query_string, $enum_query_integer, $enum_query_double); + return $response; + } + + + /** + * Operation testEnumQueryParametersWithHttpInfo + * + * To test enum query parameters. + * + * @param string $enum_query_string Query parameter enum test (string) (optional, default to -efg) + * @param float $enum_query_integer Query parameter enum test (double) (optional) + * @param double $enum_query_double Query parameter enum test (double) (optional) + * + * @return Array of null, HTTP status code, HTTP response headers (array of strings) + * @throws \Swagger\Client\ApiException on non-2xx response + */ + public function testEnumQueryParametersWithHttpInfo($enum_query_string = null, $enum_query_integer = null, $enum_query_double = null) + { + + // parse inputs + $resourcePath = "/fake"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json')); + + // query params + if ($enum_query_integer !== null) { + $queryParams['enum_query_integer'] = $this->apiClient->getSerializer()->toQueryValue($enum_query_integer); + } + + + // default format to json + $resourcePath = str_replace("{format}", "json", $resourcePath); + + // form params + if ($enum_query_string !== null) { + $formParams['enum_query_string'] = $this->apiClient->getSerializer()->toFormValue($enum_query_string); + }// form params + if ($enum_query_double !== null) { + $formParams['enum_query_double'] = $this->apiClient->getSerializer()->toFormValue($enum_query_double); + } + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } elseif (count($formParams) > 0) { + $httpBody = $formParams; // for HTTP post (form) + } + // make the API Call + try { + list($response, $statusCode, $httpHeader) = $this->apiClient->callApi( + $resourcePath, + 'GET', + $queryParams, + $httpBody, + $headerParams + ); + + return array(null, $statusCode, $httpHeader); + } catch (ApiException $e) { + switch ($e->getCode()) { + } + throw $e; } } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php index 9b77e2bf1ca..5a557dade7f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AdditionalPropertiesClass.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * AdditionalPropertiesClass Class Doc Comment * @@ -258,3 +260,5 @@ class AdditionalPropertiesClass implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); } } + + 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 33ee60a0b7a..f7de132b344 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Animal.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Animal Class Doc Comment * @@ -268,3 +270,5 @@ class Animal implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 e9857f27f76..149442d7503 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/AnimalFarm.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * AnimalFarm Class Doc Comment * @@ -210,3 +212,5 @@ class AnimalFarm implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 fc9c4c2abed..9ac45c85160 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ApiResponse.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * ApiResponse Class Doc Comment * @@ -284,3 +286,5 @@ class ApiResponse implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); } } + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php new file mode 100644 index 00000000000..42b77512d57 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfArrayOfNumberOnly.php @@ -0,0 +1,238 @@ + 'float[][]' + ); + + public 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[] + */ + protected static $attributeMap = array( + 'array_array_number' => 'ArrayArrayNumber' + ); + + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ + protected static $setters = array( + 'array_array_number' => 'setArrayArrayNumber' + ); + + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ + protected static $getters = array( + 'array_array_number' => 'getArrayArrayNumber' + ); + + public static function getters() + { + return self::$getters; + } + + + + + + /** + * Associative array for storing property values + * @var mixed[] + */ + protected $container = array(); + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { + $this->container['array_array_number'] = isset($data['array_array_number']) ? $data['array_array_number'] : null; + } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $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; + } + + + /** + * Gets array_array_number + * @return float[][] + */ + public function getArrayArrayNumber() + { + return $this->container['array_array_number']; + } + + /** + * Sets array_array_number + * @param float[][] $array_array_number + * @return $this + */ + public function setArrayArrayNumber($array_array_number) + { + $this->container['array_array_number'] = $array_array_number; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } + + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { + if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); + } + + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php new file mode 100644 index 00000000000..df2c87d3665 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayOfNumberOnly.php @@ -0,0 +1,238 @@ + 'float[]' + ); + + public 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[] + */ + protected static $attributeMap = array( + 'array_number' => 'ArrayNumber' + ); + + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ + protected static $setters = array( + 'array_number' => 'setArrayNumber' + ); + + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ + protected static $getters = array( + 'array_number' => 'getArrayNumber' + ); + + public static function getters() + { + return self::$getters; + } + + + + + + /** + * Associative array for storing property values + * @var mixed[] + */ + protected $container = array(); + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { + $this->container['array_number'] = isset($data['array_number']) ? $data['array_number'] : null; + } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $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; + } + + + /** + * Gets array_number + * @return float[] + */ + public function getArrayNumber() + { + return $this->container['array_number']; + } + + /** + * Sets array_number + * @param float[] $array_number + * @return $this + */ + public function setArrayNumber($array_number) + { + $this->container['array_number'] = $array_number; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } + + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { + if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); + } + + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php index e1a4ea91179..cc11165f8d2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ArrayTest.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * ArrayTest Class Doc Comment * @@ -67,7 +69,8 @@ class ArrayTest implements ArrayAccess protected static $swaggerTypes = array( 'array_of_string' => 'string[]', 'array_array_of_integer' => 'int[][]', - 'array_array_of_model' => '\Swagger\Client\Model\ReadOnlyFirst[][]' + 'array_array_of_model' => '\Swagger\Client\Model\ReadOnlyFirst[][]', + 'array_of_enum' => 'string[]' ); public static function swaggerTypes() @@ -82,7 +85,8 @@ class ArrayTest implements ArrayAccess protected static $attributeMap = array( 'array_of_string' => 'array_of_string', 'array_array_of_integer' => 'array_array_of_integer', - 'array_array_of_model' => 'array_array_of_model' + 'array_array_of_model' => 'array_array_of_model', + 'array_of_enum' => 'array_of_enum' ); public static function attributeMap() @@ -97,7 +101,8 @@ class ArrayTest implements ArrayAccess protected static $setters = array( 'array_of_string' => 'setArrayOfString', 'array_array_of_integer' => 'setArrayArrayOfInteger', - 'array_array_of_model' => 'setArrayArrayOfModel' + 'array_array_of_model' => 'setArrayArrayOfModel', + 'array_of_enum' => 'setArrayOfEnum' ); public static function setters() @@ -112,7 +117,8 @@ class ArrayTest implements ArrayAccess protected static $getters = array( 'array_of_string' => 'getArrayOfString', 'array_array_of_integer' => 'getArrayArrayOfInteger', - 'array_array_of_model' => 'getArrayArrayOfModel' + 'array_array_of_model' => 'getArrayArrayOfModel', + 'array_of_enum' => 'getArrayOfEnum' ); public static function getters() @@ -123,6 +129,17 @@ class ArrayTest implements ArrayAccess + /** + * Gets allowable values of the enum + * @return string[] + */ + public function getArrayOfEnumAllowableValues() + { + return [ + + ]; + } + /** * Associative array for storing property values @@ -139,6 +156,7 @@ class ArrayTest implements ArrayAccess $this->container['array_of_string'] = isset($data['array_of_string']) ? $data['array_of_string'] : null; $this->container['array_array_of_integer'] = isset($data['array_array_of_integer']) ? $data['array_array_of_integer'] : null; $this->container['array_array_of_model'] = isset($data['array_array_of_model']) ? $data['array_array_of_model'] : null; + $this->container['array_of_enum'] = isset($data['array_of_enum']) ? $data['array_of_enum'] : null; } /** @@ -149,6 +167,10 @@ class ArrayTest implements ArrayAccess public function listInvalidProperties() { $invalid_properties = array(); + $allowed_values = array(); + if (!in_array($this->container['array_of_enum'], $allowed_values)) { + $invalid_properties[] = "invalid value for 'array_of_enum', must be one of #{allowed_values}."; + } return $invalid_properties; } @@ -160,6 +182,10 @@ class ArrayTest implements ArrayAccess */ public function valid() { + $allowed_values = array(); + if (!in_array($this->container['array_of_enum'], $allowed_values)) { + return false; + } return true; } @@ -226,6 +252,31 @@ class ArrayTest implements ArrayAccess return $this; } + + /** + * Gets array_of_enum + * @return string[] + */ + public function getArrayOfEnum() + { + return $this->container['array_of_enum']; + } + + /** + * Sets array_of_enum + * @param string[] $array_of_enum + * @return $this + */ + public function setArrayOfEnum($array_of_enum) + { + $allowed_values = array(); + if (!in_array($array_of_enum, $allowed_values)) { + throw new \InvalidArgumentException("Invalid value for 'array_of_enum', must be one of "); + } + $this->container['array_of_enum'] = $array_of_enum; + + return $this; + } /** * Returns true if offset exists. False otherwise. * @param integer $offset Offset @@ -284,3 +335,5 @@ class ArrayTest implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 efabd53cbbc..952a5962347 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Cat.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Cat Class Doc Comment * @@ -234,3 +236,5 @@ class Cat extends Animal implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 d9ff6aa58e2..9841dac9568 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Category Class Doc Comment * @@ -258,3 +260,5 @@ class Category implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 081fbd4837d..b82ca4a6909 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Dog.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Dog Class Doc Comment * @@ -234,3 +236,5 @@ class Dog extends Animal implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 4c67a277dde..bb9ae95ed4e 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumClass.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * EnumClass Class Doc Comment * @@ -52,161 +54,13 @@ use \ArrayAccess; * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2 * @link https://github.com/swagger-api/swagger-codegen */ -class EnumClass implements ArrayAccess -{ - /** - * The original name of the model. - * @var string - */ - protected static $swaggerModelName = 'EnumClass'; - - /** - * Array of property to type mappings. Used for (de)serialization - * @var string[] - */ - protected static $swaggerTypes = array( - - ); - - public 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[] - */ - protected static $attributeMap = array( - - ); - - public static function attributeMap() - { - return self::$attributeMap; - } - - /** - * Array of attributes to setter functions (for deserialization of responses) - * @var string[] - */ - protected static $setters = array( - - ); - - public static function setters() - { - return self::$setters; - } - - /** - * Array of attributes to getter functions (for serialization of requests) - * @var string[] - */ - protected static $getters = array( - - ); - - public static function getters() - { - return self::$getters; - } - +class EnumClass { + const ABC = '_abc'; + const EFG = '-efg'; + const XYZ = '(xyz)'; - - /** - * Associative array for storing property values - * @var mixed[] - */ - protected $container = array(); - - /** - * Constructor - * @param mixed[] $data Associated array of property value initalizing the model - */ - public function __construct(array $data = null) - { - } - - /** - * show all the invalid properties with reasons. - * - * @return array invalid properties with reasons - */ - public function listInvalidProperties() - { - $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 - * @return boolean - */ - public function offsetExists($offset) - { - return isset($this->container[$offset]); - } - - /** - * Gets offset. - * @param integer $offset Offset - * @return mixed - */ - public function offsetGet($offset) - { - return isset($this->container[$offset]) ? $this->container[$offset] : null; - } - - /** - * Sets value based on offset. - * @param integer $offset Offset - * @param mixed $value Value to be set - * @return void - */ - public function offsetSet($offset, $value) - { - if (is_null($offset)) { - $this->container[] = $value; - } else { - $this->container[$offset] = $value; - } - } - - /** - * Unsets offset. - * @param integer $offset Offset - * @return void - */ - public function offsetUnset($offset) - { - unset($this->container[$offset]); - } - - /** - * Gets the string presentation of the object - * @return string - */ - public function __toString() - { - if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print - return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); - } - - return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); - } } + + 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 673b3ce3624..9d7ca2dd799 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/EnumTest.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * EnumTest Class Doc Comment * @@ -362,3 +364,5 @@ class EnumTest implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 e9b8bc9cf7f..a25bfd72913 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/FormatTest.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * FormatTest Class Doc Comment * @@ -691,3 +693,5 @@ class FormatTest implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); } } + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php new file mode 100644 index 00000000000..4e58162e536 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/HasOnlyReadOnly.php @@ -0,0 +1,264 @@ + 'string', + 'foo' => 'string' + ); + + public 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[] + */ + protected static $attributeMap = array( + 'bar' => 'bar', + 'foo' => 'foo' + ); + + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ + protected static $setters = array( + 'bar' => 'setBar', + 'foo' => 'setFoo' + ); + + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ + protected static $getters = array( + 'bar' => 'getBar', + 'foo' => 'getFoo' + ); + + public static function getters() + { + return self::$getters; + } + + + + + + /** + * Associative array for storing property values + * @var mixed[] + */ + protected $container = array(); + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { + $this->container['bar'] = isset($data['bar']) ? $data['bar'] : null; + $this->container['foo'] = isset($data['foo']) ? $data['foo'] : null; + } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $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; + } + + + /** + * Gets bar + * @return string + */ + public function getBar() + { + return $this->container['bar']; + } + + /** + * Sets bar + * @param string $bar + * @return $this + */ + public function setBar($bar) + { + $this->container['bar'] = $bar; + + return $this; + } + + /** + * Gets foo + * @return string + */ + public function getFoo() + { + return $this->container['foo']; + } + + /** + * Sets foo + * @param string $foo + * @return $this + */ + public function setFoo($foo) + { + $this->container['foo'] = $foo; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } + + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { + if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); + } + + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php new file mode 100644 index 00000000000..e2751af93c3 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MapTest.php @@ -0,0 +1,336 @@ + 'map[string,map[string,string]]', + 'map_map_of_enum' => 'map[string,map[string,string]]', + 'map_of_enum_string' => 'map[string,string]' + ); + + public 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[] + */ + protected static $attributeMap = array( + 'map_map_of_string' => 'map_map_of_string', + 'map_map_of_enum' => 'map_map_of_enum', + 'map_of_enum_string' => 'map_of_enum_string' + ); + + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ + protected static $setters = array( + 'map_map_of_string' => 'setMapMapOfString', + 'map_map_of_enum' => 'setMapMapOfEnum', + 'map_of_enum_string' => 'setMapOfEnumString' + ); + + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ + protected static $getters = array( + 'map_map_of_string' => 'getMapMapOfString', + 'map_map_of_enum' => 'getMapMapOfEnum', + 'map_of_enum_string' => 'getMapOfEnumString' + ); + + public static function getters() + { + return self::$getters; + } + + + + + /** + * Gets allowable values of the enum + * @return string[] + */ + public function getMapMapOfEnumAllowableValues() + { + return [ + + ]; + } + + /** + * Gets allowable values of the enum + * @return string[] + */ + public function getMapOfEnumStringAllowableValues() + { + return [ + + ]; + } + + + /** + * Associative array for storing property values + * @var mixed[] + */ + protected $container = array(); + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { + $this->container['map_map_of_string'] = isset($data['map_map_of_string']) ? $data['map_map_of_string'] : null; + $this->container['map_map_of_enum'] = isset($data['map_map_of_enum']) ? $data['map_map_of_enum'] : null; + $this->container['map_of_enum_string'] = isset($data['map_of_enum_string']) ? $data['map_of_enum_string'] : null; + } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalid_properties = array(); + $allowed_values = array(); + if (!in_array($this->container['map_map_of_enum'], $allowed_values)) { + $invalid_properties[] = "invalid value for 'map_map_of_enum', must be one of #{allowed_values}."; + } + $allowed_values = array(); + if (!in_array($this->container['map_of_enum_string'], $allowed_values)) { + $invalid_properties[] = "invalid value for 'map_of_enum_string', 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(); + if (!in_array($this->container['map_map_of_enum'], $allowed_values)) { + return false; + } + $allowed_values = array(); + if (!in_array($this->container['map_of_enum_string'], $allowed_values)) { + return false; + } + return true; + } + + + /** + * Gets map_map_of_string + * @return map[string,map[string,string]] + */ + public function getMapMapOfString() + { + return $this->container['map_map_of_string']; + } + + /** + * Sets map_map_of_string + * @param map[string,map[string,string]] $map_map_of_string + * @return $this + */ + public function setMapMapOfString($map_map_of_string) + { + $this->container['map_map_of_string'] = $map_map_of_string; + + return $this; + } + + /** + * Gets map_map_of_enum + * @return map[string,map[string,string]] + */ + public function getMapMapOfEnum() + { + return $this->container['map_map_of_enum']; + } + + /** + * Sets map_map_of_enum + * @param map[string,map[string,string]] $map_map_of_enum + * @return $this + */ + public function setMapMapOfEnum($map_map_of_enum) + { + $allowed_values = array(); + if (!in_array($map_map_of_enum, $allowed_values)) { + throw new \InvalidArgumentException("Invalid value for 'map_map_of_enum', must be one of "); + } + $this->container['map_map_of_enum'] = $map_map_of_enum; + + return $this; + } + + /** + * Gets map_of_enum_string + * @return map[string,string] + */ + public function getMapOfEnumString() + { + return $this->container['map_of_enum_string']; + } + + /** + * Sets map_of_enum_string + * @param map[string,string] $map_of_enum_string + * @return $this + */ + public function setMapOfEnumString($map_of_enum_string) + { + $allowed_values = array(); + if (!in_array($map_of_enum_string, $allowed_values)) { + throw new \InvalidArgumentException("Invalid value for 'map_of_enum_string', must be one of "); + } + $this->container['map_of_enum_string'] = $map_of_enum_string; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } + + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { + if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); + } + + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); + } +} + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php index c7ec6100988..d9756b70107 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/MixedPropertiesAndAdditionalPropertiesClass.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * MixedPropertiesAndAdditionalPropertiesClass Class Doc Comment * @@ -284,3 +286,5 @@ class MixedPropertiesAndAdditionalPropertiesClass implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 f6d9a4e2e10..bb2f1c6e98b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Model200Response.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Model200Response Class Doc Comment * @@ -66,7 +68,8 @@ class Model200Response implements ArrayAccess * @var string[] */ protected static $swaggerTypes = array( - 'name' => 'int' + 'name' => 'int', + 'class' => 'string' ); public static function swaggerTypes() @@ -79,7 +82,8 @@ class Model200Response implements ArrayAccess * @var string[] */ protected static $attributeMap = array( - 'name' => 'name' + 'name' => 'name', + 'class' => 'class' ); public static function attributeMap() @@ -92,7 +96,8 @@ class Model200Response implements ArrayAccess * @var string[] */ protected static $setters = array( - 'name' => 'setName' + 'name' => 'setName', + 'class' => 'setClass' ); public static function setters() @@ -105,7 +110,8 @@ class Model200Response implements ArrayAccess * @var string[] */ protected static $getters = array( - 'name' => 'getName' + 'name' => 'getName', + 'class' => 'getClass' ); public static function getters() @@ -130,6 +136,7 @@ class Model200Response implements ArrayAccess public function __construct(array $data = null) { $this->container['name'] = isset($data['name']) ? $data['name'] : null; + $this->container['class'] = isset($data['class']) ? $data['class'] : null; } /** @@ -175,6 +182,27 @@ class Model200Response implements ArrayAccess return $this; } + + /** + * Gets class + * @return string + */ + public function getClass() + { + return $this->container['class']; + } + + /** + * Sets class + * @param string $class + * @return $this + */ + public function setClass($class) + { + $this->container['class'] = $class; + + return $this; + } /** * Returns true if offset exists. False otherwise. * @param integer $offset Offset @@ -233,3 +261,5 @@ class Model200Response implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 f39fbd0bdef..5207932e817 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ModelReturn.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * ModelReturn Class Doc Comment * @@ -233,3 +235,5 @@ class ModelReturn implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 32dac8410f2..54b0afec715 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Name.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Name Class Doc Comment * @@ -317,3 +319,5 @@ class Name implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); } } + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php new file mode 100644 index 00000000000..e246240b2c8 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/NumberOnly.php @@ -0,0 +1,238 @@ + 'float' + ); + + public 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[] + */ + protected static $attributeMap = array( + 'just_number' => 'JustNumber' + ); + + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * @var string[] + */ + protected static $setters = array( + 'just_number' => 'setJustNumber' + ); + + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * @var string[] + */ + protected static $getters = array( + 'just_number' => 'getJustNumber' + ); + + public static function getters() + { + return self::$getters; + } + + + + + + /** + * Associative array for storing property values + * @var mixed[] + */ + protected $container = array(); + + /** + * Constructor + * @param mixed[] $data Associated array of property value initalizing the model + */ + public function __construct(array $data = null) + { + $this->container['just_number'] = isset($data['just_number']) ? $data['just_number'] : null; + } + + /** + * show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $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; + } + + + /** + * Gets just_number + * @return float + */ + public function getJustNumber() + { + return $this->container['just_number']; + } + + /** + * Sets just_number + * @param float $just_number + * @return $this + */ + public function setJustNumber($just_number) + { + $this->container['just_number'] = $just_number; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * @param integer $offset Offset + * @return boolean + */ + public function offsetExists($offset) + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * @param integer $offset Offset + * @return mixed + */ + public function offsetGet($offset) + { + return isset($this->container[$offset]) ? $this->container[$offset] : null; + } + + /** + * Sets value based on offset. + * @param integer $offset Offset + * @param mixed $value Value to be set + * @return void + */ + public function offsetSet($offset, $value) + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * @param integer $offset Offset + * @return void + */ + public function offsetUnset($offset) + { + unset($this->container[$offset]); + } + + /** + * Gets the string presentation of the object + * @return string + */ + public function __toString() + { + if (defined('JSON_PRETTY_PRINT')) { // use JSON pretty print + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this), JSON_PRETTY_PRINT); + } + + return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 cf5f61a9640..84fae7b4ee5 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Order Class Doc Comment * @@ -390,3 +392,5 @@ class Order implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 a81e9eb33f9..ae98dad6cc9 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Pet Class Doc Comment * @@ -402,3 +404,5 @@ class Pet implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); } } + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php index 22e534a51e5..df01af98f4a 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/ReadOnlyFirst.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * ReadOnlyFirst Class Doc Comment * @@ -258,3 +260,5 @@ class ReadOnlyFirst implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 e7c97a5ef56..534cb9541fb 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/SpecialModelName.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * SpecialModelName Class Doc Comment * @@ -232,3 +234,5 @@ class SpecialModelName implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 6a378c7f349..86df6d2e278 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * Tag Class Doc Comment * @@ -258,3 +260,5 @@ class Tag implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($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 e61af43c647..fa439d1bed4 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -43,6 +43,8 @@ namespace Swagger\Client\Model; use \ArrayAccess; + + /** * User Class Doc Comment * @@ -414,3 +416,5 @@ class User implements ArrayAccess return json_encode(\Swagger\Client\ObjectSerializer::sanitizeForSerialization($this)); } } + + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php index ce77aa6c3b3..fe68a3877d6 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ObjectSerializer.php @@ -264,7 +264,7 @@ class ObjectSerializer } else { return null; } - } elseif (in_array($class, array('void', 'bool', 'string', 'double', 'byte', 'mixed', 'integer', 'float', 'int', 'DateTime', 'number', 'boolean', 'object'))) { + } elseif (in_array($class, array('integer', 'int', 'void', 'number', 'object', 'double', 'float', 'byte', 'DateTime', 'string', 'mixed', 'boolean', 'bool'))) { settype($data, $class); return $data; } elseif ($class === '\SplFileObject') { diff --git a/samples/client/petstore/php/SwaggerClient-php/pom.xml b/samples/client/petstore/php/SwaggerClient-php/pom.xml index fa23a1145a8..faaeba82c11 100644 --- a/samples/client/petstore/php/SwaggerClient-php/pom.xml +++ b/samples/client/petstore/php/SwaggerClient-php/pom.xml @@ -48,7 +48,7 @@ vendor/bin/phpunit - tests + test diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Api/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Api/PetApiTest.php index 73a7b06b5eb..ab80903b4bc 100644 --- a/samples/client/petstore/php/SwaggerClient-php/test/Api/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/test/Api/PetApiTest.php @@ -9,20 +9,27 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2 * @link https://github.com/swagger-api/swagger-codegen */ + /** - * Copyright 2016 SmartBear Software + * Swagger Petstore * - * 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 + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + * + * 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. + * 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. */ /** @@ -31,7 +38,7 @@ * Please update the test case below to test the endpoint. */ -namespace Swagger\Client\Api; +namespace Swagger\Client; use \Swagger\Client\Configuration; use \Swagger\Client\ApiClient; @@ -53,17 +60,60 @@ class PetApiTest extends \PHPUnit_Framework_TestCase /** * Setup before running each test case */ - public static function setUpBeforeClass() + public function setUp() { + // add a new pet (id 10005) to ensure the pet object is available for all the tests + // increase memory limit to avoid fatal error due to findPetByStatus + // returning a lot of data + ini_set('memory_limit', '256M'); + + // for error reporting (need to run with php5.3 to get no warning) + //ini_set('display_errors', 1); + //error_reporting(~0); + // when running with php5.5, comment out below to skip the warning about + // using @ to handle file upload + //ini_set('display_startup_errors',1); + //ini_set('display_errors',1); + //error_reporting(-1); + + // enable debugging + //Configuration::$debug = true; + + // skip initializing the API client as it should be automatic + //$api_client = new ApiClient('http://petstore.swagger.io/v2'); + // new pet + $new_pet_id = 10005; + $new_pet = new Model\Pet; + $new_pet->setId($new_pet_id); + $new_pet->setName("PHP Unit Test"); + $new_pet->setPhotoUrls(array("http://test_php_unit_test.com")); + // new tag + $tag= new Model\Tag; + $tag->setId($new_pet_id); // use the same id as pet + $tag->setName("test php tag"); + // new category + $category = new Model\Category; + $category->setId($new_pet_id); // use the same id as pet + $category->setName("test php category"); + + $new_pet->setTags(array($tag)); + $new_pet->setCategory($category); + + $pet_api = new Api\PetApi(); + // add a new pet (model) + $add_response = $pet_api->addPet($new_pet); } /** * Clean up after running each test case */ - public static function tearDownAfterClass() + public function tearDown() { - + $new_pet_id = 10005; + $pet_api = new Api\PetApi(); + // delete the pet (model) + $pet_api->deletePet($new_pet_id); } /** @@ -74,8 +124,24 @@ class PetApiTest extends \PHPUnit_Framework_TestCase */ public function testAddPet() { - + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $new_pet_id = 10005; + $new_pet = new Model\Pet; + $new_pet->setId($new_pet_id); + $new_pet->setName("PHP Unit Test 2"); + $pet_api = new Api\PetApi($api_client); + // add a new pet (model) + $add_response = $pet_api->addPet($new_pet); + // return nothing (void) + $this->assertSame($add_response, null); + // verify added Pet + $response = $pet_api->getPetById($new_pet_id); + $this->assertSame($response->getId(), $new_pet_id); + $this->assertSame($response->getName(), 'PHP Unit Test 2'); } + /** * Test case for deletePet * @@ -86,16 +152,58 @@ class PetApiTest extends \PHPUnit_Framework_TestCase { } + + /** + * Test getPetByStatus and verify by the "id" of the response + */ + public function testFindPetByStatus() + { + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $pet_api = new Api\PetApi($api_client); + // return Pet (model) + $response = $pet_api->findPetsByStatus("available"); + $this->assertGreaterThan(0, count($response)); // at least one object returned + $this->assertSame(get_class($response[0]), "Swagger\\Client\\Model\\Pet"); // verify the object is Pet + // loop through result to ensure status is "available" + foreach ($response as $_pet) { + $this->assertSame($_pet['status'], "available"); + } + // test invalid status + $response = $pet_api->findPetsByStatus("unknown_and_incorrect_status"); + $this->assertSame(count($response), 0); // confirm no object returned + } + /** * Test case for findPetsByStatus * - * Finds Pets by status. + * Finds Pets by status with empty response. + * + * Make sure empty arrays from a producer is actually returned as + * an empty array and not some other value. At some point it was + * returned as null because the code stumbled on PHP loose type + * checking (not on empty array is true, same thing could happen + * with careless use of empty()). * */ - public function testFindPetsByStatus() + public function testFindPetsByStatusWithEmptyResponse() { + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $apiClient = new ApiClient($config); + $storeApi = new Api\PetApi($apiClient); + // this call returns and empty array + $response = $storeApi->findPetsByStatus(array()); + // make sure this is an array as we want it to be + $this->assertInternalType("array", $response); + + // make sure the array is empty just in case the petstore + // server changes its output + $this->assertEmpty($response); } + /** * Test case for findPetsByTags * @@ -104,8 +212,23 @@ class PetApiTest extends \PHPUnit_Framework_TestCase */ public function testFindPetsByTags() { - + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $pet_api = new Api\PetApi($api_client); + // return Pet (model) + $response = $pet_api->findPetsByTags("test php tag"); + $this->assertGreaterThan(0, count($response)); // at least one object returned + $this->assertSame(get_class($response[0]), "Swagger\\Client\\Model\\Pet"); // verify the object is Pet + // loop through result to ensure status is "available" + foreach ($response as $_pet) { + $this->assertSame($_pet['tags'][0]['name'], "test php tag"); + } + // test invalid status + $response = $pet_api->findPetsByTags("unknown_and_incorrect_tag"); + $this->assertSame(count($response), 0); // confirm no object returned } + /** * Test case for getPetById * @@ -114,8 +237,42 @@ class PetApiTest extends \PHPUnit_Framework_TestCase */ public function testGetPetById() { - + // initialize the API client without host + $pet_id = 10005; // ID of pet that needs to be fetched + $pet_api = new Api\PetApi(); + $pet_api->getApiClient()->getConfig()->setApiKey('api_key', '111222333444555'); + // return Pet (model) + $response = $pet_api->getPetById($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'PHP Unit Test'); + $this->assertSame($response->getPhotoUrls()[0], 'http://test_php_unit_test.com'); + $this->assertSame($response->getCategory()->getId(), $pet_id); + $this->assertSame($response->getCategory()->getName(), 'test php category'); + $this->assertSame($response->getTags()[0]->getId(), $pet_id); + $this->assertSame($response->getTags()[0]->getName(), 'test php tag'); } + + /** + * test getPetByIdWithHttpInfo with a Pet object (id 10005) + */ + public function testGetPetByIdWithHttpInfo() + { + // initialize the API client without host + $pet_id = 10005; // ID of pet that needs to be fetched + $pet_api = new Api\PetApi(); + $pet_api->getApiClient()->getConfig()->setApiKey('api_key', '111222333444555'); + // return Pet (model) + list($response, $status_code, $response_headers) = $pet_api->getPetByIdWithHttpInfo($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'PHP Unit Test'); + $this->assertSame($response->getCategory()->getId(), $pet_id); + $this->assertSame($response->getCategory()->getName(), 'test php category'); + $this->assertSame($response->getTags()[0]->getId(), $pet_id); + $this->assertSame($response->getTags()[0]->getName(), 'test php tag'); + $this->assertSame($status_code, 200); + $this->assertSame($response_headers['Content-Type'], 'application/json'); + } + /** * Test case for updatePet * @@ -124,8 +281,51 @@ class PetApiTest extends \PHPUnit_Framework_TestCase */ public function testUpdatePet() { - + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $pet_id = 10001; // ID of pet that needs to be fetched + $pet_api = new Api\PetApi($api_client); + // create updated pet object + $updated_pet = new Model\Pet; + $updated_pet->setId($pet_id); + $updated_pet->setName('updatePet'); // new name + $updated_pet->setStatus('pending'); // new status + // update Pet (model/json) + $update_response = $pet_api->updatePet($updated_pet); + // return nothing (void) + $this->assertSame($update_response, null); + // verify updated Pet + $response = $pet_api->getPetById($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getStatus(), 'pending'); + $this->assertSame($response->getName(), 'updatePet'); } + + /** + * Test updatePetWithFormWithHttpInfo and verify by the "name" of the response + */ + public function testUpdatePetWithFormWithHttpInfo() + { + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $pet_id = 10001; // ID of pet that needs to be fetched + $pet_api = new Api\PetApi($api_client); + // update Pet (form) + list($update_response, $status_code, $http_headers) = $pet_api->updatePetWithFormWithHttpInfo( + $pet_id, + 'update pet with form with http info' + ); + // return nothing (void) + $this->assertNull($update_response); + $this->assertSame($status_code, 200); + $this->assertSame($http_headers['Content-Type'], 'application/json'); + $response = $pet_api->getPetById($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'update pet with form with http info'); + } + /** * Test case for updatePetWithForm * @@ -134,8 +334,21 @@ class PetApiTest extends \PHPUnit_Framework_TestCase */ public function testUpdatePetWithForm() { - + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $pet_id = 10001; // ID of pet that needs to be fetched + $pet_api = new Api\PetApi($api_client); + // update Pet (form) + $update_response = $pet_api->updatePetWithForm($pet_id, 'update pet with form', 'sold'); + // return nothing (void) + $this->assertSame($update_response, null); + $response = $pet_api->getPetById($pet_id); + $this->assertSame($response->getId(), $pet_id); + $this->assertSame($response->getName(), 'update pet with form'); + $this->assertSame($response->getStatus(), 'sold'); } + /** * Test case for uploadFile * @@ -144,6 +357,74 @@ class PetApiTest extends \PHPUnit_Framework_TestCase */ public function testUploadFile() { - + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $pet_api = new Api\PetApi($api_client); + // upload file + $pet_id = 10001; + $response = $pet_api->uploadFile($pet_id, "test meta", "./composer.json"); + // return ApiResponse + $this->assertInstanceOf('Swagger\Client\Model\ApiResponse', $response); } + + /* + * test static functions defined in ApiClient + */ + public function testApiClient() + { + // test selectHeaderAccept + $api_client = new ApiClient(); + $this->assertSame('application/json', $api_client->selectHeaderAccept(array( + 'application/xml', + 'application/json' + ))); + $this->assertSame(null, $api_client->selectHeaderAccept(array())); + $this->assertSame('application/yaml,application/xml', $api_client->selectHeaderAccept(array( + 'application/yaml', + 'application/xml' + ))); + + // test selectHeaderContentType + $this->assertSame('application/json', $api_client->selectHeaderContentType(array( + 'application/xml', + 'application/json' + ))); + $this->assertSame('application/json', $api_client->selectHeaderContentType(array())); + $this->assertSame('application/yaml,application/xml', $api_client->selectHeaderContentType(array( + 'application/yaml', + 'application/xml' + ))); + + // test addDefaultHeader and getDefaultHeader + $api_client->getConfig()->addDefaultHeader('test1', 'value1'); + $api_client->getConfig()->addDefaultHeader('test2', 200); + $defaultHeader = $api_client->getConfig()->getDefaultHeaders(); + $this->assertSame('value1', $defaultHeader['test1']); + $this->assertSame(200, $defaultHeader['test2']); + + // test deleteDefaultHeader + $api_client->getConfig()->deleteDefaultHeader('test2'); + $defaultHeader = $api_client->getConfig()->getDefaultHeaders(); + $this->assertFalse(isset($defaultHeader['test2'])); + + $pet_api2 = new Api\PetApi(); + $config3 = new Configuration(); + $apiClient3 = new ApiClient($config3); + $apiClient3->getConfig()->setUserAgent('api client 3'); + $config4 = new Configuration(); + $apiClient4 = new ApiClient($config4); + $apiClient4->getConfig()->setUserAgent('api client 4'); + $pet_api3 = new Api\PetApi($apiClient3); + + // 2 different api clients are not the same + $this->assertNotEquals($apiClient3, $apiClient4); + // customied pet api not using the old pet api's api client + $this->assertNotEquals($pet_api2->getApiClient(), $pet_api3->getApiClient()); + + // test access token + $api_client->getConfig()->setAccessToken("testing_only"); + $this->assertSame('testing_only', $api_client->getConfig()->getAccessToken()); + } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Api/StoreApiTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Api/StoreApiTest.php index aaa2df27fd7..18146bf0591 100644 --- a/samples/client/petstore/php/SwaggerClient-php/test/Api/StoreApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/test/Api/StoreApiTest.php @@ -9,20 +9,27 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2 * @link https://github.com/swagger-api/swagger-codegen */ + /** - * Copyright 2016 SmartBear Software + * Swagger Petstore * - * 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 + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + * + * 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. + * 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. */ /** @@ -55,7 +62,33 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase */ public static function setUpBeforeClass() { + // add a new pet (id 10005) to ensure the pet object is available for all the tests + // for error reporting (need to run with php5.3 to get no warning) + //ini_set('display_errors', 1); + //error_reporting(~0); + + // new pet + $new_pet_id = 10005; + $new_pet = new \Swagger\Client\Model\Pet; + $new_pet->setId($new_pet_id); + $new_pet->setName("PHP Unit Test"); + $new_pet->setStatus("available"); + // new tag + $tag= new \Swagger\Client\Model\Tag; + $tag->setId($new_pet_id); // use the same id as pet + $tag->setName("test php tag"); + // new category + $category = new \Swagger\Client\Model\Category; + $category->setId($new_pet_id); // use the same id as pet + $category->setName("test php category"); + + $new_pet->setTags(array($tag)); + $new_pet->setCategory($category); + + $pet_api = new PetAPI(); + // add a new pet (model) + $add_response = $pet_api->addPet($new_pet); } /** @@ -76,6 +109,7 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase { } + /** * Test case for getInventory * @@ -84,8 +118,17 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase */ public function testGetInventory() { + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $store_api = new StoreApi($api_client); + // get inventory + $get_response = $store_api->getInventory(); + $this->assertInternalType("array", $get_response); + $this->assertInternalType("int", $get_response['available']); } + /** * Test case for getOrderById * @@ -96,6 +139,7 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase { } + /** * Test case for placeOrder * @@ -106,4 +150,5 @@ class StoreApiTest extends \PHPUnit_Framework_TestCase { } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Api/UserApiTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Api/UserApiTest.php index c866015cf7a..def54fa6580 100644 --- a/samples/client/petstore/php/SwaggerClient-php/test/Api/UserApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/test/Api/UserApiTest.php @@ -9,20 +9,27 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2 * @link https://github.com/swagger-api/swagger-codegen */ + /** - * Copyright 2016 SmartBear Software + * Swagger Petstore * - * 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 + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + * + * 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. + * 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. */ /** @@ -76,6 +83,7 @@ class UserApiTest extends \PHPUnit_Framework_TestCase { } + /** * Test case for createUsersWithArrayInput * @@ -86,6 +94,7 @@ class UserApiTest extends \PHPUnit_Framework_TestCase { } + /** * Test case for createUsersWithListInput * @@ -96,6 +105,7 @@ class UserApiTest extends \PHPUnit_Framework_TestCase { } + /** * Test case for deleteUser * @@ -106,6 +116,7 @@ class UserApiTest extends \PHPUnit_Framework_TestCase { } + /** * Test case for getUserByName * @@ -116,6 +127,7 @@ class UserApiTest extends \PHPUnit_Framework_TestCase { } + /** * Test case for loginUser * @@ -124,8 +136,21 @@ class UserApiTest extends \PHPUnit_Framework_TestCase */ public function testLoginUser() { - + // initialize the API client + $config = (new Configuration())->setHost('http://petstore.swagger.io/v2'); + $api_client = new ApiClient($config); + $user_api = new UserApi($api_client); + // login + $response = $user_api->loginUser("xxxxx", "yyyyyyyy"); + + $this->assertInternalType("string", $response); + $this->assertRegExp( + "/^logged in user session/", + $response, + "response string starts with 'logged in user session'" + ); } + /** * Test case for logoutUser * @@ -136,6 +161,7 @@ class UserApiTest extends \PHPUnit_Framework_TestCase { } + /** * Test case for updateUser * @@ -146,4 +172,5 @@ class UserApiTest extends \PHPUnit_Framework_TestCase { } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Client/ApiClientTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Client/ApiClientTest.php new file mode 100644 index 00000000000..5d4028ecf92 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/test/Client/ApiClientTest.php @@ -0,0 +1,126 @@ +assertSame('application/json', $api_client->selectHeaderAccept(array( + 'application/xml', + 'application/json' + ))); + $this->assertSame(null, $api_client->selectHeaderAccept(array())); + $this->assertSame('application/yaml,application/xml', $api_client->selectHeaderAccept(array( + 'application/yaml', + 'application/xml' + ))); + + // test selectHeaderContentType + $this->assertSame('application/json', $api_client->selectHeaderContentType(array( + 'application/xml', + 'application/json' + ))); + $this->assertSame('application/json', $api_client->selectHeaderContentType(array())); + $this->assertSame('application/yaml,application/xml', $api_client->selectHeaderContentType(array( + 'application/yaml', + 'application/xml' + ))); + + // test addDefaultHeader and getDefaultHeader + $api_client->getConfig()->addDefaultHeader('test1', 'value1'); + $api_client->getConfig()->addDefaultHeader('test2', 200); + $defaultHeader = $api_client->getConfig()->getDefaultHeaders(); + $this->assertSame('value1', $defaultHeader['test1']); + $this->assertSame(200, $defaultHeader['test2']); + + // test deleteDefaultHeader + $api_client->getConfig()->deleteDefaultHeader('test2'); + $defaultHeader = $api_client->getConfig()->getDefaultHeaders(); + $this->assertFalse(isset($defaultHeader['test2'])); + + $pet_api2 = new Api\PetApi(); + $config3 = new Configuration(); + $apiClient3 = new ApiClient($config3); + $apiClient3->getConfig()->setUserAgent('api client 3'); + $config4 = new Configuration(); + $apiClient4 = new ApiClient($config4); + $apiClient4->getConfig()->setUserAgent('api client 4'); + $pet_api3 = new Api\PetApi($apiClient3); + + // 2 different api clients are not the same + $this->assertNotEquals($apiClient3, $apiClient4); + // customied pet api not using the old pet api's api client + $this->assertNotEquals($pet_api2->getApiClient(), $pet_api3->getApiClient()); + + // test access token + $api_client->getConfig()->setAccessToken("testing_only"); + $this->assertSame('testing_only', $api_client->getConfig()->getAccessToken()); + } + +} diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Client/ObjectSerializerTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Client/ObjectSerializerTest.php new file mode 100644 index 00000000000..00e17895164 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/test/Client/ObjectSerializerTest.php @@ -0,0 +1,87 @@ +assertSame("sun.gif", $s->sanitizeFilename("sun.gif")); + $this->assertSame("sun.gif", $s->sanitizeFilename("../sun.gif")); + $this->assertSame("sun.gif", $s->sanitizeFilename("/var/tmp/sun.gif")); + $this->assertSame("sun.gif", $s->sanitizeFilename("./sun.gif")); + + $this->assertSame("sun", $s->sanitizeFilename("sun")); + $this->assertSame("sun.gif", $s->sanitizeFilename("..\sun.gif")); + $this->assertSame("sun.gif", $s->sanitizeFilename("\var\tmp\sun.gif")); + $this->assertSame("sun.gif", $s->sanitizeFilename("c:\var\tmp\sun.gif")); + $this->assertSame("sun.gif", $s->sanitizeFilename(".\sun.gif")); + } + +} diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Model/AnimalFarmTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Model/AnimalFarmTest.php index 0471346bf24..683e9e5d220 100644 --- a/samples/client/petstore/php/SwaggerClient-php/test/Model/AnimalFarmTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/test/Model/AnimalFarmTest.php @@ -10,28 +10,36 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2 * @link https://github.com/swagger-api/swagger-codegen */ + /** - * Copyright 2016 SmartBear Software + * Swagger Petstore * - * 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 + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + * + * 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. + * 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; +namespace Swagger\Client; /** * AnimalFarmTest Class Doc Comment @@ -47,16 +55,32 @@ class AnimalFarmTest extends \PHPUnit_Framework_TestCase { /** - * Setup before running each test case + * Setup before running any test case */ public static function setUpBeforeClass() { } + /** + * Setup before running each test case + */ + public function setUp() + { + + } + /** * Clean up after running each test case */ + public function tearDown() + { + + } + + /** + * Clean up after running all test cases + */ public static function tearDownAfterClass() { @@ -69,4 +93,79 @@ class AnimalFarmTest 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 Model\Dog(); + $animal = new 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()); + } + + // test inheritance in the model + public function testInheritance() + { + $new_dog = new Model\Dog; + // the object should be an instance of the derived class + $this->assertInstanceOf('Swagger\Client\Model\Dog', $new_dog); + // the object should also be an instance of the parent class + $this->assertInstanceOf('Swagger\Client\Model\Animal', $new_dog); + } + + // test inheritance constructor is working with data + // initialization + public function testInheritanceConstructorDataInitialization() + { + // initialize the object with data in the constructor + $data = array( + 'class_name' => 'Dog', + 'breed' => 'Great Dane' + ); + $new_dog = new Model\Dog($data); + + // the property on the derived class should be set + $this->assertSame('Great Dane', $new_dog->getBreed()); + // the property on the parent class should be set + $this->assertSame('Dog', $new_dog->getClassName()); + } + + // test if discriminator is initialized automatically + public function testDiscriminatorInitialization() + { + $new_dog = new Model\Dog(); + $this->assertSame('Dog', $new_dog->getClassName()); + } + + // test if ArrayAccess interface works + public function testArrayStuff() + { + // create an AnimalFarm which is an object implementing the + // ArrayAccess interface + $farm = new Model\AnimalFarm(); + + // add some animals to the farm to make sure the ArrayAccess + // interface works + $farm[] = new Model\Dog(); + $farm[] = new Model\Cat(); + $farm[] = new Model\Animal(); + + // assert we can look up the animals in the farm by array + // indices (let's try a random order) + $this->assertInstanceOf('Swagger\Client\Model\Cat', $farm[1]); + $this->assertInstanceOf('Swagger\Client\Model\Dog', $farm[0]); + $this->assertInstanceOf('Swagger\Client\Model\Animal', $farm[2]); + + // let's try to `foreach` the animals in the farm and let's + // try to use the objects we loop through + foreach ($farm as $animal) { + $this->assertContains($animal->getClassName(), array('Dog', 'Cat', 'Animal')); + $this->assertInstanceOf('Swagger\Client\Model\Animal', $animal); + } + } } diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Model/ArrayOfArrayOfNumberOnlyTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Model/ArrayOfArrayOfNumberOnlyTest.php new file mode 100644 index 00000000000..d7c1ddb9cfd --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/test/Model/ArrayOfArrayOfNumberOnlyTest.php @@ -0,0 +1,80 @@ +assertSame(Swagger\Client\Model\EnumClass::ABC, "_abc"); - $this->assertSame(Swagger\Client\Model\EnumClass::EFG, "-efg"); - $this->assertSame(Swagger\Client\Model\EnumClass::XYZ, "(xyz)"); + $this->assertSame(EnumClass::ABC, "_abc"); + $this->assertSame(EnumClass::EFG, "-efg"); + $this->assertSame(EnumClass::XYZ, "(xyz)"); } } diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Model/EnumTestTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Model/EnumTestTest.php index 2cf9956b8b4..2f6b656ba06 100644 --- a/samples/client/petstore/php/SwaggerClient-php/test/Model/EnumTestTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/test/Model/EnumTestTest.php @@ -67,11 +67,11 @@ class EnumTestTest extends \PHPUnit_Framework_TestCase */ public function testEnumTest() { - $this->assertSame(Swagger\Client\Model\EnumTest::ENUM_STRING_UPPER, "UPPER"); - $this->assertSame(Swagger\Client\Model\EnumTest::ENUM_STRING_LOWER, "lower"); - $this->assertSame(Swagger\Client\Model\EnumTest::ENUM_INTEGER_1, 1); - $this->assertSame(Swagger\Client\Model\EnumTest::ENUM_INTEGER_MINUS_1, -1); - $this->assertSame(Swagger\Client\Model\EnumTest::ENUM_NUMBER_1_DOT_1, 1.1); - $this->assertSame(Swagger\Client\Model\EnumTest::ENUM_NUMBER_MINUS_1_DOT_2, -1.2); + $this->assertSame(EnumTest::ENUM_STRING_UPPER, "UPPER"); + $this->assertSame(EnumTest::ENUM_STRING_LOWER, "lower"); + $this->assertSame(EnumTest::ENUM_INTEGER_1, 1); + $this->assertSame(EnumTest::ENUM_INTEGER_MINUS_1, -1); + $this->assertSame(EnumTest::ENUM_NUMBER_1_DOT_1, 1.1); + $this->assertSame(EnumTest::ENUM_NUMBER_MINUS_1_DOT_2, -1.2); } } diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Model/HasOnlyReadOnlyTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Model/HasOnlyReadOnlyTest.php new file mode 100644 index 00000000000..63d58ddb48e --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/test/Model/HasOnlyReadOnlyTest.php @@ -0,0 +1,80 @@ +setStatus("placed"); + $this->assertSame("placed", $order->getStatus()); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testOrderException() + { + // initialize the API client + $order = new Order(); + $order->setStatus("invalid_value"); + } + + /** + * Test attribute "id" + */ + public function testPropertyId() { } + + /** + * Test attribute "pet_id" + */ + public function testPropertyPetId() + { + + } + + /** + * Test attribute "quantity" + */ + public function testPropertyQuantity() + { + + } + + /** + * Test attribute "ship_date" + */ + public function testPropertyShipDate() + { + + } + + /** + * Test attribute "status" + */ + public function testPropertyStatus() + { + $this->assertSame(Order::STATUS_PLACED, "placed"); + $this->assertSame(Order::STATUS_APPROVED, "approved"); + } + + /** + * Test attribute "complete" + */ + public function testPropertyComplete() + { + + } + + // test deseralization of order + public function testDeserializationOfOrder() + { + $order_json = <<assertInstanceOf('Swagger\Client\Model\Order', $order); + $this->assertSame(10, $order->getId()); + $this->assertSame(20, $order->getPetId()); + $this->assertSame(30, $order->getQuantity()); + $this->assertTrue(new \DateTime("2015-08-22T07:13:36.613Z") == $order->getShipDate()); + $this->assertSame("placed", $order->getStatus()); + $this->assertSame(false, $order->getComplete()); + } + + // test deseralization of array of array of order + public function testDeserializationOfArrayOfArrayOfOrder() + { + $order_json = <<assertArrayHasKey(0, $order); + $this->assertArrayHasKey(0, $order[0]); + $_order = $order[0][0]; + $this->assertInstanceOf('Swagger\Client\Model\Order', $_order); + $this->assertSame(10, $_order->getId()); + $this->assertSame(20, $_order->getPetId()); + $this->assertSame(30, $_order->getQuantity()); + $this->assertTrue(new \DateTime("2015-08-22T07:13:36.613Z") == $_order->getShipDate()); + $this->assertSame("placed", $_order->getStatus()); + $this->assertSame(false, $_order->getComplete()); + } + + // test deseralization of map of map of order + public function testDeserializationOfMapOfMapOfOrder() + { + $order_json = <<assertArrayHasKey('test', $order); + $this->assertArrayHasKey('test2', $order['test']); + $_order = $order['test']['test2']; + $this->assertInstanceOf('Swagger\Client\Model\Order', $_order); + $this->assertSame(10, $_order->getId()); + $this->assertSame(20, $_order->getPetId()); + $this->assertSame(30, $_order->getQuantity()); + $this->assertTrue(new \DateTime("2015-08-22T07:13:36.613Z") == $_order->getShipDate()); + $this->assertSame("placed", $_order->getStatus()); + $this->assertSame(false, $_order->getComplete()); + } + } diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Model/PetTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Model/PetTest.php index 2f2ac140ca1..7c079f09a11 100644 --- a/samples/client/petstore/php/SwaggerClient-php/test/Model/PetTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/test/Model/PetTest.php @@ -10,28 +10,36 @@ * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Licene v2 * @link https://github.com/swagger-api/swagger-codegen */ + /** - * Copyright 2016 SmartBear Software + * Swagger Petstore * - * 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 + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * Generated by: https://github.com/swagger-api/swagger-codegen.git + * + * 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. + * 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; +namespace Swagger\Client; /** * PetTest Class Doc Comment @@ -69,4 +77,63 @@ class PetTest extends \PHPUnit_Framework_TestCase { } + + /** + * test empty object serialization + */ + public function testEmptyPetSerialization() + { + $new_pet = new Model\Pet; + // the empty object should be serialised to {} + $this->assertSame("{}", "$new_pet"); + } + + /** + * Test attribute "id" + */ + public function testPropertyId() + { + + } + + /** + * Test attribute "category" + */ + public function testPropertyCategory() + { + + } + + /** + * Test attribute "name" + */ + public function testPropertyName() + { + + } + + /** + * Test attribute "photo_urls" + */ + public function testPropertyPhotoUrls() + { + + } + + /** + * Test attribute "tags" + */ + public function testPropertyTags() + { + + } + + /** + * Test attribute "status" + */ + public function testPropertyStatus() + { + + } + }