Skip to content

Commit dcaf639

Browse files
committed
Merge branch 'STRML-fixPHPFormParams'
2 parents 154c28b + 2f6bf95 commit dcaf639

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

src/main/resources/php/api.mustache

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,69 +22,78 @@
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}}
3030
/**
3131
* {{nickname}}
3232
* {{summary}}
33-
*
3433
{{#allParams}}
3534
* @param {{dataType}} ${{paramName}} {{description}} ({{^optional}}required{{/optional}}{{#optional}}optional{{/optional}})
3635
{{/allParams}}
37-
* @return {{returnType}}
38-
*/
36+
* @return {{returnType}}
37+
*/
3938

4039
public function {{nickname}}({{#allParams}}${{paramName}}{{#optional}}=null{{/optional}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
4140
42-
//parse inputs
43-
$resourcePath = "{{path}}";
44-
$resourcePath = str_replace("{format}", "json", $resourcePath);
45-
$method = "{{httpMethod}}";
41+
//parse inputs
42+
$resourcePath = "{{path}}";
43+
$resourcePath = str_replace("{format}", "json", $resourcePath);
44+
$method = "{{httpMethod}}";
4645
$queryParams = array();
4746
$headerParams = array();
4847
$headerParams['Accept'] = '{{#produces}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/produces}}';
4948
$headerParams['Content-Type'] = '{{#consumes}}{{mediaType}}{{#hasMore}},{{/hasMore}}{{/consumes}}';
5049
5150
{{#queryParams}}
52-
if(${{paramName}} != null) {
53-
$queryParams['{{paramName}}'] = $this->apiClient->toQueryValue(${{paramName}});
54-
}
55-
{{/queryParams}}
51+
if(${{paramName}} != null) {
52+
$queryParams['{{paramName}}'] = $this->apiClient->toQueryValue(${{paramName}});
53+
}
54+
{{/queryParams}}
5655

5756
{{#headerParams}}
58-
if(${{paramName}} != null) {
59-
$headerParams['{{paramName}}'] = $this->apiClient->toHeaderValue(${{paramName}});
60-
}
57+
if(${{paramName}} != null) {
58+
$headerParams['{{paramName}}'] = $this->apiClient->toHeaderValue(${{paramName}});
59+
}
6160
{{/headerParams}}
6261

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

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

7887

7988
{{#returnType}}
8089

8190
if(! $response){
8291
return null;
83-
}
92+
}
8493

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

8998
{{/returnType}}
9099
}

0 commit comments

Comments
 (0)