Skip to content

Commit 30c178c

Browse files
authored
Merge pull request #70 from appwrite/feat-new-swagger-format
Feat new (Appwrite) swagger format support
2 parents d35f27e + b17ca38 commit 30c178c

File tree

3 files changed

+1767
-562
lines changed

3 files changed

+1767
-562
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ notifications:
77
email:
88
99

10+
before_install:
11+
- echo 'DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=https://mirror.gcr.io"'
12+
- sudo service docker restart
13+
1014
install:
1115
- composer install
1216

src/Spec/Swagger2.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ public function getMethods($service)
167167

168168
foreach ($method['parameters'] as $parameter) {
169169
$param = [
170-
'name' => $parameter['name'],
171-
'type' => $parameter['type'],
172-
'description' => $parameter['description'],
173-
'required' => (int)$parameter['required'],
170+
'name' => $parameter['name'] ?? null,
171+
'type' => $parameter['type'] ?? null,
172+
'description' => $parameter['description'] ?? '',
173+
'required' => (int)($parameter['required'] ?? 0),
174174
'default' => $parameter['default'] ?? null,
175175
'example' => $parameter['x-example'] ?? null,
176176
'array' => [
@@ -180,8 +180,6 @@ public function getMethods($service)
180180

181181
$param['default'] = (is_array($param['default'])) ? json_encode($param['default']): $param['default'];
182182

183-
$output['parameters']['all'][] = $param;
184-
185183
switch ($parameter['in']) {
186184
case 'header':
187185
$output['parameters']['header'][] = $param;
@@ -192,11 +190,31 @@ public function getMethods($service)
192190
case 'query':
193191
$output['parameters']['query'][] = $param;
194192
break;
195-
case 'body':
196193
case 'formData':
197194
$output['parameters']['body'][] = $param;
198195
break;
196+
case 'body':
197+
$bodyProperties = $parameter['schema']['properties'] ?? [];
198+
$bodyRequired = $parameter['schema']['required'] ?? [];
199+
200+
foreach ($bodyProperties as $key => $value) {
201+
$param['name'] = $key;
202+
$param['type'] = $value['type'] ?? null;
203+
$param['description'] = $value['description'] ?? '';
204+
$param['required'] = (in_array($key, $bodyRequired));
205+
$param['default'] = $value['default'] ?? null;
206+
$param['example'] = $value['x-example'] ?? null;
207+
208+
$output['parameters']['body'][] = $param;
209+
$output['parameters']['all'][] = $param;
210+
}
211+
212+
continue 2;
213+
214+
break;
199215
}
216+
217+
$output['parameters']['all'][] = $param;
200218
}
201219

202220
usort($output['parameters']['all'], function ($a, $b) {

0 commit comments

Comments
 (0)