Skip to content

Commit e685290

Browse files
committed
Merge remote-tracking branch 'origin/master' into feat-dotnet-response-models
2 parents 5006102 + 263ecd9 commit e685290

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1343
-624
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ env:
3232
- SDK=DotNet50
3333
- SDK=DotNet60
3434
- SDK=FlutterStable
35+
- SDK=FlutterBeta
3536
- SDK=Go112
3637
- SDK=Go118
37-
# - SDK=FlutterBeta
3838
- SDK=KotlinJava8
3939
- SDK=KotlinJava11
4040
- SDK=KotlinJava17

CONTRIBUTING.md

Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
**WORK IN PROGRESS - NOT READY FOR GENERAL USAGE**
1010

11-
[Appwrite](https://appwrite.io) SDK generator is a PHP library for auto generating SDK libraries for multiple languages and platforms.
11+
[Appwrite](https://appwrite.io) SDK generator is a PHP library for auto-generating SDK libraries for multiple languages and platforms.
1212

1313
The SDK Generator uses predefined language settings as [Twig templates](https://twig.symfony.com/) to generate codebases based on different API specs.
1414

15-
Currently, the only spec supported is Swagger 2.0, but we intend to add support for more specifications in the near future. This generator is still lacking support for any definition/models specs.
15+
Currently, the only spec supported is Swagger 2.0, but we intend to add support for more specifications in the near future. This generator is still lacking support for any definition/model specs.
1616

1717
## Getting Started
1818

@@ -134,7 +134,7 @@ $sdk->generate(__DIR__ . '/examples/php'); // Generate source code
134134

135135
## Contributing
136136

137-
All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
137+
All code contributions, including those by people with commit access, must go through a pull request and be approved by a core developer before being merged. This is to ensure proper review of all the code.
138138

139139
We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the [contribution guide](CONTRIBUTING.md).
140140

example.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
include_once 'vendor/autoload.php';
44

5+
use Appwrite\SDK\Language\GraphQL;
56
use Appwrite\Spec\Swagger2;
67
use Appwrite\SDK\SDK;
78
use Appwrite\SDK\Language\Web;
@@ -13,7 +14,7 @@
1314
use Appwrite\SDK\Language\Dart;
1415
use Appwrite\SDK\Language\Go;
1516
use Appwrite\SDK\Language\Deno;
16-
use Appwrite\SDK\Language\HTTP;
17+
use Appwrite\SDK\Language\REST;
1718
use Appwrite\SDK\Language\Swift;
1819
use Appwrite\SDK\Language\Apple;
1920
use Appwrite\SDK\Language\DotNet;
@@ -389,8 +390,8 @@ function getSSLPage($url) {
389390

390391
$sdk->generate(__DIR__ . '/examples/dotnet');
391392

392-
// HTTP
393-
$sdk = new SDK(new HTTP(), new Swagger2($spec));
393+
// REST
394+
$sdk = new SDK(new REST(), new Swagger2($spec));
394395

395396
$sdk
396397
->setName('NAME')
@@ -408,7 +409,7 @@ function getSSLPage($url) {
408409
->setDiscord('564160730845151244', 'https://appwrite.io/discord')
409410
;
410411

411-
$sdk->generate(__DIR__ . '/examples/HTTP');
412+
$sdk->generate(__DIR__ . '/examples/REST');
412413

413414
// Android
414415

@@ -458,6 +459,16 @@ function getSSLPage($url) {
458459
])
459460
;
460461
$sdk->generate(__DIR__ . '/examples/kotlin');
462+
463+
// GraphQL
464+
$sdk = new SDK(new GraphQL(), new Swagger2($spec));
465+
466+
$sdk
467+
->setName('GraphQL')
468+
->setDescription('Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Flutter SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to https://appwrite.io/docs')
469+
->setLogo('https://appwrite.io/v1/images/console.png')
470+
;
471+
$sdk->generate(__DIR__ . '/examples/graphql');
461472
}
462473
catch (Exception $exception) {
463474
echo 'Error: ' . $exception->getMessage() . ' on ' . $exception->getFile() . ':' . $exception->getLine() . "\n";

src/SDK/Language/Android.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ public function getFiles(): array
135135
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/extensions/JsonExtensions.kt',
136136
'template' => '/android/library/src/main/java/io/appwrite/extensions/JsonExtensions.kt.twig',
137137
],
138+
[
139+
'scope' => 'default',
140+
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/extensions/TypeExtensions.kt',
141+
'template' => '/android/library/src/main/java/io/appwrite/extensions/TypeExtensions.kt.twig',
142+
],
138143
[
139144
'scope' => 'default',
140145
'destination' => '/library/src/main/java/{{ sdk.namespace | caseSlash }}/extensions/CollectionExtensions.kt',

src/SDK/Language/GraphQL.php

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
<?php
2+
3+
namespace Appwrite\SDK\Language;
4+
5+
class GraphQL extends HTTP
6+
{
7+
/**
8+
* @return string
9+
*/
10+
public function getName(): string
11+
{
12+
return 'GraphQL';
13+
}
14+
15+
/**
16+
* @param $type
17+
* @return string
18+
*/
19+
public function getTypeName(array $parameter): string
20+
{
21+
$type = '';
22+
23+
switch ($parameter['type']) {
24+
case self::TYPE_INTEGER:
25+
$type = 'Int';
26+
break;
27+
case self::TYPE_STRING:
28+
$type = 'String';
29+
break;
30+
case self::TYPE_FILE:
31+
$type = 'InputFile';
32+
break;
33+
case self::TYPE_BOOLEAN:
34+
$type = 'Bool';
35+
break;
36+
case self::TYPE_ARRAY:
37+
if (!empty($parameter['array']['type'])) {
38+
$type = '[' . $this->getTypeName($parameter['array']) . ']';
39+
break;
40+
}
41+
$type = '[String]';
42+
break;
43+
case self::TYPE_OBJECT:
44+
$type = 'JSON';
45+
break;
46+
}
47+
48+
if (empty($type)) {
49+
$type = $parameter['type'];
50+
}
51+
52+
if ($parameter['required'] ?? false) {
53+
$type .= '!';
54+
}
55+
56+
return $type;
57+
}
58+
59+
/**
60+
* @param array $param
61+
* @return string
62+
*/
63+
public function getParamDefault(array $param): string
64+
{
65+
$type = $param['type'] ?? '';
66+
$default = $param['default'] ?? '';
67+
$required = $param['required'] ?? '';
68+
69+
if ($required) {
70+
return '';
71+
}
72+
73+
$output = '';
74+
75+
if (empty($default) && $default !== 0 && $default !== false) {
76+
switch ($type) {
77+
case self::TYPE_OBJECT:
78+
$output .= '{}';
79+
break;
80+
case self::TYPE_NUMBER:
81+
case self::TYPE_INTEGER:
82+
$output .= '0';
83+
break;
84+
case self::TYPE_BOOLEAN:
85+
$output .= 'false';
86+
break;
87+
case self::TYPE_ARRAY:
88+
$output .= '[]';
89+
break;
90+
case self::TYPE_STRING:
91+
$output .= '""';
92+
break;
93+
}
94+
} else {
95+
switch ($type) {
96+
case self::TYPE_OBJECT:
97+
case self::TYPE_NUMBER:
98+
case self::TYPE_ARRAY:
99+
case self::TYPE_INTEGER:
100+
$output .= $default;
101+
break;
102+
case self::TYPE_BOOLEAN:
103+
$output .= ($default) ? 'true' : 'false';
104+
break;
105+
case self::TYPE_STRING:
106+
$output .= '"' . $default . '"';
107+
break;
108+
}
109+
}
110+
111+
return $output;
112+
}
113+
114+
/**
115+
* @param array $param
116+
* @return string
117+
*/
118+
public function getParamExample(array $param): string
119+
{
120+
$type = $param['type'] ?? '';
121+
$example = $param['example'] ?? '';
122+
123+
$output = '';
124+
125+
if (empty($example) && $example !== 0 && $example !== false) {
126+
switch ($type) {
127+
case self::TYPE_FILE:
128+
$output .= 'null';
129+
break;
130+
case self::TYPE_NUMBER:
131+
case self::TYPE_INTEGER:
132+
$output .= '0';
133+
break;
134+
case self::TYPE_BOOLEAN:
135+
$output .= 'false';
136+
break;
137+
case self::TYPE_STRING:
138+
$output .= '""';
139+
break;
140+
case self::TYPE_OBJECT:
141+
$output .= '"{}"';
142+
break;
143+
case self::TYPE_ARRAY:
144+
$output .= '[]';
145+
break;
146+
}
147+
} else {
148+
switch ($type) {
149+
case self::TYPE_FILE:
150+
case self::TYPE_NUMBER:
151+
case self::TYPE_INTEGER:
152+
case self::TYPE_ARRAY:
153+
$output .= $example;
154+
break;
155+
case self::TYPE_STRING:
156+
case self::TYPE_OBJECT:
157+
$output .= '"' . $example . '"';
158+
break;
159+
case self::TYPE_BOOLEAN:
160+
$output .= ($example) ? 'true' : 'false';
161+
break;
162+
}
163+
}
164+
165+
return $output;
166+
}
167+
168+
/**
169+
* @return array
170+
*/
171+
public function getFiles(): array
172+
{
173+
return [
174+
[
175+
'scope' => 'method',
176+
'destination' => 'docs/examples/{{service.name | caseLower}}/{{method.name | caseDash}}.md',
177+
'template' => '/graphql/docs/example.md.twig',
178+
'exclude' => [
179+
'services' => [['name' => 'graphql']],
180+
'methods' => [['type' => 'webAuth']],
181+
],
182+
],
183+
];
184+
}
185+
}

0 commit comments

Comments
 (0)