Skip to content

Commit 9105b07

Browse files
committed
empty response check
1 parent 525d3d9 commit 9105b07

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

src/SDK/Language/PHP.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Appwrite\SDK\Language;
44

55
use Appwrite\SDK\Language;
6+
use Twig\TwigFilter;
67

78
class PHP extends Language {
89

@@ -356,4 +357,21 @@ protected function jsonToAssoc(array $data):string
356357

357358
return $output;
358359
}
360+
361+
protected function getReturn(array $method): string
362+
{
363+
if(($method['emptyResponse'] ?? true) || $method['type'] === 'location') {
364+
return 'string';
365+
}
366+
367+
return 'array';
368+
}
369+
370+
public function getFilters(): array {
371+
return [
372+
new TwigFilter('getReturn', function($value) {
373+
return $this->getReturn($value);
374+
})
375+
];
376+
}
359377
}

src/Spec/Swagger2.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ public function getMethods($service)
149149

150150
$responses = $method['responses'];
151151
$responseModel = '';
152+
$emptyResponse = true;
152153
foreach($responses as $code => $desc) {
154+
if($code != '204') {
155+
$emptyResponse = false;
156+
}
153157
if(isset($desc['schema']) && isset($desc['schema']['$ref'])) {
154158
$responseModel = $desc['schema']['$ref'];
155159
if(!empty($responseModel)) {
@@ -178,6 +182,7 @@ public function getMethods($service)
178182
'query' => [],
179183
'body' => [],
180184
],
185+
'emptyResponse' => $emptyResponse,
181186
'responseModel' => $responseModel,
182187
];
183188

templates/php/src/Services/Service.php.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class {{ service.name | caseUcfirst }} extends Service
2020
* @param {{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}
2121
{% endfor %}
2222
* @throws {{spec.title | caseUcfirst}}Exception
23-
* @return {% if (method.type == 'location') %}string{% else %}array{% endif %}
23+
* @return {{ method | getReturn }}
2424
2525
*/
26-
public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {% if (method.type == 'location') %}string{% else %}array{% endif %}
26+
public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{{ parameter.type | typeName }}${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }}
2727
2828
{
2929
{% for parameter in method.parameters.all %}

0 commit comments

Comments
 (0)