From 5347915c12269f26882f5c2e24395507525f2554 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Wed, 11 Mar 2015 21:14:17 +0800 Subject: [PATCH] form parameter(single quote), add more comment --- .../src/main/resources/php/api.mustache | 5 ++-- samples/client/petstore/php/PetApi.php | 24 ++++++++++++------- samples/client/petstore/php/StoreApi.php | 4 ++++ samples/client/petstore/php/Swagger.php | 3 +++ samples/client/petstore/php/UserApi.php | 8 +++++++ 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/php/api.mustache b/modules/swagger-codegen/src/main/resources/php/api.mustache index 9a360aa7ff0..7a36c9aa0a3 100644 --- a/modules/swagger-codegen/src/main/resources/php/api.mustache +++ b/modules/swagger-codegen/src/main/resources/php/api.mustache @@ -61,9 +61,9 @@ class {{classname}} { $resourcePath = str_replace("{" . "{{baseName}}" . "}", $this->apiClient->toPathValue(${{paramName}}), $resourcePath); }{{/pathParams}} - {{#formParams}} + {{#formParams}}// form params if (${{paramName}} !== null) { - $formParams[{{baseName}}] = {{#isFile}}'@' . {{/isFile}}${{paramName}}; + $formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}${{paramName}}; }{{/formParams}} {{#bodyParams}}// body params $body = null; @@ -71,6 +71,7 @@ class {{classname}} { $body = ${{paramName}}; }{{/bodyParams}} + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { diff --git a/samples/client/petstore/php/PetApi.php b/samples/client/petstore/php/PetApi.php index da31002dcbb..8c7d74cb474 100644 --- a/samples/client/petstore/php/PetApi.php +++ b/samples/client/petstore/php/PetApi.php @@ -57,6 +57,7 @@ class PetApi { $body = $body; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -102,6 +103,7 @@ class PetApi { $body = $body; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -146,6 +148,7 @@ class PetApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -196,6 +199,7 @@ class PetApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -247,6 +251,7 @@ class PetApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -297,15 +302,16 @@ class PetApi { $resourcePath = str_replace("{" . "petId" . "}", $this->apiClient->toPathValue($petId), $resourcePath); } - + // form params if ($name !== null) { - $formParams[name] = $name; - } + $formParams['name'] = $name; + }// form params if ($status !== null) { - $formParams[status] = $status; + $formParams['status'] = $status; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -355,6 +361,7 @@ class PetApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -399,15 +406,16 @@ class PetApi { $resourcePath = str_replace("{" . "petId" . "}", $this->apiClient->toPathValue($petId), $resourcePath); } - + // form params if ($additionalMetadata !== null) { - $formParams[additionalMetadata] = $additionalMetadata; - } + $formParams['additionalMetadata'] = $additionalMetadata; + }// form params if ($file !== null) { - $formParams[file] = '@' . $file; + $formParams['file'] = '@' . $file; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { diff --git a/samples/client/petstore/php/StoreApi.php b/samples/client/petstore/php/StoreApi.php index 0496c08d2e8..780012f09aa 100644 --- a/samples/client/petstore/php/StoreApi.php +++ b/samples/client/petstore/php/StoreApi.php @@ -52,6 +52,7 @@ class StoreApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -103,6 +104,7 @@ class StoreApi { $body = $body; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -154,6 +156,7 @@ class StoreApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -205,6 +208,7 @@ class StoreApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { diff --git a/samples/client/petstore/php/Swagger.php b/samples/client/petstore/php/Swagger.php index a7a18866345..d797bb53e9e 100644 --- a/samples/client/petstore/php/Swagger.php +++ b/samples/client/petstore/php/Swagger.php @@ -107,6 +107,9 @@ class APIClient { 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); diff --git a/samples/client/petstore/php/UserApi.php b/samples/client/petstore/php/UserApi.php index 697af96328b..cd5d197394b 100644 --- a/samples/client/petstore/php/UserApi.php +++ b/samples/client/petstore/php/UserApi.php @@ -57,6 +57,7 @@ class UserApi { $body = $body; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -102,6 +103,7 @@ class UserApi { $body = $body; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -147,6 +149,7 @@ class UserApi { $body = $body; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -195,6 +198,7 @@ class UserApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -241,6 +245,7 @@ class UserApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -286,6 +291,7 @@ class UserApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -342,6 +348,7 @@ class UserApi { $body = $body; } + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) { @@ -387,6 +394,7 @@ class UserApi { + // for HTTP post (form) $body = $body ?: $formParams; if (strpos($headerParams['Content-Type'], "application/x-www-form-urlencoded") > -1) {