From 7c342a060a24fabf5362c48aac46a89790d2e8b4 Mon Sep 17 00:00:00 2001 From: Samuel Reed Date: Wed, 21 Jan 2015 10:01:41 +0100 Subject: [PATCH] Add missing formParams to PHP api.mustache. Fixes #383. Also fixed mixed tabs and spaces in template. --- src/main/resources/php/api.mustache | 74 ++++++++++++++++------------- 1 file changed, 42 insertions(+), 32 deletions(-) diff --git a/src/main/resources/php/api.mustache b/src/main/resources/php/api.mustache index 727f37b2136..f8f2bcf5218 100644 --- a/src/main/resources/php/api.mustache +++ b/src/main/resources/php/api.mustache @@ -22,69 +22,79 @@ {{#operations}} class {{classname}} { - function __construct($apiClient) { - $this->apiClient = $apiClient; - } + function __construct($apiClient) { + $this->apiClient = $apiClient; + } {{#operation}} - /** - * {{nickname}} - * {{summary}} + /** + * {{nickname}} + * {{summary}} {{#allParams}} * {{paramName}}, {{dataType}}: {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}} {{newline}} {{/allParams}} - * @return {{returnType}} - */ + * @return {{returnType}} + */ public function {{nickname}}({{#allParams}}${{paramName}}{{#optional}}=null{{/optional}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - //parse inputs - $resourcePath = "{{path}}"; - $resourcePath = str_replace("{format}", "json", $resourcePath); - $method = "{{httpMethod}}"; + //parse inputs + $resourcePath = "{{path}}"; + $resourcePath = str_replace("{format}", "json", $resourcePath); + $method = "{{httpMethod}}"; $queryParams = array(); $headerParams = array(); $headerParams['Accept'] = '{{#produces}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/produces}}'; $headerParams['Content-Type'] = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}'; {{#queryParams}} - if(${{paramName}} != null) { - $queryParams['{{paramName}}'] = $this->apiClient->toQueryValue(${{paramName}}); - } - {{/queryParams}} + if(${{paramName}} != null) { + $queryParams['{{paramName}}'] = $this->apiClient->toQueryValue(${{paramName}}); + } + {{/queryParams}} {{#headerParams}} - if(${{paramName}} != null) { - $headerParams['{{paramName}}'] = $this->apiClient->toHeaderValue(${{paramName}}); - } + if(${{paramName}} != null) { + $headerParams['{{paramName}}'] = $this->apiClient->toHeaderValue(${{paramName}}); + } {{/headerParams}} {{#pathParams}} - if(${{paramName}} != null) { - $resourcePath = str_replace("{" . "{{paramName}}" . "}", - $this->apiClient->toPathValue(${{paramName}}), $resourcePath); - } - {{/pathParams}} + if(${{paramName}} != null) { + $resourcePath = str_replace("{" . "{{paramName}}" . "}", + $this->apiClient->toPathValue(${{paramName}}), $resourcePath); + } + {{/pathParams}} - //make the API Call + // Generate form params if (! isset($body)) { + $body = array(); + } + {{#formParams}} + if(${{paramName}} != null) { + $body['{{paramName}}'] = ${{paramName}}; + } + {{/formParams}} + if (empty($body)) { $body = null; } - $response = $this->apiClient->callAPI($resourcePath, $method, - $queryParams, $body, - $headerParams); + + // Make the API Call + $response = $this->apiClient->callAPI($resourcePath, $method, + $queryParams, $body, + $headerParams); {{#returnType}} if(! $response){ return null; - } + } - $responseObject = $this->apiClient->deserialize($response, - '{{returnType}}'); - return $responseObject; + $responseObject = $this->apiClient->deserialize($response, + '{{returnType}}'); + return $responseObject; {{/returnType}} }