Skip to content

Commit 7c342a0

Browse files
committed
Add missing formParams to PHP api.mustache. Fixes #383.
Also fixed mixed tabs and spaces in template.
1 parent 3abc42e commit 7c342a0

File tree

1 file changed

+42
-32
lines changed

1 file changed

+42
-32
lines changed

src/main/resources/php/api.mustache

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,79 @@
2222
{{#operations}}
2323
class {{classname}} {
2424
25-
function __construct($apiClient) {
26-
$this->apiClient = $apiClient;
27-
}
25+
function __construct($apiClient) {
26+
$this->apiClient = $apiClient;
27+
}
2828

2929
{{#operation}}
30-
/**
31-
* {{nickname}}
32-
* {{summary}}
30+
/**
31+
* {{nickname}}
32+
* {{summary}}
3333
{{#allParams}}
3434
* {{paramName}}, {{dataType}}: {{description}} {{^optional}}(required){{/optional}}{{#optional}}(optional){{/optional}}
3535
{{newline}}
3636
{{/allParams}}
37-
* @return {{returnType}}
38-
*/
37+
* @return {{returnType}}
38+
*/
3939

4040
public function {{nickname}}({{#allParams}}${{paramName}}{{#optional}}=null{{/optional}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
4141
42-
//parse inputs
43-
$resourcePath = "{{path}}";
44-
$resourcePath = str_replace("{format}", "json", $resourcePath);
45-
$method = "{{httpMethod}}";
42+
//parse inputs
43+
$resourcePath = "{{path}}";
44+
$resourcePath = str_replace("{format}", "json", $resourcePath);
45+
$method = "{{httpMethod}}";
4646
$queryParams = array();
4747
$headerParams = array();
4848
$headerParams['Accept'] = '{{#produces}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/produces}}';
4949
$headerParams['Content-Type'] = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}';
5050
5151
{{#queryParams}}
52-
if(${{paramName}} != null) {
53-
$queryParams['{{paramName}}'] = $this->apiClient->toQueryValue(${{paramName}});
54-
}
55-
{{/queryParams}}
52+
if(${{paramName}} != null) {
53+
$queryParams['{{paramName}}'] = $this->apiClient->toQueryValue(${{paramName}});
54+
}
55+
{{/queryParams}}
5656

5757
{{#headerParams}}
58-
if(${{paramName}} != null) {
59-
$headerParams['{{paramName}}'] = $this->apiClient->toHeaderValue(${{paramName}});
60-
}
58+
if(${{paramName}} != null) {
59+
$headerParams['{{paramName}}'] = $this->apiClient->toHeaderValue(${{paramName}});
60+
}
6161
{{/headerParams}}
6262

6363
{{#pathParams}}
64-
if(${{paramName}} != null) {
65-
$resourcePath = str_replace("{" . "{{paramName}}" . "}",
66-
$this->apiClient->toPathValue(${{paramName}}), $resourcePath);
67-
}
68-
{{/pathParams}}
64+
if(${{paramName}} != null) {
65+
$resourcePath = str_replace("{" . "{{paramName}}" . "}",
66+
$this->apiClient->toPathValue(${{paramName}}), $resourcePath);
67+
}
68+
{{/pathParams}}
6969

70-
//make the API Call
70+
// Generate form params
7171
if (! isset($body)) {
72+
$body = array();
73+
}
74+
{{#formParams}}
75+
if(${{paramName}} != null) {
76+
$body['{{paramName}}'] = ${{paramName}};
77+
}
78+
{{/formParams}}
79+
if (empty($body)) {
7280
$body = null;
7381
}
74-
$response = $this->apiClient->callAPI($resourcePath, $method,
75-
$queryParams, $body,
76-
$headerParams);
82+
83+
// Make the API Call
84+
$response = $this->apiClient->callAPI($resourcePath, $method,
85+
$queryParams, $body,
86+
$headerParams);
7787

7888

7989
{{#returnType}}
8090

8191
if(! $response){
8292
return null;
83-
}
93+
}
8494

85-
$responseObject = $this->apiClient->deserialize($response,
86-
'{{returnType}}');
87-
return $responseObject;
95+
$responseObject = $this->apiClient->deserialize($response,
96+
'{{returnType}}');
97+
return $responseObject;
8898

8999
{{/returnType}}
90100
}

0 commit comments

Comments
 (0)