Skip to content

Commit

Permalink
Merge pull request #70 from appwrite/feat-new-swagger-format
Browse files Browse the repository at this point in the history
Feat new (Appwrite) swagger format support
  • Loading branch information
eldadfux authored Dec 23, 2020
2 parents d35f27e + b17ca38 commit 30c178c
Show file tree
Hide file tree
Showing 3 changed files with 1,767 additions and 562 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ notifications:
email:
- team@appwrite.io

before_install:
- echo 'DOCKER_OPTS="$DOCKER_OPTS --registry-mirror=https://mirror.gcr.io"'
- sudo service docker restart

install:
- composer install

Expand Down
32 changes: 25 additions & 7 deletions src/Spec/Swagger2.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ public function getMethods($service)

foreach ($method['parameters'] as $parameter) {
$param = [
'name' => $parameter['name'],
'type' => $parameter['type'],
'description' => $parameter['description'],
'required' => (int)$parameter['required'],
'name' => $parameter['name'] ?? null,
'type' => $parameter['type'] ?? null,
'description' => $parameter['description'] ?? '',
'required' => (int)($parameter['required'] ?? 0),
'default' => $parameter['default'] ?? null,
'example' => $parameter['x-example'] ?? null,
'array' => [
Expand All @@ -180,8 +180,6 @@ public function getMethods($service)

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

$output['parameters']['all'][] = $param;

switch ($parameter['in']) {
case 'header':
$output['parameters']['header'][] = $param;
Expand All @@ -192,11 +190,31 @@ public function getMethods($service)
case 'query':
$output['parameters']['query'][] = $param;
break;
case 'body':
case 'formData':
$output['parameters']['body'][] = $param;
break;
case 'body':
$bodyProperties = $parameter['schema']['properties'] ?? [];
$bodyRequired = $parameter['schema']['required'] ?? [];

foreach ($bodyProperties as $key => $value) {
$param['name'] = $key;
$param['type'] = $value['type'] ?? null;
$param['description'] = $value['description'] ?? '';
$param['required'] = (in_array($key, $bodyRequired));
$param['default'] = $value['default'] ?? null;
$param['example'] = $value['x-example'] ?? null;

$output['parameters']['body'][] = $param;
$output['parameters']['all'][] = $param;
}

continue 2;

break;
}

$output['parameters']['all'][] = $param;
}

usort($output['parameters']['all'], function ($a, $b) {
Expand Down
Loading

0 comments on commit 30c178c

Please sign in to comment.