From 8ed690cad0cc2f88d88727caf5dd881c5b4c6640 Mon Sep 17 00:00:00 2001 From: Branden Cash Date: Fri, 12 Jun 2015 15:01:10 -0700 Subject: [PATCH 1/7] Better namespace support, so that your not limited to only having a single vendor space, you can have \Vendor\Package\Model as a namespace. Also updates with proper phpdoc comments so that IDE code hinting can function properly. --- .../codegen/languages/PhpClientCodegen.java | 78 ++++++++++++++----- .../src/main/resources/php/ApiClient.mustache | 16 ++-- .../main/resources/php/ApiException.mustache | 8 +- .../src/main/resources/php/api.mustache | 15 ++-- .../src/main/resources/php/autoload.mustache | 41 ++++++++++ .../src/main/resources/php/composer.mustache | 5 +- .../main/resources/php/configuration.mustache | 31 +++----- .../src/main/resources/php/model.mustache | 18 +++-- .../src/main/resources/php/require.mustache | 13 ---- 9 files changed, 138 insertions(+), 87 deletions(-) create mode 100644 modules/swagger-codegen/src/main/resources/php/autoload.mustache delete mode 100644 modules/swagger-codegen/src/main/resources/php/require.mustache diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java index 10c03fe4381a..2134bfe75dcc 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java @@ -7,6 +7,7 @@ import io.swagger.codegen.SupportingFile; import io.swagger.models.properties.ArrayProperty; import io.swagger.models.properties.MapProperty; import io.swagger.models.properties.Property; +import io.swagger.models.properties.RefProperty; import java.io.File; import java.util.Arrays; @@ -14,24 +15,20 @@ import java.util.HashMap; import java.util.HashSet; public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { - protected String invokerPackage = "io.swagger.client"; - protected String groupId = "io.swagger"; + protected String invokerPackage = "Swagger\\Client"; + protected String groupId = "swagger"; protected String artifactId = "swagger-client"; - protected String artifactVersion = "1.0.0"; + protected String artifactVersion = null; public PhpClientCodegen() { super(); - invokerPackage = camelize("SwaggerClient"); - - String packagePath = invokerPackage + "-php"; - - modelPackage = packagePath + "/lib/models"; - apiPackage = packagePath + "/lib"; outputFolder = "generated-code/php"; modelTemplateFiles.put("model.mustache", ".php"); apiTemplateFiles.put("api.mustache", ".php"); templateDir = "php"; + apiPackage = invokerPackage + "\\Api"; + modelPackage = invokerPackage + "\\Model"; reservedWords = new HashSet( Arrays.asList( @@ -39,6 +36,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { ); additionalProperties.put("invokerPackage", invokerPackage); + additionalProperties.put("modelPackage", modelPackage); + additionalProperties.put("apiPackage", apiPackage); + additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\")); additionalProperties.put("groupId", groupId); additionalProperties.put("artifactId", artifactId); additionalProperties.put("artifactVersion", artifactVersion); @@ -46,6 +46,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { // ref: http://php.net/manual/en/language.types.intro.php languageSpecificPrimitives = new HashSet( Arrays.asList( + "bool", "boolean", "int", "integer", @@ -55,7 +56,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { "object", "DateTime", "mixed", - "number") + "number", + "void", + "byte") ); instantiationTypes.put("array", "array"); @@ -69,20 +72,41 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { typeMapping.put("double", "double"); typeMapping.put("string", "string"); typeMapping.put("byte", "int"); - typeMapping.put("boolean", "boolean"); - typeMapping.put("date", "DateTime"); - typeMapping.put("datetime", "DateTime"); + typeMapping.put("boolean", "bool"); + typeMapping.put("date", "\\DateTime"); + typeMapping.put("datetime", "\\DateTime"); typeMapping.put("file", "string"); typeMapping.put("map", "map"); typeMapping.put("array", "array"); typeMapping.put("list", "array"); typeMapping.put("object", "object"); + typeMapping.put("DateTime", "\\DateTime"); - supportingFiles.add(new SupportingFile("composer.mustache", packagePath.replace('/', File.separatorChar), "composer.json")); - supportingFiles.add(new SupportingFile("configuration.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "Configuration.php")); - supportingFiles.add(new SupportingFile("ApiClient.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "ApiClient.php")); - supportingFiles.add(new SupportingFile("ApiException.mustache", (packagePath + "/lib").replace('/', File.separatorChar), "ApiException.php")); - supportingFiles.add(new SupportingFile("require.mustache", packagePath.replace('/', File.separatorChar), invokerPackage + ".php")); + supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json")); + supportingFiles.add(new SupportingFile("configuration.mustache", toPackagePath(invokerPackage, "lib"), "Configuration.php")); + supportingFiles.add(new SupportingFile("ApiClient.mustache", toPackagePath(invokerPackage, "lib"), "ApiClient.php")); + supportingFiles.add(new SupportingFile("ApiException.mustache", toPackagePath(invokerPackage, "lib"), "ApiException.php")); + supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php")); + } + + public String getPackagePath() { + //invokerPackage.replace("\\", "") + return "SwaggerClient-php"; + } + + public String toPackagePath(String packageName, String basePath) { + packageName = packageName.replace(invokerPackage, ""); + if (basePath != null && basePath.length() > 0) { + basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; + } + + return (getPackagePath() + File.separatorChar + basePath + // Replace period, backslash, forward slash with file separator in package name + + packageName.replaceAll("[\\.\\\\/]", File.separator) + // Trim prefix file separators from package path + .replaceAll("^" + File.separator, "")) + // Trim trailing file separators from the overall path + .replaceAll(File.separator + "$", ""); } public CodegenType getTag() { @@ -104,11 +128,11 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { @Override public String apiFileFolder() { - return (outputFolder + "/" + apiPackage()).replace('/', File.separatorChar); + return (outputFolder + "/" + toPackagePath(apiPackage(), "lib")); } public String modelFileFolder() { - return (outputFolder + "/" + modelPackage()).replace('/', File.separatorChar); + return (outputFolder + "/" + toPackagePath(modelPackage(), "lib")); } @Override @@ -116,15 +140,27 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { if (p instanceof ArrayProperty) { ArrayProperty ap = (ArrayProperty) p; Property inner = ap.getItems(); - return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]"; + return getTypeDeclaration(inner) + "[]"; } else if (p instanceof MapProperty) { MapProperty mp = (MapProperty) p; Property inner = mp.getAdditionalProperties(); return getSwaggerType(p) + "[string," + getTypeDeclaration(inner) + "]"; + } else if (p instanceof RefProperty) { + String type = super.getTypeDeclaration(p); + return (!languageSpecificPrimitives.contains(type)) + ? "\\" + modelPackage + "\\" + type : type; } return super.getTypeDeclaration(p); } + @Override + public String getTypeDeclaration(String name) { + if (!languageSpecificPrimitives.contains(name)) { + return "\\" + modelPackage + "\\" + name; + } + return super.getTypeDeclaration(name); + } + @Override public String getSwaggerType(Property p) { String swaggerType = super.getSwaggerType(p); diff --git a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache index b116eee0829f..9badb4dbb373 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiClient.mustache @@ -24,17 +24,14 @@ class ApiClient { public static $GET = "GET"; public static $PUT = "PUT"; public static $DELETE = "DELETE"; - + + /** @var string[] Array of default headers where the key is the header name and the value is the header value */ private $default_header = array(); - /* - * @var string timeout (second) of the HTTP request, by default set to 0, no timeout - */ + /** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */ protected $curl_timeout = 0; - /* - * @var string user agent of the HTTP request, set to "PHP-Swagger" by default - */ + /** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */ protected $user_agent = "PHP-Swagger"; /** @@ -386,8 +383,8 @@ class ApiClient { $deserialized[$key] = $this->deserialize($value, $subClass); } } - } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { - $subClass = substr($class, 6, -1); + } elseif (strcasecmp(substr($class, -2),'[]') == 0) { + $subClass = substr($class, 0, -2); $values = array(); foreach ($data as $key => $value) { $values[] = $this->deserialize($value, $subClass); @@ -399,7 +396,6 @@ class ApiClient { settype($data, $class); $deserialized = $data; } else { - $class = "{{invokerPackage}}\\models\\".$class; $instance = new $class(); foreach ($instance::$swaggerTypes as $property => $type) { $original_property_name = $instance::$attributeMap[$property]; diff --git a/modules/swagger-codegen/src/main/resources/php/ApiException.mustache b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache index b66c3a51eb74..a835d579d32b 100644 --- a/modules/swagger-codegen/src/main/resources/php/ApiException.mustache +++ b/modules/swagger-codegen/src/main/resources/php/ApiException.mustache @@ -21,14 +21,10 @@ use \Exception; class ApiException extends Exception { - /** - * The HTTP body of the server response. - */ + /** @var string The HTTP body of the server response. */ protected $response_body; - /** - * The HTTP header of the server response. - */ + /** @var string[] The HTTP header of the server response. */ protected $response_headers; public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) { diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 755d0e70452b..1946e26bf342 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -20,11 +20,17 @@ * NOTE: This class is auto generated by the swagger code generator program. Do not edit the class manually. */ -namespace {{invokerPackage}}; +namespace {{apiPackage}}; + +use \{{invokerPackage}}\ApiClient; +use \{{invokerPackage}}\Configuration; {{#operations}} class {{classname}} { + /** + * @param \{{invokerPackage}}\ApiClient|null $apiClient The api client to use. Defaults to getting it from Configuration + */ function __construct($apiClient = null) { if (null === $apiClient) { if (Configuration::$apiClient === null) { @@ -41,14 +47,14 @@ class {{classname}} { private $apiClient; // instance of the ApiClient /** - * get the API client - */ + * @return \{{invokerPackage}}\ApiClient get the API client + */ public function getApiClient() { return $this->apiClient; } /** - * set the API client + * @param \{{invokerPackage}} $apiClient set the API client */ public function setApiClient($apiClient) { $this->apiClient = $apiClient; @@ -123,7 +129,6 @@ class {{classname}} { $response = $this->apiClient->callAPI($resourcePath, $method, $queryParams, $httpBody, $headerParams, $authSettings); - {{#returnType}}if(! $response) { return null; } diff --git a/modules/swagger-codegen/src/main/resources/php/autoload.mustache b/modules/swagger-codegen/src/main/resources/php/autoload.mustache new file mode 100644 index 000000000000..4f56a6e20c04 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/php/autoload.mustache @@ -0,0 +1,41 @@ + '{{{datatype}}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ static $attributeMap = array( {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}}, {{/hasMore}}{{/vars}} ); - - {{#vars}}{{#description}} + {{#vars}} + /** @var {{datatype}} ${{name}} {{#description}}{{{description}}} {{/description}}*/ + public ${{name}}; + {{/vars}} /** - * {{{description}}} - */{{/description}} - public ${{name}}; /* {{{datatype}}} */{{/vars}} - + * @param mixed[] Array of parameters to initialize the object with + */ public function __construct(array $data = null) { - {{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}} + {{#vars}}$this->{{name}} = @$data["{{name}}"];{{#hasMore}} {{/hasMore}}{{/vars}} } diff --git a/modules/swagger-codegen/src/main/resources/php/require.mustache b/modules/swagger-codegen/src/main/resources/php/require.mustache deleted file mode 100644 index 3c02d861ef18..000000000000 --- a/modules/swagger-codegen/src/main/resources/php/require.mustache +++ /dev/null @@ -1,13 +0,0 @@ - From 719a0b732ee0c64e958c53cd93329793854af7d5 Mon Sep 17 00:00:00 2001 From: Branden Cash Date: Fri, 12 Jun 2015 15:01:25 -0700 Subject: [PATCH 2/7] Update sample client --- .../php/SwaggerClient-php/SwaggerClient.php | 13 - .../php/SwaggerClient-php/autoload.php | 41 ++ .../php/SwaggerClient-php/composer.json | 4 +- .../php/SwaggerClient-php/lib/Api/PetApi.php | 541 ++++++++++++++++++ .../SwaggerClient-php/lib/Api/StoreApi.php | 296 ++++++++++ .../php/SwaggerClient-php/lib/Api/UserApi.php | 516 +++++++++++++++++ .../php/SwaggerClient-php/lib/ApiClient.php | 18 +- .../SwaggerClient-php/lib/ApiException.php | 10 +- .../SwaggerClient-php/lib/Configuration.php | 33 +- .../lib/{models => Model}/Category.php | 21 +- .../lib/{models => Model}/Order.php | 50 +- .../lib/{models => Model}/Pet.php | 52 +- .../lib/{models => Model}/Tag.php | 21 +- .../lib/{models => Model}/User.php | 58 +- samples/client/petstore/php/test.php | 18 +- 15 files changed, 1551 insertions(+), 141 deletions(-) delete mode 100644 samples/client/petstore/php/SwaggerClient-php/SwaggerClient.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/autoload.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php create mode 100644 samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php rename samples/client/petstore/php/SwaggerClient-php/lib/{models => Model}/Category.php (76%) rename samples/client/petstore/php/SwaggerClient-php/lib/{models => Model}/Order.php (65%) rename samples/client/petstore/php/SwaggerClient-php/lib/{models => Model}/Pet.php (61%) rename samples/client/petstore/php/SwaggerClient-php/lib/{models => Model}/Tag.php (76%) rename samples/client/petstore/php/SwaggerClient-php/lib/{models => Model}/User.php (64%) diff --git a/samples/client/petstore/php/SwaggerClient-php/SwaggerClient.php b/samples/client/petstore/php/SwaggerClient-php/SwaggerClient.php deleted file mode 100644 index 3c02d861ef18..000000000000 --- a/samples/client/petstore/php/SwaggerClient-php/SwaggerClient.php +++ /dev/null @@ -1,13 +0,0 @@ - diff --git a/samples/client/petstore/php/SwaggerClient-php/autoload.php b/samples/client/petstore/php/SwaggerClient-php/autoload.php new file mode 100644 index 000000000000..acbd3968b23e --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/autoload.php @@ -0,0 +1,41 @@ +apiClient = Configuration::$apiClient; + } + else + $this->apiClient = Configuration::$apiClient; // use the default one + } else { + $this->apiClient = $apiClient; // use the one provided by the user + } + } + + private $apiClient; // instance of the ApiClient + + /** + * @return \Swagger\Client\ApiClient get the API client + */ + public function getApiClient() { + return $this->apiClient; + } + + /** + * @param \Swagger\Client $apiClient set the API client + */ + public function setApiClient($apiClient) { + $this->apiClient = $apiClient; + } + + + /** + * updatePet + * + * Update an existing pet + * + * @param \Swagger\Client\Model\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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','application/xml')); + + + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('petstore_auth'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * addPet + * + * Add a new pet to the store + * + * @param \Swagger\Client\Model\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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/json','application/xml')); + + + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('petstore_auth'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * findPetsByStatus + * + * Finds Pets by status + * + * @param string[] $status Status values that need to be considered for filter (required) + * @return \Swagger\Client\Model\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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('petstore_auth'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\Pet[]'); + return $responseObject; + } + + /** + * findPetsByTags + * + * Finds Pets by tags + * + * @param string[] $tags Tags to filter by (required) + * @return \Swagger\Client\Model\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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('petstore_auth'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\Pet[]'); + return $responseObject; + } + + /** + * getPetById + * + * Find pet by ID + * + * @param int $pet_id ID of pet that needs to be fetched (required) + * @return \Swagger\Client\Model\Pet + */ + public function getPetById($pet_id) { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling getPetById'); + } + + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('api_key', 'petstore_auth'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\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) { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling updatePetWithForm'); + } + + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('application/x-www-form-urlencoded')); + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('petstore_auth'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * 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) { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling deletePet'); + } + + + // parse inputs + $resourcePath = "/pet/{petId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('petstore_auth'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * 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 string $file file to upload (required) + * @return void + */ + public function uploadFile($pet_id, $additional_metadata, $file) { + + // verify the required parameter 'pet_id' is set + if ($pet_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $pet_id when calling uploadFile'); + } + + + // parse inputs + $resourcePath = "/pet/{petId}/uploadImage"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "POST"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array('multipart/form-data')); + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('petstore_auth'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php new file mode 100644 index 000000000000..b8b30977b59f --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -0,0 +1,296 @@ +apiClient = Configuration::$apiClient; + } + else + $this->apiClient = Configuration::$apiClient; // use the default one + } else { + $this->apiClient = $apiClient; // use the one provided by the user + } + } + + private $apiClient; // instance of the ApiClient + + /** + * @return \Swagger\Client\ApiClient get the API client + */ + public function getApiClient() { + return $this->apiClient; + } + + /** + * @param \Swagger\Client $apiClient set the API client + */ + public function setApiClient($apiClient) { + $this->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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array('api_key'); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response,'map[string,int]'); + return $responseObject; + } + + /** + * placeOrder + * + * Place an order for a pet + * + * @param \Swagger\Client\Model\Order $body order placed for purchasing the pet (required) + * @return \Swagger\Client\Model\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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\Order'); + return $responseObject; + } + + /** + * getOrderById + * + * Find purchase order by ID + * + * @param string $order_id ID of pet that needs to be fetched (required) + * @return \Swagger\Client\Model\Order + */ + public function getOrderById($order_id) { + + // verify the required parameter 'order_id' is set + if ($order_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $order_id when calling getOrderById'); + } + + + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\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) { + + // verify the required parameter 'order_id' is set + if ($order_id === null) { + throw new \InvalidArgumentException('Missing the required parameter $order_id when calling deleteOrder'); + } + + + // parse inputs + $resourcePath = "/store/order/{orderId}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php new file mode 100644 index 000000000000..2e83df74da47 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -0,0 +1,516 @@ +apiClient = Configuration::$apiClient; + } + else + $this->apiClient = Configuration::$apiClient; // use the default one + } else { + $this->apiClient = $apiClient; // use the one provided by the user + } + } + + private $apiClient; // instance of the ApiClient + + /** + * @return \Swagger\Client\ApiClient get the API client + */ + public function getApiClient() { + return $this->apiClient; + } + + /** + * @param \Swagger\Client $apiClient set the API client + */ + public function setApiClient($apiClient) { + $this->apiClient = $apiClient; + } + + + /** + * createUser + * + * Create user + * + * @param \Swagger\Client\Model\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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * createUsersWithArrayInput + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * createUsersWithListInput + * + * Creates list of users with given input array + * + * @param \Swagger\Client\Model\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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * 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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + 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 = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + + + + + // for model (json/xml) + if (isset($_tempBody)) { + $httpBody = $_tempBody; // $_tempBody is the method argument, if present + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * getUserByName + * + * Get user by user name + * + * @param string $username The name that needs to be fetched. Use user1 for testing. (required) + * @return \Swagger\Client\Model\User + */ + public function getUserByName($username) { + + // verify the required parameter 'username' is set + if ($username === null) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling getUserByName'); + } + + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "GET"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + if(! $response) { + return null; + } + + $responseObject = $this->apiClient->deserialize($response,'\Swagger\Client\Model\User'); + return $responseObject; + } + + /** + * updateUser + * + * Updated user + * + * @param string $username name that need to be deleted (required) + * @param \Swagger\Client\Model\User $body Updated user object (required) + * @return void + */ + public function updateUser($username, $body) { + + // verify the required parameter 'username' is set + if ($username === null) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling updateUser'); + } + + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "PUT"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + /** + * deleteUser + * + * Delete user + * + * @param string $username The name that needs to be deleted (required) + * @return void + */ + public function deleteUser($username) { + + // verify the required parameter 'username' is set + if ($username === null) { + throw new \InvalidArgumentException('Missing the required parameter $username when calling deleteUser'); + } + + + // parse inputs + $resourcePath = "/user/{username}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "DELETE"; + $httpBody = ''; + $queryParams = array(); + $headerParams = array(); + $formParams = array(); + $_header_accept = $this->apiClient->selectHeaderAccept(array('application/json', 'application/xml')); + if (!is_null($_header_accept)) { + $headerParams['Accept'] = $_header_accept; + } + $headerParams['Content-Type'] = $this->apiClient->selectHeaderContentType(array()); + + + + // 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 + } else if (count($formParams) > 0) { + // for HTTP post (form) + $httpBody = $formParams; + } + + // authentication setting, if any + $authSettings = array(); + + // make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $httpBody, + $headerParams, $authSettings); + + } + + +} diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php index 280fe9bdd712..bb5229fb1707 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiClient.php @@ -15,7 +15,7 @@ * limitations under the License. */ -namespace SwaggerClient; +namespace Swagger\Client; class ApiClient { @@ -24,17 +24,14 @@ class ApiClient { public static $GET = "GET"; public static $PUT = "PUT"; public static $DELETE = "DELETE"; - + + /** @var string[] Array of default headers where the key is the header name and the value is the header value */ private $default_header = array(); - /* - * @var string timeout (second) of the HTTP request, by default set to 0, no timeout - */ + /** @var string timeout (second) of the HTTP request, by default set to 0, no timeout */ protected $curl_timeout = 0; - /* - * @var string user agent of the HTTP request, set to "PHP-Swagger" by default - */ + /** @var string user agent of the HTTP request, set to "PHP-Swagger" by default */ protected $user_agent = "PHP-Swagger"; /** @@ -391,8 +388,8 @@ class ApiClient { $deserialized[$key] = $this->deserialize($value, $subClass); } } - } elseif (strcasecmp(substr($class, 0, 6),'array[') == 0) { - $subClass = substr($class, 6, -1); + } elseif (strcasecmp(substr($class, -2),'[]') == 0) { + $subClass = substr($class, 0, -2); $values = array(); foreach ($data as $key => $value) { $values[] = $this->deserialize($value, $subClass); @@ -404,7 +401,6 @@ class ApiClient { 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]; diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php b/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php index 51f2c4b877e1..5f3b18122615 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/ApiException.php @@ -15,20 +15,16 @@ * limitations under the License. */ -namespace SwaggerClient; +namespace Swagger\Client; use \Exception; class ApiException extends Exception { - /** - * The HTTP body of the server response. - */ + /** @var string The HTTP body of the server response. */ protected $response_body; - /** - * The HTTP header of the server response. - */ + /** @var string[] The HTTP header of the server response. */ protected $response_headers; public function __construct($message="", $code=0, $responseHeaders=null, $responseBody=null) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php index cd514956a294..e6381781bb0b 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Configuration.php @@ -15,43 +15,31 @@ * limitations under the License. */ -namespace SwaggerClient; +namespace Swagger\Client; + +use \Swagger\Client\ApiClient; class Configuration { - /** - * Associate array to store API key(s) - */ + /** @var string[] Associate array to store API key(s) */ public static $apiKey = array(); - /** - * Associate array to store API prefix (e.g. Bearer) - */ + /** string[] Associate array to store API prefix (e.g. Bearer) */ public static $apiKeyPrefix = array(); - /** - * Username for HTTP basic authentication - */ + /** @var string Username for HTTP basic authentication */ public static $username = ''; - /** - * Password for HTTP basic authentication - */ + /** @var string Password for HTTP basic authentication */ public static $password = ''; - /** - * The default instance of ApiClient - */ + /** @var \Swagger\Client\ApiClient The default instance of ApiClient */ public static $apiClient; - /** - * Debug switch (default set to false) - */ + /** @var bool Debug switch (default set to false) */ public static $debug = false; - /** - * Debug file location (log to STDOUT by default) - */ + /** @var string Debug file location (log to STDOUT by default) */ public static $debug_file = 'php://output'; /* @@ -63,4 +51,3 @@ class Configuration { } } - diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/Category.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php similarity index 76% rename from samples/client/petstore/php/SwaggerClient-php/lib/models/Category.php rename to samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php index c49c711fa8e9..750a8fee5df8 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/models/Category.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Category.php @@ -22,28 +22,35 @@ * */ -namespace SwaggerClient\models; +namespace Swagger\Client\Model; use \ArrayAccess; class Category implements ArrayAccess { + /** @var string[] Array of property to type mappings. Used for (de)serialization */ static $swaggerTypes = array( 'id' => 'int', 'name' => 'string' ); + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ static $attributeMap = array( 'id' => 'id', 'name' => 'name' ); - - public $id; /* int */ - public $name; /* string */ - + /** @var int $id */ + public $id; + + /** @var string $name */ + public $name; + + /** + * @param mixed[] Array of parameters to initialize the object with + */ public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->name = $data["name"]; + $this->id = @$data["id"]; + $this->name = @$data["name"]; } public function offsetExists($offset) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/Order.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php similarity index 65% rename from samples/client/petstore/php/SwaggerClient-php/lib/models/Order.php rename to samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php index bf8a0178e4c0..64552afb7632 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/models/Order.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Order.php @@ -22,20 +22,22 @@ * */ -namespace SwaggerClient\models; +namespace Swagger\Client\Model; use \ArrayAccess; class Order implements ArrayAccess { + /** @var string[] Array of property to type mappings. Used for (de)serialization */ static $swaggerTypes = array( 'id' => 'int', 'pet_id' => 'int', 'quantity' => 'int', - 'ship_date' => 'DateTime', + 'ship_date' => '\DateTime', 'status' => 'string', - 'complete' => 'boolean' + 'complete' => 'bool' ); + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ static $attributeMap = array( 'id' => 'id', 'pet_id' => 'petId', @@ -44,25 +46,35 @@ class Order implements ArrayAccess { 'status' => 'status', 'complete' => 'complete' ); - - public $id; /* int */ - public $pet_id; /* int */ - public $quantity; /* int */ - public $ship_date; /* DateTime */ + /** @var int $id */ + public $id; + + /** @var int $pet_id */ + public $pet_id; + + /** @var int $quantity */ + public $quantity; + + /** @var \DateTime $ship_date */ + public $ship_date; + + /** @var string $status Order Status */ + public $status; + + /** @var bool $complete */ + public $complete; + /** - * Order Status - */ - public $status; /* string */ - public $complete; /* boolean */ - + * @param mixed[] Array of parameters to initialize the object with + */ 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"]; + $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) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/Pet.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php similarity index 61% rename from samples/client/petstore/php/SwaggerClient-php/lib/models/Pet.php rename to samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php index 2009cc373cf0..ef2a4c76a0de 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/models/Pet.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Pet.php @@ -22,20 +22,22 @@ * */ -namespace SwaggerClient\models; +namespace Swagger\Client\Model; use \ArrayAccess; class Pet implements ArrayAccess { + /** @var string[] Array of property to type mappings. Used for (de)serialization */ static $swaggerTypes = array( 'id' => 'int', - 'category' => 'Category', + 'category' => '\Swagger\Client\Model\Category', 'name' => 'string', - 'photo_urls' => 'array[string]', - 'tags' => 'array[Tag]', + 'photo_urls' => 'string[]', + 'tags' => '\Swagger\Client\Model\Tag[]', 'status' => 'string' ); + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ static $attributeMap = array( 'id' => 'id', 'category' => 'category', @@ -44,25 +46,35 @@ class Pet implements ArrayAccess { 'tags' => 'tags', 'status' => 'status' ); - - public $id; /* int */ - public $category; /* Category */ - public $name; /* string */ - public $photo_urls; /* array[string] */ - public $tags; /* array[Tag] */ + /** @var int $id */ + public $id; + + /** @var \Swagger\Client\Model\Category $category */ + public $category; + + /** @var string $name */ + public $name; + + /** @var string[] $photo_urls */ + public $photo_urls; + + /** @var \Swagger\Client\Model\Tag[] $tags */ + public $tags; + + /** @var string $status pet status in the store */ + public $status; + /** - * pet status in the store - */ - public $status; /* string */ - + * @param mixed[] Array of parameters to initialize the object with + */ 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"]; + $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) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/Tag.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php similarity index 76% rename from samples/client/petstore/php/SwaggerClient-php/lib/models/Tag.php rename to samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php index 37729c68d9ec..5959cb20a6a2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/models/Tag.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/Tag.php @@ -22,28 +22,35 @@ * */ -namespace SwaggerClient\models; +namespace Swagger\Client\Model; use \ArrayAccess; class Tag implements ArrayAccess { + /** @var string[] Array of property to type mappings. Used for (de)serialization */ static $swaggerTypes = array( 'id' => 'int', 'name' => 'string' ); + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ static $attributeMap = array( 'id' => 'id', 'name' => 'name' ); - - public $id; /* int */ - public $name; /* string */ - + /** @var int $id */ + public $id; + + /** @var string $name */ + public $name; + + /** + * @param mixed[] Array of parameters to initialize the object with + */ public function __construct(array $data = null) { - $this->id = $data["id"]; - $this->name = $data["name"]; + $this->id = @$data["id"]; + $this->name = @$data["name"]; } public function offsetExists($offset) { diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/models/User.php b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php similarity index 64% rename from samples/client/petstore/php/SwaggerClient-php/lib/models/User.php rename to samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php index 0ec53c409e60..1bfb7f332db2 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/models/User.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Model/User.php @@ -22,11 +22,12 @@ * */ -namespace SwaggerClient\models; +namespace Swagger\Client\Model; use \ArrayAccess; class User implements ArrayAccess { + /** @var string[] Array of property to type mappings. Used for (de)serialization */ static $swaggerTypes = array( 'id' => 'int', 'username' => 'string', @@ -38,6 +39,7 @@ class User implements ArrayAccess { 'user_status' => 'int' ); + /** @var string[] Array of attributes where the key is the local name, and the value is the original name */ static $attributeMap = array( 'id' => 'id', 'username' => 'username', @@ -48,29 +50,43 @@ class User implements ArrayAccess { '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 */ + /** @var int $id */ + public $id; + + /** @var string $username */ + public $username; + + /** @var string $first_name */ + public $first_name; + + /** @var string $last_name */ + public $last_name; + + /** @var string $email */ + public $email; + + /** @var string $password */ + public $password; + + /** @var string $phone */ + public $phone; + + /** @var int $user_status User Status */ + public $user_status; + /** - * User Status - */ - public $user_status; /* int */ - + * @param mixed[] Array of parameters to initialize the object with + */ 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"]; + $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) { diff --git a/samples/client/petstore/php/test.php b/samples/client/petstore/php/test.php index 0c52f0fdb8ad..f5383a9a4dc5 100644 --- a/samples/client/petstore/php/test.php +++ b/samples/client/petstore/php/test.php @@ -1,6 +1,5 @@ getApiClient()->addDefaultHeader("TEST_API_KEY", "09182sdkanafndsl903"); // return Pet (model) @@ -28,34 +27,31 @@ try { // add pet (post json) $new_pet_id = 10005; - $new_pet = new SwaggerClient\models\Pet; + $new_pet = new Swagger\Client\Model\Pet; $new_pet->id = $new_pet_id; $new_pet->name = "PHP Unit Test"; // new tag - $tag= new SwaggerClient\models\Tag; + $tag= new Swagger\Client\Model\Tag; $tag->id = $new_pet_id; // use the same id as pet //$tag->name = "test php tag"; // new category - $category = new SwaggerClient\models\Category; + $category = new Swagger\Client\Model\Category; $category->id = 0; // use the same id as pet //$category->name = "test php category"; $new_pet->tags = array($tag); $new_pet->category = $category; - $pet_api = new SwaggerClient\PetAPI(); + $pet_api = new Swagger\Client\Api\PetAPI(); // add a new pet (model) $add_response = $pet_api->addPet($new_pet); // test upload file (exception) $upload_response = $pet_api->uploadFile($petId, "test meta", NULL); -} catch (Exception $e) { +} catch (Swagger\Client\Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; echo 'HTTP response headers: ', $e->getResponseHeaders(), "\n"; echo 'HTTP response body: ', $e->getResponseBody(), "\n"; echo 'HTTP status code: ', $e->getCode(), "\n"; } - - -?> From 5119299e8ac2b40be22441c5e7d1a0c5e05650e3 Mon Sep 17 00:00:00 2001 From: Branden Cash Date: Fri, 12 Jun 2015 15:45:36 -0700 Subject: [PATCH 3/7] Remove unused code --- .../main/java/io/swagger/codegen/languages/PhpClientCodegen.java | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java index 2134bfe75dcc..0690163f1371 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java @@ -90,7 +90,6 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig { } public String getPackagePath() { - //invokerPackage.replace("\\", "") return "SwaggerClient-php"; } From 69c2f6f945e55450cfd5c9ce209364ed245f218e Mon Sep 17 00:00:00 2001 From: Branden Cash Date: Fri, 12 Jun 2015 16:05:45 -0700 Subject: [PATCH 4/7] Add phpdoc for the api.apiClient --- modules/swagger-codegen/src/main/resources/php/api.mustache | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 1946e26bf342..05f6944e7204 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -44,7 +44,8 @@ class {{classname}} { } } - private $apiClient; // instance of the ApiClient + /** @var \{{invokerPackage}}\ApiClient instance of the ApiClient + private $apiClient; /** * @return \{{invokerPackage}}\ApiClient get the API client From eed45a41a391be9a87482bead63bc7b90e3c5b0f Mon Sep 17 00:00:00 2001 From: Branden Cash Date: Fri, 12 Jun 2015 16:21:37 -0700 Subject: [PATCH 5/7] Fixed the missing closing doc chars and updated sample --- .../swagger-codegen/src/main/resources/php/api.mustache | 6 +++--- .../petstore/php/SwaggerClient-php/lib/Api/PetApi.php | 7 ++++--- .../petstore/php/SwaggerClient-php/lib/Api/StoreApi.php | 7 ++++--- .../petstore/php/SwaggerClient-php/lib/Api/UserApi.php | 7 ++++--- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 05f6944e7204..3ed7f18c5795 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -44,12 +44,12 @@ class {{classname}} { } } - /** @var \{{invokerPackage}}\ApiClient instance of the ApiClient + /** @var \{{invokerPackage}}\ApiClient instance of the ApiClient */ private $apiClient; /** - * @return \{{invokerPackage}}\ApiClient get the API client - */ + * @return \{{invokerPackage}}\ApiClient get the API client + */ public function getApiClient() { return $this->apiClient; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php index 01ecd6771e41..f4f6ea8538a0 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/PetApi.php @@ -43,11 +43,12 @@ class PetApi { } } - private $apiClient; // instance of the ApiClient + /** @var \Swagger\Client\ApiClient instance of the ApiClient */ + private $apiClient; /** - * @return \Swagger\Client\ApiClient get the API client - */ + * @return \Swagger\Client\ApiClient get the API client + */ public function getApiClient() { return $this->apiClient; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php index b8b30977b59f..07a922aab0aa 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/StoreApi.php @@ -43,11 +43,12 @@ class StoreApi { } } - private $apiClient; // instance of the ApiClient + /** @var \Swagger\Client\ApiClient instance of the ApiClient */ + private $apiClient; /** - * @return \Swagger\Client\ApiClient get the API client - */ + * @return \Swagger\Client\ApiClient get the API client + */ public function getApiClient() { return $this->apiClient; } diff --git a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php index 2e83df74da47..f4d35a3a7a08 100644 --- a/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php +++ b/samples/client/petstore/php/SwaggerClient-php/lib/Api/UserApi.php @@ -43,11 +43,12 @@ class UserApi { } } - private $apiClient; // instance of the ApiClient + /** @var \Swagger\Client\ApiClient instance of the ApiClient */ + private $apiClient; /** - * @return \Swagger\Client\ApiClient get the API client - */ + * @return \Swagger\Client\ApiClient get the API client + */ public function getApiClient() { return $this->apiClient; } From 2ac7384abf841f63a6170916256baa68ab9696d4 Mon Sep 17 00:00:00 2001 From: Branden Cash Date: Fri, 12 Jun 2015 16:49:17 -0700 Subject: [PATCH 6/7] Fix tests --- .../src/test/scala/php/PhpModelTest.scala | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/swagger-codegen/src/test/scala/php/PhpModelTest.scala b/modules/swagger-codegen/src/test/scala/php/PhpModelTest.scala index ade8a09e80db..ffb9c8683dbe 100644 --- a/modules/swagger-codegen/src/test/scala/php/PhpModelTest.scala +++ b/modules/swagger-codegen/src/test/scala/php/PhpModelTest.scala @@ -51,16 +51,16 @@ class PhpModelTest extends FlatSpec with Matchers { vars.get(1).isNotContainer should equal(true) vars.get(2).baseName should be("createdAt") - vars.get(2).complexType should be(null) - vars.get(2).datatype should be("DateTime") + vars.get(2).complexType should be("\\DateTime") + vars.get(2).datatype should be("\\DateTime") vars.get(2).name should be("created_at") vars.get(2).defaultValue should be("null") - vars.get(2).baseType should be("DateTime") + vars.get(2).baseType should be("\\DateTime") vars.get(2).hasMore should equal(null) vars.get(2).required should equal(null) vars.get(2).isNotContainer should equal(true) - cm.imports.size() should be(0) + cm.imports.size() should be(1) } it should "convert a model with list property" in { @@ -91,7 +91,7 @@ class PhpModelTest extends FlatSpec with Matchers { vars.get(0).isNotContainer should equal(true) vars.get(1).baseName should be("urls") - vars.get(1).datatype should be("array[string]") + vars.get(1).datatype should be("string[]") vars.get(1).name should be("urls") vars.get(1).baseType should be("array") vars.get(1).hasMore should be(null) @@ -142,7 +142,7 @@ class PhpModelTest extends FlatSpec with Matchers { val vars = cm.vars vars.get(0).baseName should be("children") - vars.get(0).datatype should be("Children") + vars.get(0).datatype should be("\\Swagger\\Client\\Model\\Children") vars.get(0).name should be("children") vars.get(0).baseType should be("Children") vars.get(0).required should equal(null) @@ -166,7 +166,7 @@ class PhpModelTest extends FlatSpec with Matchers { val vars = cm.vars vars.get(0).baseName should be("children") vars.get(0).complexType should be("Children") - vars.get(0).datatype should be("array[Children]") + vars.get(0).datatype should be("\\Swagger\\Client\\Model\\Children[]") vars.get(0).name should be("children") vars.get(0).baseType should be("array") vars.get(0).containerType should be("array") @@ -192,7 +192,7 @@ class PhpModelTest extends FlatSpec with Matchers { val vars = cm.vars vars.get(0).baseName should be("children") vars.get(0).complexType should be("Children") - vars.get(0).datatype should be("map[string,Children]") + vars.get(0).datatype should be("map[string,\\Swagger\\Client\\Model\\Children]") vars.get(0).name should be("children") vars.get(0).baseType should be("map") vars.get(0).containerType should be("map") From b74050dd7bc3d4ff73fe2bd77406953559e0a993 Mon Sep 17 00:00:00 2001 From: Branden Cash Date: Sat, 13 Jun 2015 09:40:32 -0700 Subject: [PATCH 7/7] Change to use the autoload.php and change the namespacing --- .../SwaggerClient-php/tests/PetApiTest.php | 66 +++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php index 5131fb7649c8..131a79dba92f 100644 --- a/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/tests/PetApiTest.php @@ -1,6 +1,6 @@ id = $new_pet_id; $new_pet->name = "PHP Unit Test"; // new tag - $tag= new SwaggerClient\models\Tag; + $tag= new Swagger\Client\Model\Tag; $tag->id = $new_pet_id; // use the same id as pet $tag->name = "test php tag"; // new category - $category = new SwaggerClient\models\Category; + $category = new Swagger\Client\Model\Category; $category->id = $new_pet_id; // use the same id as pet $category->name = "test php category"; $new_pet->tags = array($tag); $new_pet->category = $category; - $pet_api = new SwaggerClient\PetAPI(); + $pet_api = new Swagger\Client\Api\PetAPI(); // add a new pet (model) $add_response = $pet_api->addPet($new_pet); } @@ -45,7 +45,7 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testApiClient() { // test selectHeaderAccept - $api_client = new SwaggerClient\ApiClient(); + $api_client = new Swagger\Client\ApiClient(); $this->assertSame('application/json', $api_client->selectHeaderAccept(array('application/xml','application/json'))); $this->assertSame(NULL, $api_client->selectHeaderAccept(array())); $this->assertSame('application/yaml,application/xml', $api_client->selectHeaderAccept(array('application/yaml','application/xml'))); @@ -67,22 +67,22 @@ class PetApiTest extends \PHPUnit_Framework_TestCase $defaultHeader = $api_client->getDefaultHeader(); $this->assertFalse(isset($defaultHeader['test2'])); - $pet_api = new SwaggerClient\PetAPI(); - $pet_api2 = new SwaggerClient\PetAPI(); - $apiClient3 = new SwaggerClient\ApiClient(); + $pet_api = new Swagger\Client\Api\PetAPI(); + $pet_api2 = new Swagger\Client\Api\PetAPI(); + $apiClient3 = new Swagger\Client\ApiClient(); $apiClient3->setUserAgent = 'api client 3'; - $apiClient4 = new SwaggerClient\ApiClient(); + $apiClient4 = new Swagger\Client\ApiClient(); $apiClient4->setUserAgent = 'api client 4'; - $pet_api3 = new SwaggerClient\PetAPI($apiClient3); + $pet_api3 = new Swagger\Client\Api\PetAPI($apiClient3); // same default api client $this->assertSame($pet_api->getApiClient(), $pet_api2->getApiClient()); // confirm using the default api client in the Configuration - $this->assertSame($pet_api->getApiClient(), SwaggerClient\Configuration::$apiClient); + $this->assertSame($pet_api->getApiClient(), Swagger\Client\Configuration::$apiClient); // 2 different api clients are not the same $this->assertNotEquals($apiClient3, $apiClient4); // customized pet api not using the default (configuration) api client - $this->assertNotEquals($pet_api3->getApiClient(), SwaggerClient\Configuration::$apiClient); + $this->assertNotEquals($pet_api3->getApiClient(), Swagger\Client\Configuration::$apiClient); // customied pet api not using the old pet api's api client $this->assertNotEquals($pet_api2->getApiClient(), $pet_api3->getApiClient()); @@ -96,10 +96,10 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testGetPetById() { // initialize the API client without host - $api_client = new SwaggerClient\ApiClient(); - SwaggerClient\Configuration::$apiKey['api_key'] = '111222333444555'; + $api_client = new Swagger\Client\ApiClient(); + Swagger\Client\Configuration::$apiKey['api_key'] = '111222333444555'; $pet_id = 10005; // ID of pet that needs to be fetched - $pet_api = new SwaggerClient\PetAPI($api_client); + $pet_api = new Swagger\Client\Api\PetAPI($api_client); // return Pet (model) $response = $pet_api->getPetById($pet_id); $this->assertSame($response->id, $pet_id); @@ -114,12 +114,12 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testFindPetByStatus() { // initialize the API client - $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); - $pet_api = new SwaggerClient\PetAPI($api_client); + $api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2'); + $pet_api = new Swagger\Client\Api\PetAPI($api_client); // return Pet (model) $response = $pet_api->findPetsByStatus("available"); $this->assertGreaterThan(0, count($response)); // at least one object returned - $this->assertSame(get_class($response[0]), "SwaggerClient\models\Pet"); // verify the object is Pet + $this->assertSame(get_class($response[0]), "Swagger\\Client\\Model\\Pet"); // verify the object is Pet // loop through result to ensure status is "available" foreach ($response as $_pet) { $this->assertSame($_pet['status'], "available"); @@ -133,11 +133,11 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testUpdatePet() { // initialize the API client - $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); + $api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2'); $pet_id = 10001; // ID of pet that needs to be fetched - $pet_api = new SwaggerClient\PetAPI($api_client); + $pet_api = new Swagger\Client\Api\PetAPI($api_client); // create updated pet object - $updated_pet = new SwaggerClient\models\Pet; + $updated_pet = new Swagger\Client\Model\Pet; $updated_pet->id = $pet_id; $updated_pet->name = 'updatePet'; // new name $updated_pet->status = 'pending'; // new status @@ -156,9 +156,9 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testUpdatePetWithForm() { // initialize the API client - $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); + $api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2'); $pet_id = 10001; // ID of pet that needs to be fetched - $pet_api = new SwaggerClient\PetAPI($api_client); + $pet_api = new Swagger\Client\Api\PetAPI($api_client); // update Pet (form) $update_response = $pet_api->updatePetWithForm($pet_id, 'update pet with form', 'sold'); // return nothing (void) @@ -173,12 +173,12 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testAddPet() { // initialize the API client - $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); + $api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2'); $new_pet_id = 10001; - $new_pet = new SwaggerClient\models\Pet; + $new_pet = new Swagger\Client\Model\Pet; $new_pet->id = $new_pet_id; $new_pet->name = "PHP Unit Test"; - $pet_api = new SwaggerClient\PetAPI($api_client); + $pet_api = new Swagger\Client\Api\PetAPI($api_client); // add a new pet (model) $add_response = $pet_api->addPet($new_pet); // return nothing (void) @@ -193,8 +193,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testUploadFile() { // initialize the API client - $api_client = new SwaggerClient\ApiClient('http://petstore.swagger.io/v2'); - $pet_api = new SwaggerClient\PetAPI($api_client); + $api_client = new Swagger\Client\ApiClient('http://petstore.swagger.io/v2'); + $pet_api = new Swagger\Client\Api\PetAPI($api_client); // upload file $pet_id = 10001; $add_response = $pet_api->uploadFile($pet_id, "test meta", "./composer.json"); @@ -206,8 +206,8 @@ class PetApiTest extends \PHPUnit_Framework_TestCase public function testGetInventory() { // initialize the API client - $api_client = new SwaggerClient\APIClient('http://petstore.swagger.io/v2'); - $store_api = new SwaggerClient\StoreAPI($api_client); + $api_client = new Swagger\Client\APIClient('http://petstore.swagger.io/v2'); + $store_api = new Swagger\Client\Api\StoreAPI($api_client); // get inventory $get_response = $store_api->getInventory();