From 4e8c71f7548ee85f3ba291249151badc454618a5 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 10 Jun 2014 16:54:48 -0700 Subject: [PATCH] regenerated client --- .../petstore/php/PHPPetstoreCodegen.scala | 2 +- samples/client/petstore/php/PetApi.php | 32 +++ samples/client/petstore/php/StoreApi.php | 10 + samples/client/petstore/php/Swagger.php | 131 ++++++------- samples/client/petstore/php/UserApi.php | 182 ++++++++++-------- .../client/petstore/php/models/Category.php | 6 - samples/client/petstore/php/models/Order.php | 14 +- samples/client/petstore/php/models/Pet.php | 14 +- samples/client/petstore/php/models/Tag.php | 6 - samples/client/petstore/php/models/User.php | 25 +-- 10 files changed, 208 insertions(+), 214 deletions(-) diff --git a/samples/client/petstore/php/PHPPetstoreCodegen.scala b/samples/client/petstore/php/PHPPetstoreCodegen.scala index 78a8b96cd6b..c438fff84bb 100644 --- a/samples/client/petstore/php/PHPPetstoreCodegen.scala +++ b/samples/client/petstore/php/PHPPetstoreCodegen.scala @@ -1,5 +1,5 @@ /** - * Copyright 2012 Wordnik, Inc. + * Copyright 2014 Wordnik, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/samples/client/petstore/php/PetApi.php b/samples/client/petstore/php/PetApi.php index 94400f032b6..f6dbc352395 100644 --- a/samples/client/petstore/php/PetApi.php +++ b/samples/client/petstore/php/PetApi.php @@ -29,6 +29,7 @@ class PetApi { * getPetById * Find pet by ID * petId, int: ID of pet that needs to be fetched (required) + * @return Pet */ @@ -40,6 +41,8 @@ class PetApi { $method = "GET"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($petId != null) { $resourcePath = str_replace("{" . "petId" . "}", @@ -67,6 +70,7 @@ class PetApi { * deletePet * Deletes a pet * petId, string: Pet id to delete (required) + * @return */ @@ -78,6 +82,8 @@ class PetApi { $method = "DELETE"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($petId != null) { $resourcePath = str_replace("{" . "petId" . "}", @@ -97,7 +103,9 @@ class PetApi { * partialUpdate * partial updates to a pet * petId, string: ID of pet that needs to be fetched (required) + * body, Pet: Pet object that needs to be added to the store (required) + * @return Array[Pet] */ @@ -109,6 +117,8 @@ class PetApi { $method = "PATCH"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json,application/xml'; + $headerParams['Content-Type'] = 'application/json,application/xml'; if($petId != null) { $resourcePath = str_replace("{" . "petId" . "}", @@ -136,8 +146,11 @@ class PetApi { * updatePetWithForm * Updates a pet in the store with form data * petId, string: ID of pet that needs to be updated (required) + * name, string: Updated name of the pet (optional) + * status, string: Updated status of the pet (optional) + * @return */ @@ -149,6 +162,8 @@ class PetApi { $method = "POST"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; if($petId != null) { $resourcePath = str_replace("{" . "petId" . "}", @@ -168,7 +183,9 @@ class PetApi { * uploadFile * uploads an image * additionalMetadata, string: Additional data to pass to server (optional) + * body, File: file to upload (optional) + * @return */ @@ -180,6 +197,8 @@ class PetApi { $method = "POST"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'multipart/form-data'; //make the API Call if (! isset($body)) { @@ -195,6 +214,7 @@ class PetApi { * addPet * Add a new pet to the store * body, Pet: Pet object that needs to be added to the store (required) + * @return */ @@ -206,6 +226,8 @@ class PetApi { $method = "POST"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json,application/xml'; //make the API Call if (! isset($body)) { @@ -221,6 +243,7 @@ class PetApi { * updatePet * Update an existing pet * body, Pet: Pet object that needs to be updated in the store (required) + * @return */ @@ -232,6 +255,8 @@ class PetApi { $method = "PUT"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; //make the API Call if (! isset($body)) { @@ -247,6 +272,7 @@ class PetApi { * findPetsByStatus * Finds Pets by status * status, string: Status values that need to be considered for filter (required) + * @return Array[Pet] */ @@ -258,6 +284,8 @@ class PetApi { $method = "GET"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($status != null) { $queryParams['status'] = $this->apiClient->toQueryValue($status); @@ -284,6 +312,7 @@ class PetApi { * findPetsByTags * Finds Pets by tags * tags, string: Tags to filter by (required) + * @return Array[Pet] */ @@ -295,6 +324,8 @@ class PetApi { $method = "GET"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($tags != null) { $queryParams['tags'] = $this->apiClient->toQueryValue($tags); @@ -318,5 +349,6 @@ class PetApi { } + } diff --git a/samples/client/petstore/php/StoreApi.php b/samples/client/petstore/php/StoreApi.php index 3ccabb3590c..89e5812c2a0 100644 --- a/samples/client/petstore/php/StoreApi.php +++ b/samples/client/petstore/php/StoreApi.php @@ -29,6 +29,7 @@ class StoreApi { * getOrderById * Find purchase order by ID * orderId, string: ID of pet that needs to be fetched (required) + * @return Order */ @@ -40,6 +41,8 @@ class StoreApi { $method = "GET"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($orderId != null) { $resourcePath = str_replace("{" . "orderId" . "}", @@ -67,6 +70,7 @@ class StoreApi { * deleteOrder * Delete purchase order by ID * orderId, string: ID of the order that needs to be deleted (required) + * @return */ @@ -78,6 +82,8 @@ class StoreApi { $method = "DELETE"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($orderId != null) { $resourcePath = str_replace("{" . "orderId" . "}", @@ -97,6 +103,7 @@ class StoreApi { * placeOrder * Place an order for a pet * body, Order: order placed for purchasing the pet (required) + * @return */ @@ -108,6 +115,8 @@ class StoreApi { $method = "POST"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; //make the API Call if (! isset($body)) { @@ -120,5 +129,6 @@ class StoreApi { } + } diff --git a/samples/client/petstore/php/Swagger.php b/samples/client/petstore/php/Swagger.php index ddf7d79de63..088f601489c 100644 --- a/samples/client/petstore/php/Swagger.php +++ b/samples/client/petstore/php/Swagger.php @@ -44,13 +44,12 @@ class APIClient { * @param array $queryParams parameters to be place in query URL * @param array $postData parameters to be placed in POST body * @param array $headerParams parameters to be place in request header - * @return unknown + * @return mixed */ public function callAPI($resourcePath, $method, $queryParams, $postData, $headerParams) { $headers = array(); - $headers[] = "Content-type: application/json"; # Allow API key from $headerParams to override default $added_api_key = False; @@ -67,7 +66,7 @@ class APIClient { } if (is_object($postData) or is_array($postData)) { - $postData = json_encode(self::sanitizeForSerialization($postData)); + $postData = json_encode($this->sanitizeForSerialization($postData)); } $url = $this->apiServer . $resourcePath; @@ -118,21 +117,35 @@ class APIClient { $response_info['http_code']); } - return $data; } /** * Build a JSON POST object */ - public static function sanitizeForSerialization($postData) { - foreach ($postData as $key => $value) { - if (is_a($value, "DateTime")) { - $postData->{$key} = $value->format(DateTime::ISO8601); - } - } - return $postData; - } + protected function sanitizeForSerialization($data) + { + if (is_scalar($data) || null === $data) { + $sanitized = $data; + } else if ($data instanceof \DateTime) { + $sanitized = $data->format(\DateTime::ISO8601); + } else if (is_array($data)) { + foreach ($data as $property => $value) { + $data[$property] = $this->sanitizeForSerialization($value); + } + $sanitized = $data; + } else if (is_object($data)) { + $values = array(); + foreach (array_keys($data::$swaggerTypes) as $property) { + $values[$property] = $this->sanitizeForSerialization($data->$property); + } + $sanitized = $values; + } else { + $sanitized = (string)$data; + } + + return $sanitized; + } /** * Take value and turn it into a string suitable for inclusion in @@ -170,73 +183,43 @@ class APIClient { return $value; } - /** - * Deserialize a JSON string into an object - * - * @param object $object object or primitive to be deserialized - * @param string $class class name is passed as a string - * @return object an instance of $class - */ - public static function deserialize($object, $class) { + /** + * Deserialize a JSON string into an object + * + * @param object $object object or primitive to be deserialized + * @param string $class class name is passed as a string + * @return object an instance of $class + */ - if (gettype($object) == "NULL") { - return $object; - } - - if (substr($class, 0, 6) == 'array[') { - $sub_class = substr($class, 6, -1); - $sub_objects = array(); - foreach ($object as $sub_object) { - $sub_objects[] = self::deserialize($sub_object, - $sub_class); + public static function deserialize($data, $class) + { + if (null === $data) { + $deserialized = null; + } else if (substr($class, 0, 6) == 'array[') { + $subClass = substr($class, 6, -1); + $values = array(); + foreach ($data as $value) { + $values[] = self::deserialize($value, $subClass); } - return $sub_objects; + $deserialized = $values; } elseif ($class == 'DateTime') { - return new DateTime($object); - } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { - settype($object, $class); - return $object; - } else { - $instance = new $class(); // this instantiates class named $class - $classVars = get_class_vars($class); - } + $deserialized = new \DateTime($data); + } elseif (in_array($class, array('string', 'int', 'float', 'bool'))) { + settype($data, $class); + $deserialized = $data; + } else { + $instance = new $class(); + foreach ($instance::$swaggerTypes as $property => $type) { + if (isset($data->$property)) { + $instance->$property = self::deserialize($data->$property, $type); + } + } + $deserialized = $instance; + } - foreach ($object as $property => $value) { + return $deserialized; + } - // Need to handle possible pluralization differences - $true_property = $property; - - if (! property_exists($class, $true_property)) { - if (substr($property, -1) == 's') { - $true_property = substr($property, 0, -1); - } - } - - if (array_key_exists($true_property, $classVars['swaggerTypes'])) { - $type = $classVars['swaggerTypes'][$true_property]; - } else { - $type = 'string'; - } - if (in_array($type, array('string', 'int', 'float', 'bool'))) { - settype($value, $type); - $instance->{$true_property} = $value; - } elseif (preg_match("/array<(.*)>/", $type, $matches)) { - $sub_class = $matches[1]; - $instance->{$true_property} = array(); - foreach ($value as $sub_property => $sub_value) { - $instance->{$true_property}[] = self::deserialize($sub_value, - $sub_class); - } - } else { - $instance->{$true_property} = self::deserialize($value, $type); - } - } - return $instance; - } } -?> - - - diff --git a/samples/client/petstore/php/UserApi.php b/samples/client/petstore/php/UserApi.php index 49a4b55fd46..87626f09e0f 100644 --- a/samples/client/petstore/php/UserApi.php +++ b/samples/client/petstore/php/UserApi.php @@ -25,89 +25,13 @@ class UserApi { $this->apiClient = $apiClient; } - /** - * createUser - * Create user - * body, User: Created user object (required) - * @return - */ - - public function createUser($body) { - - //parse inputs - $resourcePath = "/user"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $queryParams = array(); - $headerParams = array(); - - //make the API Call - if (! isset($body)) { - $body = null; - } - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); - - - } - /** - * createUsersWithArrayInput - * Creates list of users with given input array - * body, array[User]: List of user object (required) - * @return - */ - - public function createUsersWithArrayInput($body) { - - //parse inputs - $resourcePath = "/user/createWithArray"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $queryParams = array(); - $headerParams = array(); - - //make the API Call - if (! isset($body)) { - $body = null; - } - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); - - - } - /** - * createUsersWithListInput - * Creates list of users with given list input - * body, array[User]: List of user object (required) - * @return - */ - - public function createUsersWithListInput($body) { - - //parse inputs - $resourcePath = "/user/createWithList"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $queryParams = array(); - $headerParams = array(); - - //make the API Call - if (! isset($body)) { - $body = null; - } - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); - - - } /** * updateUser * Updated user * username, string: name that need to be deleted (required) + * body, User: Updated user object (required) + * @return */ @@ -119,6 +43,8 @@ class UserApi { $method = "PUT"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($username != null) { $resourcePath = str_replace("{" . "username" . "}", @@ -138,6 +64,7 @@ class UserApi { * deleteUser * Delete user * username, string: The name that needs to be deleted (required) + * @return */ @@ -149,6 +76,8 @@ class UserApi { $method = "DELETE"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($username != null) { $resourcePath = str_replace("{" . "username" . "}", @@ -168,6 +97,7 @@ class UserApi { * getUserByName * Get user by user name * username, string: The name that needs to be fetched. Use user1 for testing. (required) + * @return User */ @@ -179,6 +109,8 @@ class UserApi { $method = "GET"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($username != null) { $resourcePath = str_replace("{" . "username" . "}", @@ -206,7 +138,9 @@ class UserApi { * loginUser * Logs user into the system * username, string: The user name for login (required) + * password, string: The password for login in clear text (required) + * @return string */ @@ -218,6 +152,8 @@ class UserApi { $method = "GET"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; if($username != null) { $queryParams['username'] = $this->apiClient->toQueryValue($username); @@ -257,6 +193,95 @@ class UserApi { $method = "GET"; $queryParams = array(); $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; + + //make the API Call + if (! isset($body)) { + $body = null; + } + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); + + + } + /** + * createUser + * Create user + * body, User: Created user object (required) + + * @return + */ + + public function createUser($body) { + + //parse inputs + $resourcePath = "/user"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $queryParams = array(); + $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; + + //make the API Call + if (! isset($body)) { + $body = null; + } + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); + + + } + /** + * createUsersWithArrayInput + * Creates list of users with given input array + * body, array[User]: List of user object (required) + + * @return + */ + + public function createUsersWithArrayInput($body) { + + //parse inputs + $resourcePath = "/user/createWithArray"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $queryParams = array(); + $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; + + //make the API Call + if (! isset($body)) { + $body = null; + } + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); + + + } + /** + * createUsersWithListInput + * Creates list of users with given list input + * body, array[User]: List of user object (required) + + * @return + */ + + public function createUsersWithListInput($body) { + + //parse inputs + $resourcePath = "/user/createWithList"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $queryParams = array(); + $headerParams = array(); + $headerParams['Accept'] = 'application/json'; + $headerParams['Content-Type'] = 'application/json'; //make the API Call if (! isset($body)) { @@ -269,5 +294,6 @@ class UserApi { } + } diff --git a/samples/client/petstore/php/models/Category.php b/samples/client/petstore/php/models/Category.php index ca8e3b0a7a4..adb99943fa3 100644 --- a/samples/client/petstore/php/models/Category.php +++ b/samples/client/petstore/php/models/Category.php @@ -29,13 +29,7 @@ class Category { ); - /** - * Category unique identifier - */ public $id; // int - /** - * Name of the category - */ public $name; // string } diff --git a/samples/client/petstore/php/models/Order.php b/samples/client/petstore/php/models/Order.php index 645ce10e411..e0846bd1f73 100644 --- a/samples/client/petstore/php/models/Order.php +++ b/samples/client/petstore/php/models/Order.php @@ -32,25 +32,13 @@ class Order { ); - /** - * Unique identifier for the order - */ public $id; // int - /** - * ID of pet being ordered - */ public $petId; // int - /** - * Number of pets ordered - */ public $quantity; // int /** - * Status of the order + * Order Status */ public $status; // string - /** - * Date shipped, only if it has been - */ public $shipDate; // DateTime } diff --git a/samples/client/petstore/php/models/Pet.php b/samples/client/petstore/php/models/Pet.php index aa711a7edf6..ccdc86e0ee0 100644 --- a/samples/client/petstore/php/models/Pet.php +++ b/samples/client/petstore/php/models/Pet.php @@ -34,24 +34,12 @@ class Pet { ); /** - * Unique identifier for the Pet + * unique identifier for the pet */ public $id; // int - /** - * Category the pet is in - */ public $category; // Category - /** - * Friendly name of the pet - */ public $name; // string - /** - * Image URLs - */ public $photoUrls; // array[string] - /** - * Tags assigned to this pet - */ public $tags; // array[Tag] /** * pet status in the store diff --git a/samples/client/petstore/php/models/Tag.php b/samples/client/petstore/php/models/Tag.php index 2d85e97b50b..8550685e45e 100644 --- a/samples/client/petstore/php/models/Tag.php +++ b/samples/client/petstore/php/models/Tag.php @@ -29,13 +29,7 @@ class Tag { ); - /** - * Unique identifier for the tag - */ public $id; // int - /** - * Friendly name for the tag - */ public $name; // string } diff --git a/samples/client/petstore/php/models/User.php b/samples/client/petstore/php/models/User.php index 69c239082ee..85804deb74b 100644 --- a/samples/client/petstore/php/models/User.php +++ b/samples/client/petstore/php/models/User.php @@ -25,8 +25,8 @@ class User { static $swaggerTypes = array( 'id' => 'int', - 'username' => 'string', 'firstName' => 'string', + 'username' => 'string', 'lastName' => 'string', 'email' => 'string', 'password' => 'string', @@ -35,33 +35,12 @@ class User { ); - /** - * Unique identifier for the user - */ public $id; // int - /** - * Unique username - */ - public $username; // string - /** - * First name of the user - */ public $firstName; // string - /** - * Last name of the user - */ + public $username; // string public $lastName; // string - /** - * Email address of the user - */ public $email; // string - /** - * Password name of the user - */ public $password; // string - /** - * Phone number of the user - */ public $phone; // string /** * User Status