From 8512259d02996750e4b8f2770c0e406175e6aebe Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 16 Apr 2015 23:45:31 +0800 Subject: [PATCH 1/5] update method name based on style guide, update petstore sample --- .../swagger/codegen/DefaultCodegen.java | 3 +- .../languages/AndroidClientCodegen.java | 9 + .../languages/CSharpClientCodegen.java | 10 + .../codegen/languages/JavaClientCodegen.java | 11 + .../codegen/languages/ObjcClientCodegen.java | 10 + .../languages/Python3ClientCodegen.java | 9 + .../languages/PythonClientCodegen.java | 9 + .../codegen/languages/RubyClientCodegen.java | 10 + .../codegen/languages/ScalaClientCodegen.java | 13 +- .../codegen/languages/TizenClientCodegen.java | 11 + .../java/io/swagger/client/ApiInvoker.java | 3 +- .../src/main/csharp/io/swagger/Api/PetApi.cs | 16 +- .../main/csharp/io/swagger/Api/StoreApi.cs | 8 +- .../src/main/csharp/io/swagger/Api/UserApi.cs | 16 +- .../csharp/io/swagger/client/ApiInvoker.cs | 20 +- .../php/SwaggerClient-php/SwaggerClient.php | 16 + .../php/SwaggerClient-php/composer.json | 32 ++ .../php/SwaggerClient-php/lib/APIClient.php | 304 +++++++++++ .../lib/APIClientException.php | 38 ++ .../php/SwaggerClient-php/lib/PetApi.php | 493 ++++++++++++++++++ .../php/SwaggerClient-php/lib/StoreApi.php | 258 +++++++++ .../php/SwaggerClient-php/lib/UserApi.php | 472 +++++++++++++++++ .../SwaggerClient-php/lib/models/Category.php | 64 +++ .../SwaggerClient-php/lib/models/Order.php | 83 +++ .../php/SwaggerClient-php/lib/models/Pet.php | 83 +++ .../php/SwaggerClient-php/lib/models/Tag.php | 64 +++ .../php/SwaggerClient-php/lib/models/User.php | 91 ++++ samples/client/petstore/php/old/README.md | 52 ++ .../petstore/php/old/SwaggerPetstore.php | 16 + samples/client/petstore/php/old/composer.json | 32 ++ .../client/petstore/php/old/lib/APIClient.php | 304 +++++++++++ .../php/old/lib/APIClientException.php | 38 ++ .../client/petstore/php/old/lib/PetApi.php | 493 ++++++++++++++++++ .../client/petstore/php/old/lib/StoreApi.php | 258 +++++++++ .../client/petstore/php/old/lib/UserApi.php | 472 +++++++++++++++++ .../petstore/php/old/lib/models/Category.php | 64 +++ .../petstore/php/old/lib/models/Order.php | 83 +++ .../petstore/php/old/lib/models/Pet.php | 83 +++ .../petstore/php/old/lib/models/Tag.php | 64 +++ .../petstore/php/old/lib/models/User.php | 91 ++++ .../petstore/php/old/tests/PetApiTest.php | 19 + .../SwaggerPetstore/pet_api.py | 32 +- .../SwaggerPetstore/store_api.py | 16 +- .../SwaggerPetstore/user_api.py | 32 +- samples/client/petstore/ruby/lib/pet_api.rb | 16 +- samples/client/petstore/ruby/lib/store_api.rb | 8 +- samples/client/petstore/ruby/lib/user_api.rb | 16 +- samples/client/petstore/ruby/spec/pet_spec.rb | 16 +- .../client/petstore/ruby/spec/spec_helper.rb | 6 +- .../client/petstore/ruby/spec/store_spec.rb | 2 +- samples/html/index.html | 10 +- 51 files changed, 4278 insertions(+), 101 deletions(-) create mode 100644 samples/client/petstore/php/SwaggerClient-php/SwaggerClient.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/composer.json create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/APIClientException.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/models/Category.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/models/Order.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/models/Pet.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/models/Tag.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/models/User.php create mode 100644 samples/client/petstore/php/old/README.md create mode 100644 samples/client/petstore/php/old/SwaggerPetstore.php create mode 100644 samples/client/petstore/php/old/composer.json create mode 100644 samples/client/petstore/php/old/lib/APIClient.php create mode 100644 samples/client/petstore/php/old/lib/APIClientException.php create mode 100644 samples/client/petstore/php/old/lib/PetApi.php create mode 100644 samples/client/petstore/php/old/lib/StoreApi.php create mode 100644 samples/client/petstore/php/old/lib/UserApi.php create mode 100644 samples/client/petstore/php/old/lib/models/Category.php create mode 100644 samples/client/petstore/php/old/lib/models/Order.php create mode 100644 samples/client/petstore/php/old/lib/models/Pet.php create mode 100644 samples/client/petstore/php/old/lib/models/Tag.php create mode 100644 samples/client/petstore/php/old/lib/models/User.php create mode 100644 samples/client/petstore/php/old/tests/PetApiTest.php diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java index c8e0ad45283..6f51374c536 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/DefaultCodegen.java @@ -838,7 +838,8 @@ public class DefaultCodegen { // op.cookieParams = cookieParams; op.formParams = addHasMore(formParams); // legacy support - op.nickname = operationId; + op.nickname = op.operationId; + if(op.allParams.size() > 0) op.hasParams = true; diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AndroidClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AndroidClientCodegen.java index b161814152c..e97cd02c523 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AndroidClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/AndroidClientCodegen.java @@ -162,5 +162,14 @@ public class AndroidClientCodegen extends DefaultCodegen implements CodegenConfi return toModelName(name); } + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return camelize(operationId, true); + } + } diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/CSharpClientCodegen.java index 43a54f5478e..d815ade0915 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/CSharpClientCodegen.java @@ -163,4 +163,14 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig type = swaggerType; return type; } + + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return camelize(operationId); + } + } diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/JavaClientCodegen.java index 832f0a92329..39ed9dfe540 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/JavaClientCodegen.java @@ -160,4 +160,15 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { type = swaggerType; return toModelName(type); } + + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return camelize(operationId, true); + } + + } diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java index 3d9b756c007..54fa020922f 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ObjcClientCodegen.java @@ -276,4 +276,14 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig { public String escapeReservedWord(String name) { return "_" + name; } + + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return camelize(operationId, true); + } + } diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/Python3ClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/Python3ClientCodegen.java index 2e1a3ee165a..81ba21ebe72 100755 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/Python3ClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/Python3ClientCodegen.java @@ -186,4 +186,13 @@ public class Python3ClientCodegen extends DefaultCodegen implements CodegenConfi return underscore(name) + "_api"; } + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return underscore(operationId); + } + } diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java index b28c0ccf750..bbb07b1592a 100755 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/PythonClientCodegen.java @@ -196,4 +196,13 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig return underscore(name) + "_api"; } + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return underscore(operationId); + } + } diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/RubyClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/RubyClientCodegen.java index 5decf61d2c0..0c472a2b75d 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/RubyClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/RubyClientCodegen.java @@ -189,4 +189,14 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig { return camelize(name) + "Api"; } + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return underscore(operationId); + } + + } diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ScalaClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ScalaClientCodegen.java index 36114982419..4695cc3d065 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ScalaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/ScalaClientCodegen.java @@ -189,4 +189,15 @@ public class ScalaClientCodegen extends DefaultCodegen implements CodegenConfig else return "null"; } -} \ No newline at end of file + + + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + return camelize(operationId, true); + } + +} diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/TizenClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/TizenClientCodegen.java index 007a978d36b..ab9fa033f1c 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/TizenClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/TizenClientCodegen.java @@ -244,4 +244,15 @@ public class TizenClientCodegen extends DefaultCodegen implements CodegenConfig public String escapeReservedWord(String name) { return "_" + name; } + + @Override + public String toOperationId(String operationId) { + // method name cannot use reserved keyword, e.g. return$ + if(reservedWords.contains(operationId)) + throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); + + // add_pet_by_id => addPetById + return camelize(operationId, true); + } + } diff --git a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java index 8c3f271a13e..dec0db43f66 100644 --- a/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java +++ b/samples/client/petstore/android-java/src/main/java/io/swagger/client/ApiInvoker.java @@ -16,6 +16,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.*; import org.apache.http.impl.conn.*; +import org.apache.http.impl.conn.tsccm.*; import org.apache.http.params.*; import org.apache.http.util.EntityUtils; @@ -381,7 +382,7 @@ public class ApiInvoker { schemeRegistry.register(httpsScheme); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); - ignoreSSLConnectionManager = new SingleClientConnManager(new BasicHttpParams(), schemeRegistry); + ignoreSSLConnectionManager = new ThreadSafeClientConnManager(new BasicHttpParams(), schemeRegistry); } catch (NoSuchAlgorithmException e) { // This will only be thrown if SSL isn't available for some reason. } catch (KeyManagementException e) { diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/PetApi.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/PetApi.cs index 3750f302faa..4f20c0cba45 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/PetApi.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/PetApi.cs @@ -36,7 +36,7 @@ namespace io.swagger.Api { /// Pet object that needs to be added to the store /// - public void updatePet (Pet Body) { + public void UpdatePet (Pet Body) { // create path and map variables var path = "/pet".Replace("{format}","json"); @@ -84,7 +84,7 @@ namespace io.swagger.Api { /// Pet object that needs to be added to the store /// - public void addPet (Pet Body) { + public void AddPet (Pet Body) { // create path and map variables var path = "/pet".Replace("{format}","json"); @@ -132,7 +132,7 @@ namespace io.swagger.Api { /// Status values that need to be considered for filter /// - public List findPetsByStatus (List Status) { + public List FindPetsByStatus (List Status) { // create path and map variables var path = "/pet/findByStatus".Replace("{format}","json"); @@ -188,7 +188,7 @@ namespace io.swagger.Api { /// Tags to filter by /// - public List findPetsByTags (List Tags) { + public List FindPetsByTags (List Tags) { // create path and map variables var path = "/pet/findByTags".Replace("{format}","json"); @@ -244,7 +244,7 @@ namespace io.swagger.Api { /// ID of pet that needs to be fetched /// - public Pet getPetById (long? PetId) { + public Pet GetPetById (long? PetId) { // create path and map variables var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId)); @@ -299,7 +299,7 @@ namespace io.swagger.Api { /// Updated status of the pet /// - public void updatePetWithForm (string PetId, string Name, string Status) { + public void UpdatePetWithForm (string PetId, string Name, string Status) { // create path and map variables var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId)); @@ -362,7 +362,7 @@ namespace io.swagger.Api { /// Pet id to delete /// - public void deletePet (string ApiKey, long? PetId) { + public void DeletePet (string ApiKey, long? PetId) { // create path and map variables var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId)); @@ -413,7 +413,7 @@ namespace io.swagger.Api { /// file to upload /// - public void uploadFile (long? PetId, string AdditionalMetadata, byte[] File) { + public void UploadFile (long? PetId, string AdditionalMetadata, byte[] File) { // create path and map variables var path = "/pet/{petId}/uploadImage".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId)); diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/StoreApi.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/StoreApi.cs index 6ab79f87976..2514539e298 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/StoreApi.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/StoreApi.cs @@ -35,7 +35,7 @@ namespace io.swagger.Api { /// /// - public Dictionary getInventory () { + public Dictionary GetInventory () { // create path and map variables var path = "/store/inventory".Replace("{format}","json"); @@ -88,7 +88,7 @@ namespace io.swagger.Api { /// order placed for purchasing the pet /// - public Order placeOrder (Order Body) { + public Order PlaceOrder (Order Body) { // create path and map variables var path = "/store/order".Replace("{format}","json"); @@ -141,7 +141,7 @@ namespace io.swagger.Api { /// ID of pet that needs to be fetched /// - public Order getOrderById (string OrderId) { + public Order GetOrderById (string OrderId) { // create path and map variables var path = "/store/order/{orderId}".Replace("{format}","json").Replace("{" + "orderId" + "}", apiInvoker.ParameterToString(OrderId)); @@ -194,7 +194,7 @@ namespace io.swagger.Api { /// ID of the order that needs to be deleted /// - public void deleteOrder (string OrderId) { + public void DeleteOrder (string OrderId) { // create path and map variables var path = "/store/order/{orderId}".Replace("{format}","json").Replace("{" + "orderId" + "}", apiInvoker.ParameterToString(OrderId)); diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/UserApi.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/UserApi.cs index c262cbd38cb..4f1f4a1bf19 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/UserApi.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/UserApi.cs @@ -36,7 +36,7 @@ namespace io.swagger.Api { /// Created user object /// - public void createUser (User Body) { + public void CreateUser (User Body) { // create path and map variables var path = "/user".Replace("{format}","json"); @@ -84,7 +84,7 @@ namespace io.swagger.Api { /// List of user object /// - public void createUsersWithArrayInput (List Body) { + public void CreateUsersWithArrayInput (List Body) { // create path and map variables var path = "/user/createWithArray".Replace("{format}","json"); @@ -132,7 +132,7 @@ namespace io.swagger.Api { /// List of user object /// - public void createUsersWithListInput (List Body) { + public void CreateUsersWithListInput (List Body) { // create path and map variables var path = "/user/createWithList".Replace("{format}","json"); @@ -181,7 +181,7 @@ namespace io.swagger.Api { /// The password for login in clear text /// - public string loginUser (string Username, string Password) { + public string LoginUser (string Username, string Password) { // create path and map variables var path = "/user/login".Replace("{format}","json"); @@ -239,7 +239,7 @@ namespace io.swagger.Api { /// /// - public void logoutUser () { + public void LogoutUser () { // create path and map variables var path = "/user/logout".Replace("{format}","json"); @@ -287,7 +287,7 @@ namespace io.swagger.Api { /// The name that needs to be fetched. Use user1 for testing. /// - public User getUserByName (string Username) { + public User GetUserByName (string Username) { // create path and map variables var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username)); @@ -341,7 +341,7 @@ namespace io.swagger.Api { /// Updated user object /// - public void updateUser (string Username, User Body) { + public void UpdateUser (string Username, User Body) { // create path and map variables var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username)); @@ -389,7 +389,7 @@ namespace io.swagger.Api { /// The name that needs to be deleted /// - public void deleteUser (string Username) { + public void DeleteUser (string Username) { // create path and map variables var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username)); diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiInvoker.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiInvoker.cs index c14d1af7d6c..ee2c5b1d889 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiInvoker.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/client/ApiInvoker.cs @@ -15,10 +15,21 @@ return _instance; } + /// + /// Add default header + /// + /// Header field name + /// Header field value + /// public void addDefaultHeader(string key, string value) { defaultHeaderMap.Add(key, value); } + /// + /// escape string (url-encoded) + /// + /// String to be escaped + /// Escaped string public string escapeString(string str) { return str; } @@ -27,12 +38,18 @@ /// if parameter is DateTime, output in ISO8601 format, otherwise just return the string /// /// The parameter (header, path, query, form) - /// + /// Formatted string public string ParameterToString(object obj) { return (obj is DateTime) ? ((DateTime)obj).ToString ("u") : Convert.ToString (obj); } + /// + /// Deserialize the JSON string into a proper object + /// + /// JSON string + /// Object type + /// Object representation of the JSON string public static object deserialize(string json, Type type) { try { @@ -109,6 +126,7 @@ case "GET": break; case "POST": + case "PATCH": case "PUT": case "DELETE": using (Stream requestStream = client.GetRequestStream()) diff --git a/samples/client/petstore/php/SwaggerClient-php/SwaggerClient.php b/samples/client/petstore/php/SwaggerClient-php/SwaggerClient.php new file mode 100644 index 00000000000..058aa169504 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/SwaggerClient.php @@ -0,0 +1,16 @@ + diff --git a/samples/client/petstore/php/SwaggerClient-php/composer.json b/samples/client/petstore/php/SwaggerClient-php/composer.json new file mode 100644 index 00000000000..13fc1b62690 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/composer.json @@ -0,0 +1,32 @@ +{ + "name": "SwaggerClient/SwaggerClient-php", + "description": "", + "keywords": [ + "swagger", + "php", + "sdk", + "api" + ], + "homepage": "http://swagger.io", + "license": "Apache v2", + "authors": [ + { + "name": "Swagger and contributors", + "homepage": "https://github.com/swagger-api/swagger-codegen" + } + ], + "require": { + "php": ">=5.3.3", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "~0.6.1", + "squizlabs/php_codesniffer": "~2.0" + }, + "autoload": { + "psr-4": { "SwaggerClient\\" : "lib/" } + } +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php new file mode 100644 index 00000000000..f69675c1e9b --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/APIClient.php @@ -0,0 +1,304 @@ +host = $host; + $this->headerName = $headerName; + $this->headerValue = $headerValue; + } + + /** + * Set the user agent of the API client + * + * @param string $user_agent The user agent of the API client + */ + public function setUserAgent($user_agent) { + if (!is_string($user_agent)) { + throw new Exception('User-agent must be a string.'); + } + $this->user_agent= $user_agent; + } + + /** + * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + */ + public function setTimeout($seconds) { + if (!is_numeric($seconds)) { + throw new Exception('Timeout variable must be numeric.'); + } + $this->curl_timeout = $seconds; + } + + /** + * @param string $resourcePath path to method endpoint + * @param string $method method to call + * @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 mixed + */ + public function callAPI($resourcePath, $method, $queryParams, $postData, + $headerParams) { + + $headers = array(); + + # Allow API key from $headerParams to override default + $added_api_key = False; + if ($headerParams != null) { + foreach ($headerParams as $key => $val) { + $headers[] = "$key: $val"; + if ($key == $this->headerName) { + $added_api_key = True; + } + } + } + if (! $added_api_key && $this->headerName != null) { + $headers[] = $this->headerName . ": " . $this->headerValue; + } + + if ((isset($headerName['Content-Type']) and strpos($headerName['Content-Type'], "multipart/form-data") === FALSE) and (is_object($postData) or is_array($postData))) { + $postData = json_encode($this->sanitizeForSerialization($postData)); + } + + $url = $this->host . $resourcePath; + + $curl = curl_init(); + // set timeout, if needed + if ($this->curl_timeout != 0) { + curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout); + } + // return the result on success, rather than just TRUE + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + if (! empty($queryParams)) { + $url = ($url . '?' . http_build_query($queryParams)); + } + + if ($method == self::$POST) { + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PATCH) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PUT) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$DELETE) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method != self::$GET) { + throw new Exception('Method ' . $method . ' is not recognized.'); + } + curl_setopt($curl, CURLOPT_URL, $url); + + // Set user agent + curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); + + // Make the request + $response = curl_exec($curl); + $response_info = curl_getinfo($curl); + + // Handle the response + if ($response_info['http_code'] == 0) { + throw new APIClientException("TIMEOUT: api call to " . $url . + " took more than 5s to return", 0, $response_info, $response); + } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { + $data = json_decode($response); + if (json_last_error() > 0) { // if response is a string + $data = $response; + } + } else if ($response_info['http_code'] == 401) { + throw new APIClientException("Unauthorized API request to " . $url . + ": " . serialize($response), 0, $response_info, $response); + } else if ($response_info['http_code'] == 404) { + $data = null; + } else { + throw new APIClientException("Can't connect to the api: " . $url . + " response code: " . + $response_info['http_code'], 0, $response_info, $response); + } + return $data; + } + + /** + * Build a JSON POST object + */ + 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[$data::$attributeMap[$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 + * the path, by url-encoding. + * @param string $value a string which will be part of the path + * @return string the serialized object + */ + public static function toPathValue($value) { + return rawurlencode(self::toString($value)); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the query, by imploding comma-separated if it's an object. + * If it's a string, pass through unchanged. It will be url-encoded + * later. + * @param object $object an object to be serialized to a string + * @return string the serialized object + */ + public static function toQueryValue($object) { + if (is_array($object)) { + return implode(',', $object); + } else { + return self::toString($object); + } + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the header. If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * @param string $value a string which will be part of the header + * @return string the header string + */ + public static function toHeaderValue($value) { + return self::toString($value); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the http body (form parameter). If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * @param string $value the value of the form parameter + * @return string the form string + */ + public static function toFormValue($value) { + return self::toString($value); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the parameter. If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * @param string $value the value of the parameter + * @return string the header string + */ + public static function toString($value) { + if ($value instanceof \DateTime) { // datetime in ISO8601 format + return $value->format(\DateTime::ISO8601); + } + else { + 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($data, $class) + { + if (null === $data) { + $deserialized = null; + } elseif (substr($class, 0, 4) == 'map[') { + $inner = substr($class, 4, -1); + $values = array(); + if(strrpos($inner, ",") !== false) { + $subClass_array = explode(',', $inner, 2); + $subClass = $subClass_array[1]; + foreach ($data as $key => $value) { + $values[] = array($key => self::deserialize($value, $subClass)); + } + } + $deserialized = $values; + } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { + $subClass = substr($class, 6, -1); + $values = array(); + foreach ($data as $key => $value) { + $values[] = self::deserialize($value, $subClass); + } + $deserialized = $values; + } elseif ($class == 'DateTime') { + $deserialized = new \DateTime($data); + } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool'))) { + settype($data, $class); + $deserialized = $data; + } else { + $class = "SwaggerClient\\models\\".$class; + $instance = new $class(); + foreach ($instance::$swaggerTypes as $property => $type) { + $original_property_name = $instance::$attributeMap[$property]; + if (isset($original_property_name)) { + $instance->$property = self::deserialize($data->$original_property_name, $type); + } + } + $deserialized = $instance; + } + + return $deserialized; + } + +} + diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/APIClientException.php b/samples/client/petstore/php/SwaggerClient-php/lib/APIClientException.php new file mode 100644 index 00000000000..8d83da0186e --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/APIClientException.php @@ -0,0 +1,38 @@ +response_info = $response_info; + $this->response = $response; + } + + public function getResponse() { + return $this->response; + } + + public function getResponseInfo() { + return $this->response_info; + } +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php new file mode 100644 index 00000000000..80d9c040d1e --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/PetApi.php @@ -0,0 +1,493 @@ +apiClient = $apiClient; + } + + + /** + * updatePet + * + * Update an existing pet + * + * @param Pet $body Pet object that needs to be added to the store (required) + * @return void + */ + public function updatePet($body) { + + // parse inputs + $resourcePath = "/pet"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array('application/json','application/xml',); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * addPet + * + * Add a new pet to the store + * + * @param Pet $body Pet object that needs to be added to the store (required) + * @return void + */ + public function addPet($body) { + + // parse inputs + $resourcePath = "/pet"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array('application/json','application/xml',); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * findPetsByStatus + * + * Finds Pets by status + * + * @param array[string] $status Status values that need to be considered for filter (required) + * @return array[Pet] + */ + public function findPetsByStatus($status) { + + // parse inputs + $resourcePath = "/pet/findByStatus"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + // query params + if($status !== null) { + $queryParams['status'] = $this->apiClient->toQueryValue($status); + } + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'array[Pet]'); + return $responseObject; + } + + /** + * findPetsByTags + * + * Finds Pets by tags + * + * @param array[string] $tags Tags to filter by (required) + * @return array[Pet] + */ + public function findPetsByTags($tags) { + + // parse inputs + $resourcePath = "/pet/findByTags"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + // query params + if($tags !== null) { + $queryParams['tags'] = $this->apiClient->toQueryValue($tags); + } + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'array[Pet]'); + return $responseObject; + } + + /** + * getPetById + * + * Find pet by ID + * + * @param int $pet_id ID of pet that needs to be fetched (required) + * @return Pet + */ + public function getPetById($pet_id) { + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'Pet'); + return $responseObject; + } + + /** + * updatePetWithForm + * + * Updates a pet in the store with form data + * + * @param string $pet_id ID of pet that needs to be updated (required) + * @param string $name Updated name of the pet (required) + * @param string $status Updated status of the pet (required) + * @return void + */ + public function updatePetWithForm($pet_id, $name, $status) { + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array('application/x-www-form-urlencoded',); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } + // form params + if ($name !== null) { + $formParams['name'] = $this->apiClient->toFormValue($name); + }// form params + if ($status !== null) { + $formParams['status'] = $this->apiClient->toFormValue($status); + } + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * deletePet + * + * Deletes a pet + * + * @param string $api_key (required) + * @param int $pet_id Pet id to delete (required) + * @return void + */ + public function deletePet($api_key, $pet_id) { + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + // header params + if($api_key !== null) { + $headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key); + } + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * uploadFile + * + * uploads an image + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (required) + * @param file $file file to upload (required) + * @return void + */ + public function uploadFile($pet_id, $additional_metadata, $file) { + + // parse inputs + $resourcePath = "/pet/{petId}/uploadImage"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array('multipart/form-data',); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } + // form params + if ($additional_metadata !== null) { + $formParams['additionalMetadata'] = $this->apiClient->toFormValue($additional_metadata); + }// form params + if ($file !== null) { + $formParams['file'] = '@' . $this->apiClient->toFormValue($file); + } + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php new file mode 100644 index 00000000000..4e40ed983b9 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/StoreApi.php @@ -0,0 +1,258 @@ +apiClient = $apiClient; + } + + + /** + * getInventory + * + * Returns pet inventories by status + * + * @return map[string,int] + */ + public function getInventory() { + + // parse inputs + $resourcePath = "/store/inventory"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'map[string,int]'); + return $responseObject; + } + + /** + * placeOrder + * + * Place an order for a pet + * + * @param Order $body order placed for purchasing the pet (required) + * @return Order + */ + public function placeOrder($body) { + + // parse inputs + $resourcePath = "/store/order"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'Order'); + return $responseObject; + } + + /** + * getOrderById + * + * Find purchase order by ID + * + * @param string $order_id ID of pet that needs to be fetched (required) + * @return Order + */ + public function getOrderById($order_id) { + + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($order_id !== null) { + $resourcePath = str_replace("{" . "orderId" . "}", + $this->apiClient->toPathValue($order_id), $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'Order'); + return $responseObject; + } + + /** + * deleteOrder + * + * Delete purchase order by ID + * + * @param string $order_id ID of the order that needs to be deleted (required) + * @return void + */ + public function deleteOrder($order_id) { + + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($order_id !== null) { + $resourcePath = str_replace("{" . "orderId" . "}", + $this->apiClient->toPathValue($order_id), $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php new file mode 100644 index 00000000000..f3e9e7f4cc6 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/UserApi.php @@ -0,0 +1,472 @@ +apiClient = $apiClient; + } + + + /** + * createUser + * + * Create user + * + * @param User $body Created user object (required) + * @return void + */ + public function createUser($body) { + + // parse inputs + $resourcePath = "/user"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * createUsersWithArrayInput + * + * Creates list of users with given input array + * + * @param array[User] $body List of user object (required) + * @return void + */ + public function createUsersWithArrayInput($body) { + + // parse inputs + $resourcePath = "/user/createWithArray"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * createUsersWithListInput + * + * Creates list of users with given input array + * + * @param array[User] $body List of user object (required) + * @return void + */ + public function createUsersWithListInput($body) { + + // parse inputs + $resourcePath = "/user/createWithList"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * loginUser + * + * Logs user into the system + * + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * @return string + */ + public function loginUser($username, $password) { + + // parse inputs + $resourcePath = "/user/login"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + // query params + if($username !== null) { + $queryParams['username'] = $this->apiClient->toQueryValue($username); + }// query params + if($password !== null) { + $queryParams['password'] = $this->apiClient->toQueryValue($password); + } + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'string'); + return $responseObject; + } + + /** + * logoutUser + * + * Logs out current logged in user session + * + * @return void + */ + public function logoutUser() { + + // parse inputs + $resourcePath = "/user/logout"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * getUserByName + * + * Get user by user name + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @return User + */ + public function getUserByName($username) { + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'User'); + return $responseObject; + } + + /** + * updateUser + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param User $body Updated user object (required) + * @return void + */ + public function updateUser($username, $body) { + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } + + // body params + $_tempBody = null; + if (isset($body)) { + $_tempBody = $body; + } + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * deleteUser + * + * Delete user + * + * @param string $username The name that needs to be deleted (required) + * @return void + */ + public function deleteUser($username) { + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") !== FALSE) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/models/Category.php new file mode 100644 index 00000000000..9c2a6542301 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/models/Category.php @@ -0,0 +1,64 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/models/Order.php new file mode 100644 index 00000000000..c6a909b29ef --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/models/Order.php @@ -0,0 +1,83 @@ + 'int', + 'pet_id' => 'int', + 'quantity' => 'int', + 'ship_date' => 'DateTime', + 'status' => 'string', + 'complete' => 'boolean' + ); + + static $attributeMap = array( + 'id' => 'id', + 'pet_id' => 'petId', + 'quantity' => 'quantity', + 'ship_date' => 'shipDate', + 'status' => 'status', + 'complete' => 'complete' + ); + + + public $id; /* int */ + public $pet_id; /* int */ + public $quantity; /* int */ + public $ship_date; /* DateTime */ + /** + * Order Status + */ + public $status; /* string */ + public $complete; /* boolean */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->pet_id = $data["pet_id"]; + $this->quantity = $data["quantity"]; + $this->ship_date = $data["ship_date"]; + $this->status = $data["status"]; + $this->complete = $data["complete"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/models/Pet.php new file mode 100644 index 00000000000..d2014f3fa34 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/models/Pet.php @@ -0,0 +1,83 @@ + 'int', + 'category' => 'Category', + 'name' => 'string', + 'photo_urls' => 'array[string]', + 'tags' => 'array[Tag]', + 'status' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'category' => 'category', + 'name' => 'name', + 'photo_urls' => 'photoUrls', + 'tags' => 'tags', + 'status' => 'status' + ); + + + public $id; /* int */ + public $category; /* Category */ + public $name; /* string */ + public $photo_urls; /* array[string] */ + public $tags; /* array[Tag] */ + /** + * pet status in the store + */ + public $status; /* string */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->category = $data["category"]; + $this->name = $data["name"]; + $this->photo_urls = $data["photo_urls"]; + $this->tags = $data["tags"]; + $this->status = $data["status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/models/Tag.php new file mode 100644 index 00000000000..4a87c0626f1 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/models/Tag.php @@ -0,0 +1,64 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/models/User.php new file mode 100644 index 00000000000..ab8b4a60fc4 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/models/User.php @@ -0,0 +1,91 @@ + 'int', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'email' => 'string', + 'password' => 'string', + 'phone' => 'string', + 'user_status' => 'int' + ); + + static $attributeMap = array( + 'id' => 'id', + 'username' => 'username', + 'first_name' => 'firstName', + 'last_name' => 'lastName', + 'email' => 'email', + 'password' => 'password', + 'phone' => 'phone', + 'user_status' => 'userStatus' + ); + + + public $id; /* int */ + public $username; /* string */ + public $first_name; /* string */ + public $last_name; /* string */ + public $email; /* string */ + public $password; /* string */ + public $phone; /* string */ + /** + * User Status + */ + public $user_status; /* int */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->username = $data["username"]; + $this->first_name = $data["first_name"]; + $this->last_name = $data["last_name"]; + $this->email = $data["email"]; + $this->password = $data["password"]; + $this->phone = $data["phone"]; + $this->user_status = $data["user_status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/old/README.md b/samples/client/petstore/php/old/README.md new file mode 100644 index 00000000000..6dfd19a292a --- /dev/null +++ b/samples/client/petstore/php/old/README.md @@ -0,0 +1,52 @@ +## Requirements + +PHP 5.3.3 and later. + +## Composer + +You can install the bindings via [Composer](http://getcomposer.org/). Add this to your `composer.json`: + + { + "repositories": [ + { + "type": "git", + "url": "https://github.com/wing328/SwaggerPetstore-php.git" + } + ], + "require": { + "SwaggerPetstore/SwaggerPetstore-php": "*@dev" + } + } + +Then install via: + + composer install + +To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/00-intro.md#autoloading): + + require_once('vendor/autoload.php'); + +## Manual Installation + +If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the `SwaggerPetstore.php` file. + + require_once('/path/to/SwaggerPetstore-php/SwaggerPetstore.php'); + +## Getting Started + +php test.php + +## Documentation + +TODO + +## Tests + +In order to run tests first install [PHPUnit](http://packagist.org/packages/phpunit/phpunit) via [Composer](http://getcomposer.org/): + + composer update + +To run the test suite: + + ./vendor/bin/phpunit tests + diff --git a/samples/client/petstore/php/old/SwaggerPetstore.php b/samples/client/petstore/php/old/SwaggerPetstore.php new file mode 100644 index 00000000000..058aa169504 --- /dev/null +++ b/samples/client/petstore/php/old/SwaggerPetstore.php @@ -0,0 +1,16 @@ + diff --git a/samples/client/petstore/php/old/composer.json b/samples/client/petstore/php/old/composer.json new file mode 100644 index 00000000000..7109d7a8790 --- /dev/null +++ b/samples/client/petstore/php/old/composer.json @@ -0,0 +1,32 @@ +{ + "name": "SwaggerPetstore/SwaggerPetstore-php", + "description": "", + "keywords": [ + "swagger", + "php", + "sdk", + "api" + ], + "homepage": "http://swagger.io", + "license": "Apache v2", + "authors": [ + { + "name": "Swagger and contributors", + "homepage": "https://github.com/swagger-api/swagger-codegen" + } + ], + "require": { + "php": ">=5.3.3", + "ext-curl": "*", + "ext-json": "*", + "ext-mbstring": "*" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "satooshi/php-coveralls": "~0.6.1", + "squizlabs/php_codesniffer": "~2.0" + }, + "autoload": { + "psr-4": { "SwaggerPetstore\\" : "lib/" } + } +} diff --git a/samples/client/petstore/php/old/lib/APIClient.php b/samples/client/petstore/php/old/lib/APIClient.php new file mode 100644 index 00000000000..681bb8cee3c --- /dev/null +++ b/samples/client/petstore/php/old/lib/APIClient.php @@ -0,0 +1,304 @@ +host = $host; + $this->headerName = $headerName; + $this->headerValue = $headerValue; + } + + /** + * Set the user agent of the API client + * + * @param string $user_agent The user agent of the API client + */ + public function setUserAgent($user_agent) { + if (!is_string($user_agent)) { + throw new Exception('User-agent must be a string.'); + } + $this->user_agent= $user_agent; + } + + /** + * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] + */ + public function setTimeout($seconds) { + if (!is_numeric($seconds)) { + throw new Exception('Timeout variable must be numeric.'); + } + $this->curl_timeout = $seconds; + } + + /** + * @param string $resourcePath path to method endpoint + * @param string $method method to call + * @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 mixed + */ + public function callAPI($resourcePath, $method, $queryParams, $postData, + $headerParams) { + + $headers = array(); + + # Allow API key from $headerParams to override default + $added_api_key = False; + if ($headerParams != null) { + foreach ($headerParams as $key => $val) { + $headers[] = "$key: $val"; + if ($key == $this->headerName) { + $added_api_key = True; + } + } + } + if (! $added_api_key && $this->headerName != null) { + $headers[] = $this->headerName . ": " . $this->headerValue; + } + + if ((isset($headers['Content-Type']) and strpos($headers['Content-Type'], "multipart/form-data") < 0) and (is_object($postData) or is_array($postData))) { + $postData = json_encode($this->sanitizeForSerialization($postData)); + } + + $url = $this->host . $resourcePath; + + $curl = curl_init(); + // set timeout, if needed + if ($this->curl_timeout != 0) { + curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout); + } + // return the result on success, rather than just TRUE + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + + if (! empty($queryParams)) { + $url = ($url . '?' . http_build_query($queryParams)); + } + + if ($method == self::$POST) { + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PATCH) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$PUT) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method == self::$DELETE) { + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); + curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); + } else if ($method != self::$GET) { + throw new Exception('Method ' . $method . ' is not recognized.'); + } + curl_setopt($curl, CURLOPT_URL, $url); + + // Set user agent + curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); + + // Make the request + $response = curl_exec($curl); + $response_info = curl_getinfo($curl); + + // Handle the response + if ($response_info['http_code'] == 0) { + throw new APIClientException("TIMEOUT: api call to " . $url . + " took more than 5s to return", 0, $response_info, $response); + } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { + $data = json_decode($response); + if (json_last_error() > 0) { // if response is a string + $data = $response; + } + } else if ($response_info['http_code'] == 401) { + throw new APIClientException("Unauthorized API request to " . $url . + ": " . serialize($response), 0, $response_info, $response); + } else if ($response_info['http_code'] == 404) { + $data = null; + } else { + throw new APIClientException("Can't connect to the api: " . $url . + " response code: " . + $response_info['http_code'], 0, $response_info, $response); + } + return $data; + } + + /** + * Build a JSON POST object + */ + 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[$data::$attributeMap[$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 + * the path, by url-encoding. + * @param string $value a string which will be part of the path + * @return string the serialized object + */ + public static function toPathValue($value) { + return rawurlencode(self::toString($value)); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the query, by imploding comma-separated if it's an object. + * If it's a string, pass through unchanged. It will be url-encoded + * later. + * @param object $object an object to be serialized to a string + * @return string the serialized object + */ + public static function toQueryValue($object) { + if (is_array($object)) { + return implode(',', $object); + } else { + return self::toString($object); + } + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the header. If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * @param string $value a string which will be part of the header + * @return string the header string + */ + public static function toHeaderValue($value) { + return self::toString($value); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the http body (form parameter). If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * @param string $value the value of the form parameter + * @return string the form string + */ + public static function toFormValue($value) { + return self::toString($value); + } + + /** + * Take value and turn it into a string suitable for inclusion in + * the parameter. If it's a string, pass through unchanged + * If it's a datetime object, format it in ISO8601 + * @param string $value the value of the parameter + * @return string the header string + */ + public static function toString($value) { + if ($value instanceof \DateTime) { // datetime in ISO8601 format + return $value->format(\DateTime::ISO8601); + } + else { + 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($data, $class) + { + if (null === $data) { + $deserialized = null; + } elseif (substr($class, 0, 4) == 'map[') { + $inner = substr($class, 4, -1); + $values = array(); + if(strrpos($inner, ",") !== false) { + $subClass_array = explode(',', $inner, 2); + $subClass = $subClass_array[1]; + foreach ($data as $key => $value) { + $values[] = array($key => self::deserialize($value, $subClass)); + } + } + $deserialized = $values; + } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { + $subClass = substr($class, 6, -1); + $values = array(); + foreach ($data as $key => $value) { + $values[] = self::deserialize($value, $subClass); + } + $deserialized = $values; + } elseif ($class == 'DateTime') { + $deserialized = new \DateTime($data); + } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool'))) { + settype($data, $class); + $deserialized = $data; + } else { + $class = "SwaggerPetstore\\models\\".$class; + $instance = new $class(); + foreach ($instance::$swaggerTypes as $property => $type) { + if (isset($data->$property)) { + $original_property_name = $instance::$attributeMap[$property]; + $instance->$property = self::deserialize($data->$original_property_name, $type); + } + } + $deserialized = $instance; + } + + return $deserialized; + } + +} + diff --git a/samples/client/petstore/php/old/lib/APIClientException.php b/samples/client/petstore/php/old/lib/APIClientException.php new file mode 100644 index 00000000000..8f083caf6f9 --- /dev/null +++ b/samples/client/petstore/php/old/lib/APIClientException.php @@ -0,0 +1,38 @@ +response_info = $response_info; + $this->response = $response; + } + + public function getResponse() { + return $this->response; + } + + public function getResponseInfo() { + return $this->response_info; + } +} diff --git a/samples/client/petstore/php/old/lib/PetApi.php b/samples/client/petstore/php/old/lib/PetApi.php new file mode 100644 index 00000000000..1b31db8915d --- /dev/null +++ b/samples/client/petstore/php/old/lib/PetApi.php @@ -0,0 +1,493 @@ +apiClient = $apiClient; + } + + + /** + * updatePet + * + * Update an existing pet + * + * @param Pet $body Pet object that needs to be added to the store (required) + * @return void + */ + public function updatePet($body) { + + // parse inputs + $resourcePath = "/pet"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array('application/json','application/xml',); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $body = null; + if (isset($body)) { + $body = $body; + } + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * addPet + * + * Add a new pet to the store + * + * @param Pet $body Pet object that needs to be added to the store (required) + * @return void + */ + public function addPet($body) { + + // parse inputs + $resourcePath = "/pet"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array('application/json','application/xml',); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $body = null; + if (isset($body)) { + $body = $body; + } + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * findPetsByStatus + * + * Finds Pets by status + * + * @param array[string] $status Status values that need to be considered for filter (required) + * @return array[Pet] + */ + public function findPetsByStatus($status) { + + // parse inputs + $resourcePath = "/pet/findByStatus"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + // query params + if($status !== null) { + $queryParams['status'] = $this->apiClient->toQueryValue($status); + } + + + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'array[Pet]'); + return $responseObject; + } + + /** + * findPetsByTags + * + * Finds Pets by tags + * + * @param array[string] $tags Tags to filter by (required) + * @return array[Pet] + */ + public function findPetsByTags($tags) { + + // parse inputs + $resourcePath = "/pet/findByTags"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + // query params + if($tags !== null) { + $queryParams['tags'] = $this->apiClient->toQueryValue($tags); + } + + + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'array[Pet]'); + return $responseObject; + } + + /** + * getPetById + * + * Find pet by ID + * + * @param int $pet_id ID of pet that needs to be fetched (required) + * @return Pet + */ + public function getPetById($pet_id) { + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'Pet'); + return $responseObject; + } + + /** + * updatePetWithForm + * + * Updates a pet in the store with form data + * + * @param string $pet_id ID of pet that needs to be updated (required) + * @param string $name Updated name of the pet (required) + * @param string $status Updated status of the pet (required) + * @return void + */ + public function updatePetWithForm($pet_id, $name, $status) { + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array('application/x-www-form-urlencoded',); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } + // form params + if ($name !== null) { + $formParams['name'] = $this->apiClient->toFormValue($name); + }// form params + if ($status !== null) { + $formParams['status'] = $this->apiClient->toFormValue($status); + } + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * deletePet + * + * Deletes a pet + * + * @param string $api_key (required) + * @param int $pet_id Pet id to delete (required) + * @return void + */ + public function deletePet($api_key, $pet_id) { + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + // header params + if($api_key !== null) { + $headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key); + } + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * uploadFile + * + * uploads an image + * + * @param int $pet_id ID of pet to update (required) + * @param string $additional_metadata Additional data to pass to server (required) + * @param file $file file to upload (required) + * @return void + */ + public function uploadFile($pet_id, $additional_metadata, $file) { + + // parse inputs + $resourcePath = "/pet/{petId}/uploadImage"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array('multipart/form-data',); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($pet_id !== null) { + $resourcePath = str_replace("{" . "petId" . "}", + $this->apiClient->toPathValue($pet_id), $resourcePath); + } + // form params + if ($additional_metadata !== null) { + $formParams['additionalMetadata'] = $this->apiClient->toFormValue($additional_metadata); + }// form params + if ($file !== null) { + $formParams['file'] = '@' . $this->apiClient->toFormValue($file); + } + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + +} diff --git a/samples/client/petstore/php/old/lib/StoreApi.php b/samples/client/petstore/php/old/lib/StoreApi.php new file mode 100644 index 00000000000..83a3f0520fa --- /dev/null +++ b/samples/client/petstore/php/old/lib/StoreApi.php @@ -0,0 +1,258 @@ +apiClient = $apiClient; + } + + + /** + * getInventory + * + * Returns pet inventories by status + * + * @return map[string,int] + */ + public function getInventory() { + + // parse inputs + $resourcePath = "/store/inventory"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'map[string,int]'); + return $responseObject; + } + + /** + * placeOrder + * + * Place an order for a pet + * + * @param Order $body order placed for purchasing the pet (required) + * @return Order + */ + public function placeOrder($body) { + + // parse inputs + $resourcePath = "/store/order"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $body = null; + if (isset($body)) { + $body = $body; + } + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'Order'); + return $responseObject; + } + + /** + * getOrderById + * + * Find purchase order by ID + * + * @param string $order_id ID of pet that needs to be fetched (required) + * @return Order + */ + public function getOrderById($order_id) { + + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($order_id !== null) { + $resourcePath = str_replace("{" . "orderId" . "}", + $this->apiClient->toPathValue($order_id), $resourcePath); + } + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'Order'); + return $responseObject; + } + + /** + * deleteOrder + * + * Delete purchase order by ID + * + * @param string $order_id ID of the order that needs to be deleted (required) + * @return void + */ + public function deleteOrder($order_id) { + + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($order_id !== null) { + $resourcePath = str_replace("{" . "orderId" . "}", + $this->apiClient->toPathValue($order_id), $resourcePath); + } + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + +} diff --git a/samples/client/petstore/php/old/lib/UserApi.php b/samples/client/petstore/php/old/lib/UserApi.php new file mode 100644 index 00000000000..d55b430d7a1 --- /dev/null +++ b/samples/client/petstore/php/old/lib/UserApi.php @@ -0,0 +1,472 @@ +apiClient = $apiClient; + } + + + /** + * createUser + * + * Create user + * + * @param User $body Created user object (required) + * @return void + */ + public function createUser($body) { + + // parse inputs + $resourcePath = "/user"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $body = null; + if (isset($body)) { + $body = $body; + } + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * createUsersWithArrayInput + * + * Creates list of users with given input array + * + * @param array[User] $body List of user object (required) + * @return void + */ + public function createUsersWithArrayInput($body) { + + // parse inputs + $resourcePath = "/user/createWithArray"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $body = null; + if (isset($body)) { + $body = $body; + } + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * createUsersWithListInput + * + * Creates list of users with given input array + * + * @param array[User] $body List of user object (required) + * @return void + */ + public function createUsersWithListInput($body) { + + // parse inputs + $resourcePath = "/user/createWithList"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + // body params + $body = null; + if (isset($body)) { + $body = $body; + } + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * loginUser + * + * Logs user into the system + * + * @param string $username The user name for login (required) + * @param string $password The password for login in clear text (required) + * @return string + */ + public function loginUser($username, $password) { + + // parse inputs + $resourcePath = "/user/login"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + // query params + if($username !== null) { + $queryParams['username'] = $this->apiClient->toQueryValue($username); + }// query params + if($password !== null) { + $queryParams['password'] = $this->apiClient->toQueryValue($password); + } + + + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'string'); + return $responseObject; + } + + /** + * logoutUser + * + * Logs out current logged in user session + * + * @return void + */ + public function logoutUser() { + + // parse inputs + $resourcePath = "/user/logout"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * getUserByName + * + * Get user by user name + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @return User + */ + public function getUserByName($username) { + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response, + 'User'); + return $responseObject; + } + + /** + * updateUser + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param User $body Updated user object (required) + * @return void + */ + public function updateUser($username, $body) { + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } + + // body params + $body = null; + if (isset($body)) { + $body = $body; + } + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + /** + * deleteUser + * + * Delete user + * + * @param string $username The name that needs to be deleted (required) + * @return void + */ + public function deleteUser($username) { + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = 'application/json, application/xml'; + if ($_header_accept !== '') { + $headerParams['Accept'] = $_header_accept; + } + $_header_content_type = array(); + $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; + + + + // path params + if($username !== null) { + $resourcePath = str_replace("{" . "username" . "}", + $this->apiClient->toPathValue($username), $resourcePath); + } + + + + // for model (json/xml) + if (isset($body)) { + $httpBody = $body; // $body is the method argument, if present + } + + // for HTTP post (form) + if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { + $httpBody = http_build_query($formParams); + } + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams); + + + } + + +} diff --git a/samples/client/petstore/php/old/lib/models/Category.php b/samples/client/petstore/php/old/lib/models/Category.php new file mode 100644 index 00000000000..101222b4503 --- /dev/null +++ b/samples/client/petstore/php/old/lib/models/Category.php @@ -0,0 +1,64 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/old/lib/models/Order.php b/samples/client/petstore/php/old/lib/models/Order.php new file mode 100644 index 00000000000..87e8c812eb7 --- /dev/null +++ b/samples/client/petstore/php/old/lib/models/Order.php @@ -0,0 +1,83 @@ + 'int', + 'pet_id' => 'int', + 'quantity' => 'int', + 'ship_date' => 'DateTime', + 'status' => 'string', + 'complete' => 'boolean' + ); + + static $attributeMap = array( + 'id' => 'id', + 'pet_id' => 'petId', + 'quantity' => 'quantity', + 'ship_date' => 'shipDate', + 'status' => 'status', + 'complete' => 'complete' + ); + + + public $id; /* int */ + public $pet_id; /* int */ + public $quantity; /* int */ + public $ship_date; /* DateTime */ + /** + * Order Status + */ + public $status; /* string */ + public $complete; /* boolean */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->pet_id = $data["pet_id"]; + $this->quantity = $data["quantity"]; + $this->ship_date = $data["ship_date"]; + $this->status = $data["status"]; + $this->complete = $data["complete"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/old/lib/models/Pet.php b/samples/client/petstore/php/old/lib/models/Pet.php new file mode 100644 index 00000000000..eb67904bf13 --- /dev/null +++ b/samples/client/petstore/php/old/lib/models/Pet.php @@ -0,0 +1,83 @@ + 'int', + 'category' => 'Category', + 'name' => 'string', + 'photo_urls' => 'array[string]', + 'tags' => 'array[Tag]', + 'status' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'category' => 'category', + 'name' => 'name', + 'photo_urls' => 'photoUrls', + 'tags' => 'tags', + 'status' => 'status' + ); + + + public $id; /* int */ + public $category; /* Category */ + public $name; /* string */ + public $photo_urls; /* array[string] */ + public $tags; /* array[Tag] */ + /** + * pet status in the store + */ + public $status; /* string */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->category = $data["category"]; + $this->name = $data["name"]; + $this->photo_urls = $data["photo_urls"]; + $this->tags = $data["tags"]; + $this->status = $data["status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/old/lib/models/Tag.php b/samples/client/petstore/php/old/lib/models/Tag.php new file mode 100644 index 00000000000..a9982317ece --- /dev/null +++ b/samples/client/petstore/php/old/lib/models/Tag.php @@ -0,0 +1,64 @@ + 'int', + 'name' => 'string' + ); + + static $attributeMap = array( + 'id' => 'id', + 'name' => 'name' + ); + + + public $id; /* int */ + public $name; /* string */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->name = $data["name"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/old/lib/models/User.php b/samples/client/petstore/php/old/lib/models/User.php new file mode 100644 index 00000000000..8662f937bc8 --- /dev/null +++ b/samples/client/petstore/php/old/lib/models/User.php @@ -0,0 +1,91 @@ + 'int', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'email' => 'string', + 'password' => 'string', + 'phone' => 'string', + 'user_status' => 'int' + ); + + static $attributeMap = array( + 'id' => 'id', + 'username' => 'username', + 'first_name' => 'firstName', + 'last_name' => 'lastName', + 'email' => 'email', + 'password' => 'password', + 'phone' => 'phone', + 'user_status' => 'userStatus' + ); + + + public $id; /* int */ + public $username; /* string */ + public $first_name; /* string */ + public $last_name; /* string */ + public $email; /* string */ + public $password; /* string */ + public $phone; /* string */ + /** + * User Status + */ + public $user_status; /* int */ + + public function __construct(array $data = null) { + $this->id = $data["id"]; + $this->username = $data["username"]; + $this->first_name = $data["first_name"]; + $this->last_name = $data["last_name"]; + $this->email = $data["email"]; + $this->password = $data["password"]; + $this->phone = $data["phone"]; + $this->user_status = $data["user_status"]; + } + + public function offsetExists($offset) { + return isset($this->$offset); + } + + public function offsetGet($offset) { + return $this->$offset; + } + + public function offsetSet($offset, $value) { + $this->$offset = $value; + } + + public function offsetUnset($offset) { + unset($this->$offset); + } +} diff --git a/samples/client/petstore/php/old/tests/PetApiTest.php b/samples/client/petstore/php/old/tests/PetApiTest.php new file mode 100644 index 00000000000..77413fd30d8 --- /dev/null +++ b/samples/client/petstore/php/old/tests/PetApiTest.php @@ -0,0 +1,19 @@ +getPetById($petId); + $this->assertSame($response->id, $petId); + } +} + +?> diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py index 5a96b4b6494..298ef2bedd8 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/pet_api.py @@ -33,7 +33,7 @@ class PetApi(object): - def updatePet(self, **kwargs): + def update_pet(self, **kwargs): """Update an existing pet Args: @@ -50,7 +50,7 @@ class PetApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method updatePet" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method update_pet" % key) params[key] = val del params['kwargs'] @@ -92,7 +92,7 @@ class PetApi(object): - def addPet(self, **kwargs): + def add_pet(self, **kwargs): """Add a new pet to the store Args: @@ -109,7 +109,7 @@ class PetApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method addPet" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method add_pet" % key) params[key] = val del params['kwargs'] @@ -151,7 +151,7 @@ class PetApi(object): - def findPetsByStatus(self, **kwargs): + def find_pets_by_status(self, **kwargs): """Finds Pets by status Args: @@ -168,7 +168,7 @@ class PetApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method findPetsByStatus" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method find_pets_by_status" % key) params[key] = val del params['kwargs'] @@ -216,7 +216,7 @@ class PetApi(object): - def findPetsByTags(self, **kwargs): + def find_pets_by_tags(self, **kwargs): """Finds Pets by tags Args: @@ -233,7 +233,7 @@ class PetApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method findPetsByTags" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method find_pets_by_tags" % key) params[key] = val del params['kwargs'] @@ -281,7 +281,7 @@ class PetApi(object): - def getPetById(self, **kwargs): + def get_pet_by_id(self, **kwargs): """Find pet by ID Args: @@ -298,7 +298,7 @@ class PetApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method getPetById" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method get_pet_by_id" % key) params[key] = val del params['kwargs'] @@ -349,7 +349,7 @@ class PetApi(object): - def updatePetWithForm(self, **kwargs): + def update_pet_with_form(self, **kwargs): """Updates a pet in the store with form data Args: @@ -372,7 +372,7 @@ class PetApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method updatePetWithForm" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method update_pet_with_form" % key) params[key] = val del params['kwargs'] @@ -423,7 +423,7 @@ class PetApi(object): - def deletePet(self, **kwargs): + def delete_pet(self, **kwargs): """Deletes a pet Args: @@ -443,7 +443,7 @@ class PetApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method deletePet" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method delete_pet" % key) params[key] = val del params['kwargs'] @@ -491,7 +491,7 @@ class PetApi(object): - def uploadFile(self, **kwargs): + def upload_file(self, **kwargs): """uploads an image Args: @@ -514,7 +514,7 @@ class PetApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method uploadFile" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method upload_file" % key) params[key] = val del params['kwargs'] diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py index 49010daf1ab..53f6db8ff54 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/store_api.py @@ -33,7 +33,7 @@ class StoreApi(object): - def getInventory(self, **kwargs): + def get_inventory(self, **kwargs): """Returns pet inventories by status Args: @@ -47,7 +47,7 @@ class StoreApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method getInventory" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method get_inventory" % key) params[key] = val del params['kwargs'] @@ -92,7 +92,7 @@ class StoreApi(object): - def placeOrder(self, **kwargs): + def place_order(self, **kwargs): """Place an order for a pet Args: @@ -109,7 +109,7 @@ class StoreApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method placeOrder" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method place_order" % key) params[key] = val del params['kwargs'] @@ -157,7 +157,7 @@ class StoreApi(object): - def getOrderById(self, **kwargs): + def get_order_by_id(self, **kwargs): """Find purchase order by ID Args: @@ -174,7 +174,7 @@ class StoreApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method getOrderById" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method get_order_by_id" % key) params[key] = val del params['kwargs'] @@ -225,7 +225,7 @@ class StoreApi(object): - def deleteOrder(self, **kwargs): + def delete_order(self, **kwargs): """Delete purchase order by ID Args: @@ -242,7 +242,7 @@ class StoreApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method deleteOrder" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method delete_order" % key) params[key] = val del params['kwargs'] diff --git a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py index 8d6f6670c6e..530912c38fe 100644 --- a/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py +++ b/samples/client/petstore/python/SwaggerPetstore-python/SwaggerPetstore/user_api.py @@ -33,7 +33,7 @@ class UserApi(object): - def createUser(self, **kwargs): + def create_user(self, **kwargs): """Create user Args: @@ -50,7 +50,7 @@ class UserApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method createUser" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method create_user" % key) params[key] = val del params['kwargs'] @@ -92,7 +92,7 @@ class UserApi(object): - def createUsersWithArrayInput(self, **kwargs): + def create_users_with_array_input(self, **kwargs): """Creates list of users with given input array Args: @@ -109,7 +109,7 @@ class UserApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method createUsersWithArrayInput" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method create_users_with_array_input" % key) params[key] = val del params['kwargs'] @@ -151,7 +151,7 @@ class UserApi(object): - def createUsersWithListInput(self, **kwargs): + def create_users_with_list_input(self, **kwargs): """Creates list of users with given input array Args: @@ -168,7 +168,7 @@ class UserApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method createUsersWithListInput" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method create_users_with_list_input" % key) params[key] = val del params['kwargs'] @@ -210,7 +210,7 @@ class UserApi(object): - def loginUser(self, **kwargs): + def login_user(self, **kwargs): """Logs user into the system Args: @@ -230,7 +230,7 @@ class UserApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method loginUser" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method login_user" % key) params[key] = val del params['kwargs'] @@ -281,7 +281,7 @@ class UserApi(object): - def logoutUser(self, **kwargs): + def logout_user(self, **kwargs): """Logs out current logged in user session Args: @@ -295,7 +295,7 @@ class UserApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method logoutUser" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method logout_user" % key) params[key] = val del params['kwargs'] @@ -334,7 +334,7 @@ class UserApi(object): - def getUserByName(self, **kwargs): + def get_user_by_name(self, **kwargs): """Get user by user name Args: @@ -351,7 +351,7 @@ class UserApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method getUserByName" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method get_user_by_name" % key) params[key] = val del params['kwargs'] @@ -402,7 +402,7 @@ class UserApi(object): - def updateUser(self, **kwargs): + def update_user(self, **kwargs): """Updated user Args: @@ -422,7 +422,7 @@ class UserApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method updateUser" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method update_user" % key) params[key] = val del params['kwargs'] @@ -470,7 +470,7 @@ class UserApi(object): - def deleteUser(self, **kwargs): + def delete_user(self, **kwargs): """Delete user Args: @@ -487,7 +487,7 @@ class UserApi(object): params = locals() for (key, val) in params['kwargs'].iteritems(): if key not in allParams: - raise TypeError("Got an unexpected keyword argument '%s' to method deleteUser" % key) + raise TypeError("Got an unexpected keyword argument '%s' to method delete_user" % key) params[key] = val del params['kwargs'] diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index d083df5f74d..6b032510c41 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -9,7 +9,7 @@ class PetApi # @param [Hash] opts the optional parameters # @option opts [Pet] :body Pet object that needs to be added to the store # @return void - def self.updatePet(opts = {}) + def self.update_pet(opts = {}) # verify existence of params # resource path @@ -61,7 +61,7 @@ class PetApi # @param [Hash] opts the optional parameters # @option opts [Pet] :body Pet object that needs to be added to the store # @return void - def self.addPet(opts = {}) + def self.add_pet(opts = {}) # verify existence of params # resource path @@ -113,7 +113,7 @@ class PetApi # @param [Hash] opts the optional parameters # @option opts [array[string]] :status Status values that need to be considered for filter # @return array[Pet] - def self.findPetsByStatus(opts = {}) + def self.find_pets_by_status(opts = {}) # verify existence of params # resource path @@ -147,7 +147,7 @@ class PetApi # @param [Hash] opts the optional parameters # @option opts [array[string]] :tags Tags to filter by # @return array[Pet] - def self.findPetsByTags(opts = {}) + def self.find_pets_by_tags(opts = {}) # verify existence of params # resource path @@ -181,7 +181,7 @@ class PetApi # @param pet_id ID of pet that needs to be fetched # @param [Hash] opts the optional parameters # @return Pet - def self.getPetById(pet_id, opts = {}) + def self.get_pet_by_id(pet_id, opts = {}) # verify existence of params raise "pet_id is required" if pet_id.nil? @@ -217,7 +217,7 @@ class PetApi # @option opts [string] :name Updated name of the pet # @option opts [string] :status Updated status of the pet # @return void - def self.updatePetWithForm(pet_id, opts = {}) + def self.update_pet_with_form(pet_id, opts = {}) # verify existence of params raise "pet_id is required" if pet_id.nil? @@ -253,7 +253,7 @@ class PetApi # @param [Hash] opts the optional parameters # @option opts [string] :api_key # @return void - def self.deletePet(pet_id, opts = {}) + def self.delete_pet(pet_id, opts = {}) # verify existence of params raise "pet_id is required" if pet_id.nil? @@ -289,7 +289,7 @@ class PetApi # @option opts [string] :additional_metadata Additional data to pass to server # @option opts [file] :file file to upload # @return void - def self.uploadFile(pet_id, opts = {}) + def self.upload_file(pet_id, opts = {}) # verify existence of params raise "pet_id is required" if pet_id.nil? diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index 757049a6fb6..6cd3296039b 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -8,7 +8,7 @@ class StoreApi # Returns a map of status codes to quantities # @param [Hash] opts the optional parameters # @return map[string,int] - def self.getInventory(opts = {}) + def self.get_inventory(opts = {}) # verify existence of params # resource path @@ -41,7 +41,7 @@ class StoreApi # @param [Hash] opts the optional parameters # @option opts [Order] :body order placed for purchasing the pet # @return Order - def self.placeOrder(opts = {}) + def self.place_order(opts = {}) # verify existence of params # resource path @@ -94,7 +94,7 @@ class StoreApi # @param order_id ID of pet that needs to be fetched # @param [Hash] opts the optional parameters # @return Order - def self.getOrderById(order_id, opts = {}) + def self.get_order_by_id(order_id, opts = {}) # verify existence of params raise "order_id is required" if order_id.nil? @@ -128,7 +128,7 @@ class StoreApi # @param order_id ID of the order that needs to be deleted # @param [Hash] opts the optional parameters # @return void - def self.deleteOrder(order_id, opts = {}) + def self.delete_order(order_id, opts = {}) # verify existence of params raise "order_id is required" if order_id.nil? diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 9d0e6bd6ce9..dead94897cd 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -9,7 +9,7 @@ class UserApi # @param [Hash] opts the optional parameters # @option opts [User] :body Created user object # @return void - def self.createUser(opts = {}) + def self.create_user(opts = {}) # verify existence of params # resource path @@ -61,7 +61,7 @@ class UserApi # @param [Hash] opts the optional parameters # @option opts [array[User]] :body List of user object # @return void - def self.createUsersWithArrayInput(opts = {}) + def self.create_users_with_array_input(opts = {}) # verify existence of params # resource path @@ -113,7 +113,7 @@ class UserApi # @param [Hash] opts the optional parameters # @option opts [array[User]] :body List of user object # @return void - def self.createUsersWithListInput(opts = {}) + def self.create_users_with_list_input(opts = {}) # verify existence of params # resource path @@ -166,7 +166,7 @@ class UserApi # @option opts [string] :username The user name for login # @option opts [string] :password The password for login in clear text # @return string - def self.loginUser(opts = {}) + def self.login_user(opts = {}) # verify existence of params # resource path @@ -200,7 +200,7 @@ class UserApi # # @param [Hash] opts the optional parameters # @return void - def self.logoutUser(opts = {}) + def self.logout_user(opts = {}) # verify existence of params # resource path @@ -232,7 +232,7 @@ class UserApi # @param username The name that needs to be fetched. Use user1 for testing. # @param [Hash] opts the optional parameters # @return User - def self.getUserByName(username, opts = {}) + def self.get_user_by_name(username, opts = {}) # verify existence of params raise "username is required" if username.nil? @@ -267,7 +267,7 @@ class UserApi # @param [Hash] opts the optional parameters # @option opts [User] :body Updated user object # @return void - def self.updateUser(username, opts = {}) + def self.update_user(username, opts = {}) # verify existence of params raise "username is required" if username.nil? @@ -320,7 +320,7 @@ class UserApi # @param username The name that needs to be deleted # @param [Hash] opts the optional parameters # @return void - def self.deleteUser(username, opts = {}) + def self.delete_user(username, opts = {}) # verify existence of params raise "username is required" if username.nil? diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index e3b42b78142..f0e38084802 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -8,24 +8,24 @@ describe "Pet" do describe "pet methods" do it "should fetch a pet object" do - pet = PetApi.getPetById(10002) + pet = PetApi.get_pet_by_id(10002) pet.should be_a(Pet) pet.id.should == 10002 pet.name.should == "RUBY UNIT TESTING" end it "should find pets by status" do - pets = PetApi.findPetsByStatus(:status => 'available') + pets = PetApi.find_pets_by_status('available') pets.length.should >= 3 end it "should not find a pet with invalid status" do - pets = PetApi.findPetsByStatus(:status => 'invalid-status') + pets = PetApi.find_pets_by_status('invalid-status') pets.length.should == 0 end it "should find a pet by status" do - pets = PetApi.findPetsByStatus(:status => "available,sold") + pets = PetApi.find_pets_by_status("available,sold") pets.map {|pet| if(pet.status != 'available' && pet.status != 'sold') raise "pet status wasn't right" @@ -35,18 +35,18 @@ describe "Pet" do it "should update a pet" do pet = Pet.new({'id' => 10002, 'status' => 'sold'}) - PetApi.addPet(:body => pet) + PetApi.add_pet(pet) - fetched = PetApi.getPetById(10002) + fetched = PetApi.get_pet_by_id(10002) fetched.id.should == 10002 fetched.status.should == 'sold' end it "should create a pet" do pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING") - PetApi.addPet(:body => pet) + PetApi.add_pet(pet) - pet = PetApi.getPetById(10002) + pet = PetApi.get_pet_by_id(10002) pet.id.should == 10002 pet.name.should == "RUBY UNIT TESTING" end diff --git a/samples/client/petstore/ruby/spec/spec_helper.rb b/samples/client/petstore/ruby/spec/spec_helper.rb index c0bcaffa9c7..c4c56d8a955 100644 --- a/samples/client/petstore/ruby/spec/spec_helper.rb +++ b/samples/client/petstore/ruby/spec/spec_helper.rb @@ -47,10 +47,10 @@ end # always delete and then re-create the pet object with 10002 def prepare_pet # remove the pet - PetApi.deletePet(10002, :api_key => 'special-key') + PetApi.delete_pet('special-key', 10002) # recreate the pet pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING") - PetApi.addPet(:body => pet) + PetApi.add_pet(pet) end # always delete and then re-create the store order @@ -61,7 +61,7 @@ def prepare_store "shipDate" => "2015-04-06T23:42:01.678Z", "status" => "placed", "complete" => false) - StoreApi.placeOrder(:body => order) + StoreApi.place_order(order) end configure_swagger diff --git a/samples/client/petstore/ruby/spec/store_spec.rb b/samples/client/petstore/ruby/spec/store_spec.rb index 961aac05f06..a1e2bd3193f 100644 --- a/samples/client/petstore/ruby/spec/store_spec.rb +++ b/samples/client/petstore/ruby/spec/store_spec.rb @@ -7,7 +7,7 @@ describe "Store" do end it "should fetch an order" do - item = StoreApi.getOrderById(10002) + item = StoreApi.get_order_by_id(10002) item.id.should == 10002 end end diff --git a/samples/html/index.html b/samples/html/index.html index 1055c9962ad..bab16472c30 100644 --- a/samples/html/index.html +++ b/samples/html/index.html @@ -420,7 +420,7 @@

Example data

Content-Type: application/xml
-
not implemented com.wordnik.swagger.models.properties.MapProperty@2acca551
+
not implemented com.wordnik.swagger.models.properties.MapProperty@3c536f11

@@ -444,11 +444,11 @@

Example data

Content-Type: application/json
-
{\n  "id" : 123456789,\n  "petId" : 123456789,\n  "complete" : true,\n  "status" : "aeiou",\n  "quantity" : 123,\n  "shipDate" : "2015-04-05T03:02:18.855+0000"\n}
+
{\n  "id" : 123456789,\n  "petId" : 123456789,\n  "complete" : true,\n  "status" : "aeiou",\n  "quantity" : 123,\n  "shipDate" : "2015-04-16T14:41:29.883+0000"\n}

Example data

Content-Type: application/xml
-
\n  123456\n  123456\n  0\n  2015-04-04T20:02:18.857Z\n  string\n  true\n
+
\n  123456\n  123456\n  0\n  2015-04-16T22:41:29.886Z\n  string\n  true\n

@@ -472,11 +472,11 @@

Example data

Content-Type: application/json
-
{\n  "id" : 123456789,\n  "petId" : 123456789,\n  "complete" : true,\n  "status" : "aeiou",\n  "quantity" : 123,\n  "shipDate" : "2015-04-05T03:02:18.859+0000"\n}
+
{\n  "id" : 123456789,\n  "petId" : 123456789,\n  "complete" : true,\n  "status" : "aeiou",\n  "quantity" : 123,\n  "shipDate" : "2015-04-16T14:41:29.887+0000"\n}

Example data

Content-Type: application/xml
-
\n  123456\n  123456\n  0\n  2015-04-04T20:02:18.859Z\n  string\n  true\n
+
\n  123456\n  123456\n  0\n  2015-04-16T22:41:29.888Z\n  string\n  true\n

From 4c717829b340538510716412a1cf2d876095e4df Mon Sep 17 00:00:00 2001 From: wing328 Date: Thu, 16 Apr 2015 23:54:55 +0800 Subject: [PATCH 2/5] update test.php, remove old SwaggerPetstore-php --- .../php/SwaggerPetstore-php/README.md | 52 -- .../SwaggerPetstore-php/SwaggerPetstore.php | 16 - .../php/SwaggerPetstore-php/composer.json | 32 -- .../php/SwaggerPetstore-php/lib/APIClient.php | 304 ----------- .../lib/APIClientException.php | 38 -- .../php/SwaggerPetstore-php/lib/PetApi.php | 493 ------------------ .../php/SwaggerPetstore-php/lib/StoreApi.php | 258 --------- .../php/SwaggerPetstore-php/lib/UserApi.php | 472 ----------------- .../lib/models/Category.php | 64 --- .../SwaggerPetstore-php/lib/models/Order.php | 83 --- .../SwaggerPetstore-php/lib/models/Pet.php | 83 --- .../SwaggerPetstore-php/lib/models/Tag.php | 64 --- .../SwaggerPetstore-php/lib/models/User.php | 91 ---- .../SwaggerPetstore-php/tests/PetApiTest.php | 19 - samples/client/petstore/php/old/README.md | 52 -- .../petstore/php/old/SwaggerPetstore.php | 16 - samples/client/petstore/php/old/composer.json | 32 -- .../client/petstore/php/old/lib/APIClient.php | 304 ----------- .../php/old/lib/APIClientException.php | 38 -- .../client/petstore/php/old/lib/PetApi.php | 493 ------------------ .../client/petstore/php/old/lib/StoreApi.php | 258 --------- .../client/petstore/php/old/lib/UserApi.php | 472 ----------------- .../petstore/php/old/lib/models/Category.php | 64 --- .../petstore/php/old/lib/models/Order.php | 83 --- .../petstore/php/old/lib/models/Pet.php | 83 --- .../petstore/php/old/lib/models/Tag.php | 64 --- .../petstore/php/old/lib/models/User.php | 91 ---- .../petstore/php/old/tests/PetApiTest.php | 19 - samples/client/petstore/php/test.php | 8 +- 29 files changed, 4 insertions(+), 4142 deletions(-) delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/README.md delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/SwaggerPetstore.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/composer.json delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/APIClient.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/APIClientException.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/PetApi.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/StoreApi.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/UserApi.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/models/Category.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/models/Order.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/models/Pet.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/models/Tag.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/lib/models/User.php delete mode 100644 samples/client/petstore/php/SwaggerPetstore-php/tests/PetApiTest.php delete mode 100644 samples/client/petstore/php/old/README.md delete mode 100644 samples/client/petstore/php/old/SwaggerPetstore.php delete mode 100644 samples/client/petstore/php/old/composer.json delete mode 100644 samples/client/petstore/php/old/lib/APIClient.php delete mode 100644 samples/client/petstore/php/old/lib/APIClientException.php delete mode 100644 samples/client/petstore/php/old/lib/PetApi.php delete mode 100644 samples/client/petstore/php/old/lib/StoreApi.php delete mode 100644 samples/client/petstore/php/old/lib/UserApi.php delete mode 100644 samples/client/petstore/php/old/lib/models/Category.php delete mode 100644 samples/client/petstore/php/old/lib/models/Order.php delete mode 100644 samples/client/petstore/php/old/lib/models/Pet.php delete mode 100644 samples/client/petstore/php/old/lib/models/Tag.php delete mode 100644 samples/client/petstore/php/old/lib/models/User.php delete mode 100644 samples/client/petstore/php/old/tests/PetApiTest.php diff --git a/samples/client/petstore/php/SwaggerPetstore-php/README.md b/samples/client/petstore/php/SwaggerPetstore-php/README.md deleted file mode 100644 index 6dfd19a292a..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/README.md +++ /dev/null @@ -1,52 +0,0 @@ -## Requirements - -PHP 5.3.3 and later. - -## Composer - -You can install the bindings via [Composer](http://getcomposer.org/). Add this to your `composer.json`: - - { - "repositories": [ - { - "type": "git", - "url": "https://github.com/wing328/SwaggerPetstore-php.git" - } - ], - "require": { - "SwaggerPetstore/SwaggerPetstore-php": "*@dev" - } - } - -Then install via: - - composer install - -To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/00-intro.md#autoloading): - - require_once('vendor/autoload.php'); - -## Manual Installation - -If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the `SwaggerPetstore.php` file. - - require_once('/path/to/SwaggerPetstore-php/SwaggerPetstore.php'); - -## Getting Started - -php test.php - -## Documentation - -TODO - -## Tests - -In order to run tests first install [PHPUnit](http://packagist.org/packages/phpunit/phpunit) via [Composer](http://getcomposer.org/): - - composer update - -To run the test suite: - - ./vendor/bin/phpunit tests - diff --git a/samples/client/petstore/php/SwaggerPetstore-php/SwaggerPetstore.php b/samples/client/petstore/php/SwaggerPetstore-php/SwaggerPetstore.php deleted file mode 100644 index 058aa169504..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/SwaggerPetstore.php +++ /dev/null @@ -1,16 +0,0 @@ - diff --git a/samples/client/petstore/php/SwaggerPetstore-php/composer.json b/samples/client/petstore/php/SwaggerPetstore-php/composer.json deleted file mode 100644 index 7109d7a8790..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/composer.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "SwaggerPetstore/SwaggerPetstore-php", - "description": "", - "keywords": [ - "swagger", - "php", - "sdk", - "api" - ], - "homepage": "http://swagger.io", - "license": "Apache v2", - "authors": [ - { - "name": "Swagger and contributors", - "homepage": "https://github.com/swagger-api/swagger-codegen" - } - ], - "require": { - "php": ">=5.3.3", - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*" - }, - "require-dev": { - "phpunit/phpunit": "~4.0", - "satooshi/php-coveralls": "~0.6.1", - "squizlabs/php_codesniffer": "~2.0" - }, - "autoload": { - "psr-4": { "SwaggerPetstore\\" : "lib/" } - } -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/APIClient.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/APIClient.php deleted file mode 100644 index 681bb8cee3c..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/APIClient.php +++ /dev/null @@ -1,304 +0,0 @@ -host = $host; - $this->headerName = $headerName; - $this->headerValue = $headerValue; - } - - /** - * Set the user agent of the API client - * - * @param string $user_agent The user agent of the API client - */ - public function setUserAgent($user_agent) { - if (!is_string($user_agent)) { - throw new Exception('User-agent must be a string.'); - } - $this->user_agent= $user_agent; - } - - /** - * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] - */ - public function setTimeout($seconds) { - if (!is_numeric($seconds)) { - throw new Exception('Timeout variable must be numeric.'); - } - $this->curl_timeout = $seconds; - } - - /** - * @param string $resourcePath path to method endpoint - * @param string $method method to call - * @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 mixed - */ - public function callAPI($resourcePath, $method, $queryParams, $postData, - $headerParams) { - - $headers = array(); - - # Allow API key from $headerParams to override default - $added_api_key = False; - if ($headerParams != null) { - foreach ($headerParams as $key => $val) { - $headers[] = "$key: $val"; - if ($key == $this->headerName) { - $added_api_key = True; - } - } - } - if (! $added_api_key && $this->headerName != null) { - $headers[] = $this->headerName . ": " . $this->headerValue; - } - - if ((isset($headers['Content-Type']) and strpos($headers['Content-Type'], "multipart/form-data") < 0) and (is_object($postData) or is_array($postData))) { - $postData = json_encode($this->sanitizeForSerialization($postData)); - } - - $url = $this->host . $resourcePath; - - $curl = curl_init(); - // set timeout, if needed - if ($this->curl_timeout != 0) { - curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout); - } - // return the result on success, rather than just TRUE - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - if (! empty($queryParams)) { - $url = ($url . '?' . http_build_query($queryParams)); - } - - if ($method == self::$POST) { - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { - throw new Exception('Method ' . $method . ' is not recognized.'); - } - curl_setopt($curl, CURLOPT_URL, $url); - - // Set user agent - curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); - - // Make the request - $response = curl_exec($curl); - $response_info = curl_getinfo($curl); - - // Handle the response - if ($response_info['http_code'] == 0) { - throw new APIClientException("TIMEOUT: api call to " . $url . - " took more than 5s to return", 0, $response_info, $response); - } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { - $data = json_decode($response); - if (json_last_error() > 0) { // if response is a string - $data = $response; - } - } else if ($response_info['http_code'] == 401) { - throw new APIClientException("Unauthorized API request to " . $url . - ": " . serialize($response), 0, $response_info, $response); - } else if ($response_info['http_code'] == 404) { - $data = null; - } else { - throw new APIClientException("Can't connect to the api: " . $url . - " response code: " . - $response_info['http_code'], 0, $response_info, $response); - } - return $data; - } - - /** - * Build a JSON POST object - */ - 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[$data::$attributeMap[$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 - * the path, by url-encoding. - * @param string $value a string which will be part of the path - * @return string the serialized object - */ - public static function toPathValue($value) { - return rawurlencode(self::toString($value)); - } - - /** - * Take value and turn it into a string suitable for inclusion in - * the query, by imploding comma-separated if it's an object. - * If it's a string, pass through unchanged. It will be url-encoded - * later. - * @param object $object an object to be serialized to a string - * @return string the serialized object - */ - public static function toQueryValue($object) { - if (is_array($object)) { - return implode(',', $object); - } else { - return self::toString($object); - } - } - - /** - * Take value and turn it into a string suitable for inclusion in - * the header. If it's a string, pass through unchanged - * If it's a datetime object, format it in ISO8601 - * @param string $value a string which will be part of the header - * @return string the header string - */ - public static function toHeaderValue($value) { - return self::toString($value); - } - - /** - * Take value and turn it into a string suitable for inclusion in - * the http body (form parameter). If it's a string, pass through unchanged - * If it's a datetime object, format it in ISO8601 - * @param string $value the value of the form parameter - * @return string the form string - */ - public static function toFormValue($value) { - return self::toString($value); - } - - /** - * Take value and turn it into a string suitable for inclusion in - * the parameter. If it's a string, pass through unchanged - * If it's a datetime object, format it in ISO8601 - * @param string $value the value of the parameter - * @return string the header string - */ - public static function toString($value) { - if ($value instanceof \DateTime) { // datetime in ISO8601 format - return $value->format(\DateTime::ISO8601); - } - else { - 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($data, $class) - { - if (null === $data) { - $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { - $inner = substr($class, 4, -1); - $values = array(); - if(strrpos($inner, ",") !== false) { - $subClass_array = explode(',', $inner, 2); - $subClass = $subClass_array[1]; - foreach ($data as $key => $value) { - $values[] = array($key => self::deserialize($value, $subClass)); - } - } - $deserialized = $values; - } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { - $subClass = substr($class, 6, -1); - $values = array(); - foreach ($data as $key => $value) { - $values[] = self::deserialize($value, $subClass); - } - $deserialized = $values; - } elseif ($class == 'DateTime') { - $deserialized = new \DateTime($data); - } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool'))) { - settype($data, $class); - $deserialized = $data; - } else { - $class = "SwaggerPetstore\\models\\".$class; - $instance = new $class(); - foreach ($instance::$swaggerTypes as $property => $type) { - if (isset($data->$property)) { - $original_property_name = $instance::$attributeMap[$property]; - $instance->$property = self::deserialize($data->$original_property_name, $type); - } - } - $deserialized = $instance; - } - - return $deserialized; - } - -} - diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/APIClientException.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/APIClientException.php deleted file mode 100644 index 8f083caf6f9..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/APIClientException.php +++ /dev/null @@ -1,38 +0,0 @@ -response_info = $response_info; - $this->response = $response; - } - - public function getResponse() { - return $this->response; - } - - public function getResponseInfo() { - return $this->response_info; - } -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/PetApi.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/PetApi.php deleted file mode 100644 index 1b31db8915d..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/PetApi.php +++ /dev/null @@ -1,493 +0,0 @@ -apiClient = $apiClient; - } - - - /** - * updatePet - * - * Update an existing pet - * - * @param Pet $body Pet object that needs to be added to the store (required) - * @return void - */ - public function updatePet($body) { - - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array('application/json','application/xml',); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * addPet - * - * Add a new pet to the store - * - * @param Pet $body Pet object that needs to be added to the store (required) - * @return void - */ - public function addPet($body) { - - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array('application/json','application/xml',); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * findPetsByStatus - * - * Finds Pets by status - * - * @param array[string] $status Status values that need to be considered for filter (required) - * @return array[Pet] - */ - public function findPetsByStatus($status) { - - // parse inputs - $resourcePath = "/pet/findByStatus"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - // query params - if($status !== null) { - $queryParams['status'] = $this->apiClient->toQueryValue($status); - } - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'array[Pet]'); - return $responseObject; - } - - /** - * findPetsByTags - * - * Finds Pets by tags - * - * @param array[string] $tags Tags to filter by (required) - * @return array[Pet] - */ - public function findPetsByTags($tags) { - - // parse inputs - $resourcePath = "/pet/findByTags"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - // query params - if($tags !== null) { - $queryParams['tags'] = $this->apiClient->toQueryValue($tags); - } - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'array[Pet]'); - return $responseObject; - } - - /** - * getPetById - * - * Find pet by ID - * - * @param int $pet_id ID of pet that needs to be fetched (required) - * @return Pet - */ - public function getPetById($pet_id) { - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'Pet'); - return $responseObject; - } - - /** - * updatePetWithForm - * - * Updates a pet in the store with form data - * - * @param string $pet_id ID of pet that needs to be updated (required) - * @param string $name Updated name of the pet (required) - * @param string $status Updated status of the pet (required) - * @return void - */ - public function updatePetWithForm($pet_id, $name, $status) { - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array('application/x-www-form-urlencoded',); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - // form params - if ($name !== null) { - $formParams['name'] = $this->apiClient->toFormValue($name); - }// form params - if ($status !== null) { - $formParams['status'] = $this->apiClient->toFormValue($status); - } - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * deletePet - * - * Deletes a pet - * - * @param string $api_key (required) - * @param int $pet_id Pet id to delete (required) - * @return void - */ - public function deletePet($api_key, $pet_id) { - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - // header params - if($api_key !== null) { - $headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key); - } - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * uploadFile - * - * uploads an image - * - * @param int $pet_id ID of pet to update (required) - * @param string $additional_metadata Additional data to pass to server (required) - * @param file $file file to upload (required) - * @return void - */ - public function uploadFile($pet_id, $additional_metadata, $file) { - - // parse inputs - $resourcePath = "/pet/{petId}/uploadImage"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array('multipart/form-data',); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - // form params - if ($additional_metadata !== null) { - $formParams['additionalMetadata'] = $this->apiClient->toFormValue($additional_metadata); - }// form params - if ($file !== null) { - $formParams['file'] = '@' . $this->apiClient->toFormValue($file); - } - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/StoreApi.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/StoreApi.php deleted file mode 100644 index 83a3f0520fa..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/StoreApi.php +++ /dev/null @@ -1,258 +0,0 @@ -apiClient = $apiClient; - } - - - /** - * getInventory - * - * Returns pet inventories by status - * - * @return map[string,int] - */ - public function getInventory() { - - // parse inputs - $resourcePath = "/store/inventory"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'map[string,int]'); - return $responseObject; - } - - /** - * placeOrder - * - * Place an order for a pet - * - * @param Order $body order placed for purchasing the pet (required) - * @return Order - */ - public function placeOrder($body) { - - // parse inputs - $resourcePath = "/store/order"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'Order'); - return $responseObject; - } - - /** - * getOrderById - * - * Find purchase order by ID - * - * @param string $order_id ID of pet that needs to be fetched (required) - * @return Order - */ - public function getOrderById($order_id) { - - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->toPathValue($order_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'Order'); - return $responseObject; - } - - /** - * deleteOrder - * - * Delete purchase order by ID - * - * @param string $order_id ID of the order that needs to be deleted (required) - * @return void - */ - public function deleteOrder($order_id) { - - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->toPathValue($order_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/UserApi.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/UserApi.php deleted file mode 100644 index d55b430d7a1..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/UserApi.php +++ /dev/null @@ -1,472 +0,0 @@ -apiClient = $apiClient; - } - - - /** - * createUser - * - * Create user - * - * @param User $body Created user object (required) - * @return void - */ - public function createUser($body) { - - // parse inputs - $resourcePath = "/user"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * createUsersWithArrayInput - * - * Creates list of users with given input array - * - * @param array[User] $body List of user object (required) - * @return void - */ - public function createUsersWithArrayInput($body) { - - // parse inputs - $resourcePath = "/user/createWithArray"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * createUsersWithListInput - * - * Creates list of users with given input array - * - * @param array[User] $body List of user object (required) - * @return void - */ - public function createUsersWithListInput($body) { - - // parse inputs - $resourcePath = "/user/createWithList"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * loginUser - * - * Logs user into the system - * - * @param string $username The user name for login (required) - * @param string $password The password for login in clear text (required) - * @return string - */ - public function loginUser($username, $password) { - - // parse inputs - $resourcePath = "/user/login"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - // query params - if($username !== null) { - $queryParams['username'] = $this->apiClient->toQueryValue($username); - }// query params - if($password !== null) { - $queryParams['password'] = $this->apiClient->toQueryValue($password); - } - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'string'); - return $responseObject; - } - - /** - * logoutUser - * - * Logs out current logged in user session - * - * @return void - */ - public function logoutUser() { - - // parse inputs - $resourcePath = "/user/logout"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * getUserByName - * - * Get user by user name - * - * @param string $username The name that needs to be fetched. Use user1 for testing. (required) - * @return User - */ - public function getUserByName($username) { - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'User'); - return $responseObject; - } - - /** - * updateUser - * - * Updated user - * - * @param string $username name that need to be deleted (required) - * @param User $body Updated user object (required) - * @return void - */ - public function updateUser($username, $body) { - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * deleteUser - * - * Delete user - * - * @param string $username The name that needs to be deleted (required) - * @return void - */ - public function deleteUser($username) { - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Category.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Category.php deleted file mode 100644 index 101222b4503..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Category.php +++ /dev/null @@ -1,64 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Order.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Order.php deleted file mode 100644 index 87e8c812eb7..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Order.php +++ /dev/null @@ -1,83 +0,0 @@ - 'int', - 'pet_id' => 'int', - 'quantity' => 'int', - 'ship_date' => 'DateTime', - 'status' => 'string', - 'complete' => 'boolean' - ); - - static $attributeMap = array( - 'id' => 'id', - 'pet_id' => 'petId', - 'quantity' => 'quantity', - 'ship_date' => 'shipDate', - 'status' => 'status', - 'complete' => 'complete' - ); - - - public $id; /* int */ - public $pet_id; /* int */ - public $quantity; /* int */ - public $ship_date; /* DateTime */ - /** - * Order Status - */ - public $status; /* string */ - public $complete; /* boolean */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->pet_id = $data["pet_id"]; - $this->quantity = $data["quantity"]; - $this->ship_date = $data["ship_date"]; - $this->status = $data["status"]; - $this->complete = $data["complete"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Pet.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Pet.php deleted file mode 100644 index eb67904bf13..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Pet.php +++ /dev/null @@ -1,83 +0,0 @@ - 'int', - 'category' => 'Category', - 'name' => 'string', - 'photo_urls' => 'array[string]', - 'tags' => 'array[Tag]', - 'status' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'category' => 'category', - 'name' => 'name', - 'photo_urls' => 'photoUrls', - 'tags' => 'tags', - 'status' => 'status' - ); - - - public $id; /* int */ - public $category; /* Category */ - public $name; /* string */ - public $photo_urls; /* array[string] */ - public $tags; /* array[Tag] */ - /** - * pet status in the store - */ - public $status; /* string */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->category = $data["category"]; - $this->name = $data["name"]; - $this->photo_urls = $data["photo_urls"]; - $this->tags = $data["tags"]; - $this->status = $data["status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Tag.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Tag.php deleted file mode 100644 index a9982317ece..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/Tag.php +++ /dev/null @@ -1,64 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/User.php b/samples/client/petstore/php/SwaggerPetstore-php/lib/models/User.php deleted file mode 100644 index 8662f937bc8..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/lib/models/User.php +++ /dev/null @@ -1,91 +0,0 @@ - 'int', - 'username' => 'string', - 'first_name' => 'string', - 'last_name' => 'string', - 'email' => 'string', - 'password' => 'string', - 'phone' => 'string', - 'user_status' => 'int' - ); - - static $attributeMap = array( - 'id' => 'id', - 'username' => 'username', - 'first_name' => 'firstName', - 'last_name' => 'lastName', - 'email' => 'email', - 'password' => 'password', - 'phone' => 'phone', - 'user_status' => 'userStatus' - ); - - - public $id; /* int */ - public $username; /* string */ - public $first_name; /* string */ - public $last_name; /* string */ - public $email; /* string */ - public $password; /* string */ - public $phone; /* string */ - /** - * User Status - */ - public $user_status; /* int */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->username = $data["username"]; - $this->first_name = $data["first_name"]; - $this->last_name = $data["last_name"]; - $this->email = $data["email"]; - $this->password = $data["password"]; - $this->phone = $data["phone"]; - $this->user_status = $data["user_status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/SwaggerPetstore-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerPetstore-php/tests/PetApiTest.php deleted file mode 100644 index 77413fd30d8..00000000000 --- a/samples/client/petstore/php/SwaggerPetstore-php/tests/PetApiTest.php +++ /dev/null @@ -1,19 +0,0 @@ -getPetById($petId); - $this->assertSame($response->id, $petId); - } -} - -?> diff --git a/samples/client/petstore/php/old/README.md b/samples/client/petstore/php/old/README.md deleted file mode 100644 index 6dfd19a292a..00000000000 --- a/samples/client/petstore/php/old/README.md +++ /dev/null @@ -1,52 +0,0 @@ -## Requirements - -PHP 5.3.3 and later. - -## Composer - -You can install the bindings via [Composer](http://getcomposer.org/). Add this to your `composer.json`: - - { - "repositories": [ - { - "type": "git", - "url": "https://github.com/wing328/SwaggerPetstore-php.git" - } - ], - "require": { - "SwaggerPetstore/SwaggerPetstore-php": "*@dev" - } - } - -Then install via: - - composer install - -To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/00-intro.md#autoloading): - - require_once('vendor/autoload.php'); - -## Manual Installation - -If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the `SwaggerPetstore.php` file. - - require_once('/path/to/SwaggerPetstore-php/SwaggerPetstore.php'); - -## Getting Started - -php test.php - -## Documentation - -TODO - -## Tests - -In order to run tests first install [PHPUnit](http://packagist.org/packages/phpunit/phpunit) via [Composer](http://getcomposer.org/): - - composer update - -To run the test suite: - - ./vendor/bin/phpunit tests - diff --git a/samples/client/petstore/php/old/SwaggerPetstore.php b/samples/client/petstore/php/old/SwaggerPetstore.php deleted file mode 100644 index 058aa169504..00000000000 --- a/samples/client/petstore/php/old/SwaggerPetstore.php +++ /dev/null @@ -1,16 +0,0 @@ - diff --git a/samples/client/petstore/php/old/composer.json b/samples/client/petstore/php/old/composer.json deleted file mode 100644 index 7109d7a8790..00000000000 --- a/samples/client/petstore/php/old/composer.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "SwaggerPetstore/SwaggerPetstore-php", - "description": "", - "keywords": [ - "swagger", - "php", - "sdk", - "api" - ], - "homepage": "http://swagger.io", - "license": "Apache v2", - "authors": [ - { - "name": "Swagger and contributors", - "homepage": "https://github.com/swagger-api/swagger-codegen" - } - ], - "require": { - "php": ">=5.3.3", - "ext-curl": "*", - "ext-json": "*", - "ext-mbstring": "*" - }, - "require-dev": { - "phpunit/phpunit": "~4.0", - "satooshi/php-coveralls": "~0.6.1", - "squizlabs/php_codesniffer": "~2.0" - }, - "autoload": { - "psr-4": { "SwaggerPetstore\\" : "lib/" } - } -} diff --git a/samples/client/petstore/php/old/lib/APIClient.php b/samples/client/petstore/php/old/lib/APIClient.php deleted file mode 100644 index 681bb8cee3c..00000000000 --- a/samples/client/petstore/php/old/lib/APIClient.php +++ /dev/null @@ -1,304 +0,0 @@ -host = $host; - $this->headerName = $headerName; - $this->headerValue = $headerValue; - } - - /** - * Set the user agent of the API client - * - * @param string $user_agent The user agent of the API client - */ - public function setUserAgent($user_agent) { - if (!is_string($user_agent)) { - throw new Exception('User-agent must be a string.'); - } - $this->user_agent= $user_agent; - } - - /** - * @param integer $seconds Number of seconds before timing out [set to 0 for no timeout] - */ - public function setTimeout($seconds) { - if (!is_numeric($seconds)) { - throw new Exception('Timeout variable must be numeric.'); - } - $this->curl_timeout = $seconds; - } - - /** - * @param string $resourcePath path to method endpoint - * @param string $method method to call - * @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 mixed - */ - public function callAPI($resourcePath, $method, $queryParams, $postData, - $headerParams) { - - $headers = array(); - - # Allow API key from $headerParams to override default - $added_api_key = False; - if ($headerParams != null) { - foreach ($headerParams as $key => $val) { - $headers[] = "$key: $val"; - if ($key == $this->headerName) { - $added_api_key = True; - } - } - } - if (! $added_api_key && $this->headerName != null) { - $headers[] = $this->headerName . ": " . $this->headerValue; - } - - if ((isset($headers['Content-Type']) and strpos($headers['Content-Type'], "multipart/form-data") < 0) and (is_object($postData) or is_array($postData))) { - $postData = json_encode($this->sanitizeForSerialization($postData)); - } - - $url = $this->host . $resourcePath; - - $curl = curl_init(); - // set timeout, if needed - if ($this->curl_timeout != 0) { - curl_setopt($curl, CURLOPT_TIMEOUT, $this->curl_timeout); - } - // return the result on success, rather than just TRUE - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - - if (! empty($queryParams)) { - $url = ($url . '?' . http_build_query($queryParams)); - } - - if ($method == self::$POST) { - curl_setopt($curl, CURLOPT_POST, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PATCH) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$PUT) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method == self::$DELETE) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - } else if ($method != self::$GET) { - throw new Exception('Method ' . $method . ' is not recognized.'); - } - curl_setopt($curl, CURLOPT_URL, $url); - - // Set user agent - curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent); - - // Make the request - $response = curl_exec($curl); - $response_info = curl_getinfo($curl); - - // Handle the response - if ($response_info['http_code'] == 0) { - throw new APIClientException("TIMEOUT: api call to " . $url . - " took more than 5s to return", 0, $response_info, $response); - } else if ($response_info['http_code'] >= 200 && $response_info['http_code'] <= 299 ) { - $data = json_decode($response); - if (json_last_error() > 0) { // if response is a string - $data = $response; - } - } else if ($response_info['http_code'] == 401) { - throw new APIClientException("Unauthorized API request to " . $url . - ": " . serialize($response), 0, $response_info, $response); - } else if ($response_info['http_code'] == 404) { - $data = null; - } else { - throw new APIClientException("Can't connect to the api: " . $url . - " response code: " . - $response_info['http_code'], 0, $response_info, $response); - } - return $data; - } - - /** - * Build a JSON POST object - */ - 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[$data::$attributeMap[$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 - * the path, by url-encoding. - * @param string $value a string which will be part of the path - * @return string the serialized object - */ - public static function toPathValue($value) { - return rawurlencode(self::toString($value)); - } - - /** - * Take value and turn it into a string suitable for inclusion in - * the query, by imploding comma-separated if it's an object. - * If it's a string, pass through unchanged. It will be url-encoded - * later. - * @param object $object an object to be serialized to a string - * @return string the serialized object - */ - public static function toQueryValue($object) { - if (is_array($object)) { - return implode(',', $object); - } else { - return self::toString($object); - } - } - - /** - * Take value and turn it into a string suitable for inclusion in - * the header. If it's a string, pass through unchanged - * If it's a datetime object, format it in ISO8601 - * @param string $value a string which will be part of the header - * @return string the header string - */ - public static function toHeaderValue($value) { - return self::toString($value); - } - - /** - * Take value and turn it into a string suitable for inclusion in - * the http body (form parameter). If it's a string, pass through unchanged - * If it's a datetime object, format it in ISO8601 - * @param string $value the value of the form parameter - * @return string the form string - */ - public static function toFormValue($value) { - return self::toString($value); - } - - /** - * Take value and turn it into a string suitable for inclusion in - * the parameter. If it's a string, pass through unchanged - * If it's a datetime object, format it in ISO8601 - * @param string $value the value of the parameter - * @return string the header string - */ - public static function toString($value) { - if ($value instanceof \DateTime) { // datetime in ISO8601 format - return $value->format(\DateTime::ISO8601); - } - else { - 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($data, $class) - { - if (null === $data) { - $deserialized = null; - } elseif (substr($class, 0, 4) == 'map[') { - $inner = substr($class, 4, -1); - $values = array(); - if(strrpos($inner, ",") !== false) { - $subClass_array = explode(',', $inner, 2); - $subClass = $subClass_array[1]; - foreach ($data as $key => $value) { - $values[] = array($key => self::deserialize($value, $subClass)); - } - } - $deserialized = $values; - } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { - $subClass = substr($class, 6, -1); - $values = array(); - foreach ($data as $key => $value) { - $values[] = self::deserialize($value, $subClass); - } - $deserialized = $values; - } elseif ($class == 'DateTime') { - $deserialized = new \DateTime($data); - } elseif (in_array($class, array('string', 'int', 'float', 'double', 'bool'))) { - settype($data, $class); - $deserialized = $data; - } else { - $class = "SwaggerPetstore\\models\\".$class; - $instance = new $class(); - foreach ($instance::$swaggerTypes as $property => $type) { - if (isset($data->$property)) { - $original_property_name = $instance::$attributeMap[$property]; - $instance->$property = self::deserialize($data->$original_property_name, $type); - } - } - $deserialized = $instance; - } - - return $deserialized; - } - -} - diff --git a/samples/client/petstore/php/old/lib/APIClientException.php b/samples/client/petstore/php/old/lib/APIClientException.php deleted file mode 100644 index 8f083caf6f9..00000000000 --- a/samples/client/petstore/php/old/lib/APIClientException.php +++ /dev/null @@ -1,38 +0,0 @@ -response_info = $response_info; - $this->response = $response; - } - - public function getResponse() { - return $this->response; - } - - public function getResponseInfo() { - return $this->response_info; - } -} diff --git a/samples/client/petstore/php/old/lib/PetApi.php b/samples/client/petstore/php/old/lib/PetApi.php deleted file mode 100644 index 1b31db8915d..00000000000 --- a/samples/client/petstore/php/old/lib/PetApi.php +++ /dev/null @@ -1,493 +0,0 @@ -apiClient = $apiClient; - } - - - /** - * updatePet - * - * Update an existing pet - * - * @param Pet $body Pet object that needs to be added to the store (required) - * @return void - */ - public function updatePet($body) { - - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array('application/json','application/xml',); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * addPet - * - * Add a new pet to the store - * - * @param Pet $body Pet object that needs to be added to the store (required) - * @return void - */ - public function addPet($body) { - - // parse inputs - $resourcePath = "/pet"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array('application/json','application/xml',); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * findPetsByStatus - * - * Finds Pets by status - * - * @param array[string] $status Status values that need to be considered for filter (required) - * @return array[Pet] - */ - public function findPetsByStatus($status) { - - // parse inputs - $resourcePath = "/pet/findByStatus"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - // query params - if($status !== null) { - $queryParams['status'] = $this->apiClient->toQueryValue($status); - } - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'array[Pet]'); - return $responseObject; - } - - /** - * findPetsByTags - * - * Finds Pets by tags - * - * @param array[string] $tags Tags to filter by (required) - * @return array[Pet] - */ - public function findPetsByTags($tags) { - - // parse inputs - $resourcePath = "/pet/findByTags"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - // query params - if($tags !== null) { - $queryParams['tags'] = $this->apiClient->toQueryValue($tags); - } - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'array[Pet]'); - return $responseObject; - } - - /** - * getPetById - * - * Find pet by ID - * - * @param int $pet_id ID of pet that needs to be fetched (required) - * @return Pet - */ - public function getPetById($pet_id) { - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'Pet'); - return $responseObject; - } - - /** - * updatePetWithForm - * - * Updates a pet in the store with form data - * - * @param string $pet_id ID of pet that needs to be updated (required) - * @param string $name Updated name of the pet (required) - * @param string $status Updated status of the pet (required) - * @return void - */ - public function updatePetWithForm($pet_id, $name, $status) { - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array('application/x-www-form-urlencoded',); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - // form params - if ($name !== null) { - $formParams['name'] = $this->apiClient->toFormValue($name); - }// form params - if ($status !== null) { - $formParams['status'] = $this->apiClient->toFormValue($status); - } - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * deletePet - * - * Deletes a pet - * - * @param string $api_key (required) - * @param int $pet_id Pet id to delete (required) - * @return void - */ - public function deletePet($api_key, $pet_id) { - - // parse inputs - $resourcePath = "/pet/{petId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - // header params - if($api_key !== null) { - $headerParams['api_key'] = $this->apiClient->toHeaderValue($api_key); - } - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * uploadFile - * - * uploads an image - * - * @param int $pet_id ID of pet to update (required) - * @param string $additional_metadata Additional data to pass to server (required) - * @param file $file file to upload (required) - * @return void - */ - public function uploadFile($pet_id, $additional_metadata, $file) { - - // parse inputs - $resourcePath = "/pet/{petId}/uploadImage"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array('multipart/form-data',); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($pet_id !== null) { - $resourcePath = str_replace("{" . "petId" . "}", - $this->apiClient->toPathValue($pet_id), $resourcePath); - } - // form params - if ($additional_metadata !== null) { - $formParams['additionalMetadata'] = $this->apiClient->toFormValue($additional_metadata); - }// form params - if ($file !== null) { - $formParams['file'] = '@' . $this->apiClient->toFormValue($file); - } - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - -} diff --git a/samples/client/petstore/php/old/lib/StoreApi.php b/samples/client/petstore/php/old/lib/StoreApi.php deleted file mode 100644 index 83a3f0520fa..00000000000 --- a/samples/client/petstore/php/old/lib/StoreApi.php +++ /dev/null @@ -1,258 +0,0 @@ -apiClient = $apiClient; - } - - - /** - * getInventory - * - * Returns pet inventories by status - * - * @return map[string,int] - */ - public function getInventory() { - - // parse inputs - $resourcePath = "/store/inventory"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'map[string,int]'); - return $responseObject; - } - - /** - * placeOrder - * - * Place an order for a pet - * - * @param Order $body order placed for purchasing the pet (required) - * @return Order - */ - public function placeOrder($body) { - - // parse inputs - $resourcePath = "/store/order"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'Order'); - return $responseObject; - } - - /** - * getOrderById - * - * Find purchase order by ID - * - * @param string $order_id ID of pet that needs to be fetched (required) - * @return Order - */ - public function getOrderById($order_id) { - - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->toPathValue($order_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'Order'); - return $responseObject; - } - - /** - * deleteOrder - * - * Delete purchase order by ID - * - * @param string $order_id ID of the order that needs to be deleted (required) - * @return void - */ - public function deleteOrder($order_id) { - - // parse inputs - $resourcePath = "/store/order/{orderId}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($order_id !== null) { - $resourcePath = str_replace("{" . "orderId" . "}", - $this->apiClient->toPathValue($order_id), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - -} diff --git a/samples/client/petstore/php/old/lib/UserApi.php b/samples/client/petstore/php/old/lib/UserApi.php deleted file mode 100644 index d55b430d7a1..00000000000 --- a/samples/client/petstore/php/old/lib/UserApi.php +++ /dev/null @@ -1,472 +0,0 @@ -apiClient = $apiClient; - } - - - /** - * createUser - * - * Create user - * - * @param User $body Created user object (required) - * @return void - */ - public function createUser($body) { - - // parse inputs - $resourcePath = "/user"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * createUsersWithArrayInput - * - * Creates list of users with given input array - * - * @param array[User] $body List of user object (required) - * @return void - */ - public function createUsersWithArrayInput($body) { - - // parse inputs - $resourcePath = "/user/createWithArray"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * createUsersWithListInput - * - * Creates list of users with given input array - * - * @param array[User] $body List of user object (required) - * @return void - */ - public function createUsersWithListInput($body) { - - // parse inputs - $resourcePath = "/user/createWithList"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "POST"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * loginUser - * - * Logs user into the system - * - * @param string $username The user name for login (required) - * @param string $password The password for login in clear text (required) - * @return string - */ - public function loginUser($username, $password) { - - // parse inputs - $resourcePath = "/user/login"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - // query params - if($username !== null) { - $queryParams['username'] = $this->apiClient->toQueryValue($username); - }// query params - if($password !== null) { - $queryParams['password'] = $this->apiClient->toQueryValue($password); - } - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'string'); - return $responseObject; - } - - /** - * logoutUser - * - * Logs out current logged in user session - * - * @return void - */ - public function logoutUser() { - - // parse inputs - $resourcePath = "/user/logout"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * getUserByName - * - * Get user by user name - * - * @param string $username The name that needs to be fetched. Use user1 for testing. (required) - * @return User - */ - public function getUserByName($username) { - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "GET"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - if(! $response) { - return null; - } - - $responseObject = $this->apiClient->deserialize($response, - 'User'); - return $responseObject; - } - - /** - * updateUser - * - * Updated user - * - * @param string $username name that need to be deleted (required) - * @param User $body Updated user object (required) - * @return void - */ - public function updateUser($username, $body) { - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "PUT"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - // body params - $body = null; - if (isset($body)) { - $body = $body; - } - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - /** - * deleteUser - * - * Delete user - * - * @param string $username The name that needs to be deleted (required) - * @return void - */ - public function deleteUser($username) { - - // parse inputs - $resourcePath = "/user/{username}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "DELETE"; - $httpBody = ''; - $queryParams = array(); - $headerParams = array(); - $formParams = array(); - $_header_accept = 'application/json, application/xml'; - if ($_header_accept !== '') { - $headerParams['Accept'] = $_header_accept; - } - $_header_content_type = array(); - $headerParams['Content-Type'] = count($_header_content_type) > 0 ? $_header_content_type[0] : 'application/json'; - - - - // path params - if($username !== null) { - $resourcePath = str_replace("{" . "username" . "}", - $this->apiClient->toPathValue($username), $resourcePath); - } - - - - // for model (json/xml) - if (isset($body)) { - $httpBody = $body; // $body is the method argument, if present - } - - // for HTTP post (form) - if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { - $httpBody = http_build_query($formParams); - } - - // make the API Call - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $httpBody, - $headerParams); - - - } - - -} diff --git a/samples/client/petstore/php/old/lib/models/Category.php b/samples/client/petstore/php/old/lib/models/Category.php deleted file mode 100644 index 101222b4503..00000000000 --- a/samples/client/petstore/php/old/lib/models/Category.php +++ /dev/null @@ -1,64 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/old/lib/models/Order.php b/samples/client/petstore/php/old/lib/models/Order.php deleted file mode 100644 index 87e8c812eb7..00000000000 --- a/samples/client/petstore/php/old/lib/models/Order.php +++ /dev/null @@ -1,83 +0,0 @@ - 'int', - 'pet_id' => 'int', - 'quantity' => 'int', - 'ship_date' => 'DateTime', - 'status' => 'string', - 'complete' => 'boolean' - ); - - static $attributeMap = array( - 'id' => 'id', - 'pet_id' => 'petId', - 'quantity' => 'quantity', - 'ship_date' => 'shipDate', - 'status' => 'status', - 'complete' => 'complete' - ); - - - public $id; /* int */ - public $pet_id; /* int */ - public $quantity; /* int */ - public $ship_date; /* DateTime */ - /** - * Order Status - */ - public $status; /* string */ - public $complete; /* boolean */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->pet_id = $data["pet_id"]; - $this->quantity = $data["quantity"]; - $this->ship_date = $data["ship_date"]; - $this->status = $data["status"]; - $this->complete = $data["complete"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/old/lib/models/Pet.php b/samples/client/petstore/php/old/lib/models/Pet.php deleted file mode 100644 index eb67904bf13..00000000000 --- a/samples/client/petstore/php/old/lib/models/Pet.php +++ /dev/null @@ -1,83 +0,0 @@ - 'int', - 'category' => 'Category', - 'name' => 'string', - 'photo_urls' => 'array[string]', - 'tags' => 'array[Tag]', - 'status' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'category' => 'category', - 'name' => 'name', - 'photo_urls' => 'photoUrls', - 'tags' => 'tags', - 'status' => 'status' - ); - - - public $id; /* int */ - public $category; /* Category */ - public $name; /* string */ - public $photo_urls; /* array[string] */ - public $tags; /* array[Tag] */ - /** - * pet status in the store - */ - public $status; /* string */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->category = $data["category"]; - $this->name = $data["name"]; - $this->photo_urls = $data["photo_urls"]; - $this->tags = $data["tags"]; - $this->status = $data["status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/old/lib/models/Tag.php b/samples/client/petstore/php/old/lib/models/Tag.php deleted file mode 100644 index a9982317ece..00000000000 --- a/samples/client/petstore/php/old/lib/models/Tag.php +++ /dev/null @@ -1,64 +0,0 @@ - 'int', - 'name' => 'string' - ); - - static $attributeMap = array( - 'id' => 'id', - 'name' => 'name' - ); - - - public $id; /* int */ - public $name; /* string */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->name = $data["name"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/old/lib/models/User.php b/samples/client/petstore/php/old/lib/models/User.php deleted file mode 100644 index 8662f937bc8..00000000000 --- a/samples/client/petstore/php/old/lib/models/User.php +++ /dev/null @@ -1,91 +0,0 @@ - 'int', - 'username' => 'string', - 'first_name' => 'string', - 'last_name' => 'string', - 'email' => 'string', - 'password' => 'string', - 'phone' => 'string', - 'user_status' => 'int' - ); - - static $attributeMap = array( - 'id' => 'id', - 'username' => 'username', - 'first_name' => 'firstName', - 'last_name' => 'lastName', - 'email' => 'email', - 'password' => 'password', - 'phone' => 'phone', - 'user_status' => 'userStatus' - ); - - - public $id; /* int */ - public $username; /* string */ - public $first_name; /* string */ - public $last_name; /* string */ - public $email; /* string */ - public $password; /* string */ - public $phone; /* string */ - /** - * User Status - */ - public $user_status; /* int */ - - public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->username = $data["username"]; - $this->first_name = $data["first_name"]; - $this->last_name = $data["last_name"]; - $this->email = $data["email"]; - $this->password = $data["password"]; - $this->phone = $data["phone"]; - $this->user_status = $data["user_status"]; - } - - public function offsetExists($offset) { - return isset($this->$offset); - } - - public function offsetGet($offset) { - return $this->$offset; - } - - public function offsetSet($offset, $value) { - $this->$offset = $value; - } - - public function offsetUnset($offset) { - unset($this->$offset); - } -} diff --git a/samples/client/petstore/php/old/tests/PetApiTest.php b/samples/client/petstore/php/old/tests/PetApiTest.php deleted file mode 100644 index 77413fd30d8..00000000000 --- a/samples/client/petstore/php/old/tests/PetApiTest.php +++ /dev/null @@ -1,19 +0,0 @@ -getPetById($petId); - $this->assertSame($response->id, $petId); - } -} - -?> diff --git a/samples/client/petstore/php/test.php b/samples/client/petstore/php/test.php index df10876feb5..7cbbfce3cbb 100644 --- a/samples/client/petstore/php/test.php +++ b/samples/client/petstore/php/test.php @@ -1,12 +1,12 @@ getPetById($petId); var_dump($response); From 676c4d0835ca88df6aba62e167ce41cbed29794a Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 17 Apr 2015 00:10:27 +0800 Subject: [PATCH 3/5] add back php unit testing and readme to PHP SwaggerClient sample code --- .../petstore/php/SwaggerClient-php/README.md | 52 +++++++++++++++++++ .../SwaggerClient-php/tests/PetApiTest.php | 16 ++++++ 2 files changed, 68 insertions(+) create mode 100644 samples/client/petstore/php/SwaggerClient-php/README.md create mode 100644 samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md new file mode 100644 index 00000000000..6dfd19a292a --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/README.md @@ -0,0 +1,52 @@ +## Requirements + +PHP 5.3.3 and later. + +## Composer + +You can install the bindings via [Composer](http://getcomposer.org/). Add this to your `composer.json`: + + { + "repositories": [ + { + "type": "git", + "url": "https://github.com/wing328/SwaggerPetstore-php.git" + } + ], + "require": { + "SwaggerPetstore/SwaggerPetstore-php": "*@dev" + } + } + +Then install via: + + composer install + +To use the bindings, use Composer's [autoload](https://getcomposer.org/doc/00-intro.md#autoloading): + + require_once('vendor/autoload.php'); + +## Manual Installation + +If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the `SwaggerPetstore.php` file. + + require_once('/path/to/SwaggerPetstore-php/SwaggerPetstore.php'); + +## Getting Started + +php test.php + +## Documentation + +TODO + +## Tests + +In order to run tests first install [PHPUnit](http://packagist.org/packages/phpunit/phpunit) via [Composer](http://getcomposer.org/): + + composer update + +To run the test suite: + + ./vendor/bin/phpunit tests + diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php new file mode 100644 index 00000000000..dcf5fd32d31 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -0,0 +1,16 @@ +getPetById($petId); + $this->assertSame($response->id, $petId); + } +} +?> From c30ed059fe78dbe47ac216a8513ef93b48d44196 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 17 Apr 2015 00:16:09 +0800 Subject: [PATCH 4/5] update php api test with SwaggerClient.php --- .../petstore/php/SwaggerClient-php/tests/PetApiTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index dcf5fd32d31..3286208ec56 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -1,13 +1,13 @@ getPetById($petId); $this->assertSame($response->id, $petId); From c87579e1f7d62a45724eccac3c89d88c81ac1bc0 Mon Sep 17 00:00:00 2001 From: wing328 Date: Fri, 17 Apr 2015 01:03:15 +0800 Subject: [PATCH 5/5] fix rspec due to change of optional parameter in ruby method --- samples/client/petstore/ruby/spec/pet_spec.rb | 10 +++++----- samples/client/petstore/ruby/spec/spec_helper.rb | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index f0e38084802..67cee70c1ee 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -15,17 +15,17 @@ describe "Pet" do end it "should find pets by status" do - pets = PetApi.find_pets_by_status('available') + pets = PetApi.find_pets_by_status(:status => 'available') pets.length.should >= 3 end it "should not find a pet with invalid status" do - pets = PetApi.find_pets_by_status('invalid-status') + pets = PetApi.find_pets_by_status(:status => 'invalid-status') pets.length.should == 0 end it "should find a pet by status" do - pets = PetApi.find_pets_by_status("available,sold") + pets = PetApi.find_pets_by_status(:status => "available,sold") pets.map {|pet| if(pet.status != 'available' && pet.status != 'sold') raise "pet status wasn't right" @@ -35,7 +35,7 @@ describe "Pet" do it "should update a pet" do pet = Pet.new({'id' => 10002, 'status' => 'sold'}) - PetApi.add_pet(pet) + PetApi.add_pet(:body => pet) fetched = PetApi.get_pet_by_id(10002) fetched.id.should == 10002 @@ -44,7 +44,7 @@ describe "Pet" do it "should create a pet" do pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING") - PetApi.add_pet(pet) + PetApi.add_pet(:body => pet) pet = PetApi.get_pet_by_id(10002) pet.id.should == 10002 diff --git a/samples/client/petstore/ruby/spec/spec_helper.rb b/samples/client/petstore/ruby/spec/spec_helper.rb index c4c56d8a955..71725a45a6c 100644 --- a/samples/client/petstore/ruby/spec/spec_helper.rb +++ b/samples/client/petstore/ruby/spec/spec_helper.rb @@ -47,10 +47,10 @@ end # always delete and then re-create the pet object with 10002 def prepare_pet # remove the pet - PetApi.delete_pet('special-key', 10002) + PetApi.delete_pet(10002) # recreate the pet pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING") - PetApi.add_pet(pet) + PetApi.add_pet(:body => pet) end # always delete and then re-create the store order @@ -61,7 +61,7 @@ def prepare_store "shipDate" => "2015-04-06T23:42:01.678Z", "status" => "placed", "complete" => false) - StoreApi.place_order(order) + StoreApi.place_order(:body => order) end configure_swagger