Skip to content

Commit ee4ea1c

Browse files
committed
Differentiate method auth and method security
1 parent 67b3422 commit ee4ea1c

File tree

27 files changed

+58
-55
lines changed

27 files changed

+58
-55
lines changed

src/Spec/Swagger2.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,15 @@ public function getMethods($service)
137137

138138
foreach ($paths as $pathName => $path) {
139139
foreach ($path as $methodName => $method) {
140-
$auth = $method['x-appwrite']['auth'] ?? [];
140+
$methodAuth = $method['x-appwrite']['auth'] ?? [];
141+
$methodSecurity = $method['security'][0] ?? [];
141142

142143
if (isset($method['tags']) && is_array($method['tags']) && in_array($service, $method['tags'])) {
143-
if (isset($auth) && is_array($auth)) {
144-
foreach ($auth as $i => $node) {
145-
$auth[$i] = (array_key_exists($i, $security)) ? $security[$i] : [];
146-
}
144+
foreach ($methodAuth as $i => $node) {
145+
$methodAuth[$i] = (array_key_exists($i, $security)) ? $security[$i] : [];
146+
}
147+
foreach ($methodSecurity as $i => $node) {
148+
$methodSecurity[$i] = (array_key_exists($i, $security)) ? $security[$i] : [];
147149
}
148150

149151
$responses = $method['responses'];
@@ -169,7 +171,8 @@ public function getMethods($service)
169171
'packaging' => $method['x-appwrite']['packaging'] ?? false,
170172
'title' => $method['summary'] ?? '',
171173
'description' => $method['description'] ?? '',
172-
'security' => [$auth] ?? [],
174+
'auth' => [$methodAuth] ?? [],
175+
'security' => [$methodSecurity] ?? [],
173176
'consumes' => $method['consumes'] ?? [],
174177
'cookies' => $method['x-appwrite']['cookies'] ?? false,
175178
'type' => $method['x-appwrite']['type'] ?? false,

templates/android/docs/java/example.md.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public class MainActivity extends AppCompatActivity {
1616
setContentView(R.layout.activity_main);
1717

1818
Client client = new Client(getApplicationContext())
19-
{% if method.security|length > 0 %}
19+
{% if method.auth|length > 0 %}
2020
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
21-
{% for node in method.security %}
21+
{% for node in method.auth %}
2222
{% for key,header in node|keys %}
2323
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}"){% if loop.last %};{% endif %} // {{node[header].description}}
2424
{% endfor %}

templates/android/docs/kotlin/example.md.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class MainActivity : AppCompatActivity() {
1414
setContentView(R.layout.activity_main)
1515

1616
val client = Client(applicationContext)
17-
{% if method.security|length > 0 %}
17+
{% if method.auth|length > 0 %}
1818
.setEndpoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
19-
{% for node in method.security %}
19+
{% for node in method.auth %}
2020
{% for key,header in node|keys %}
2121
.set{{header | caseUcfirst}}("{{node[header]['x-appwrite']['demo']}}") // {{node[header].description}}
2222
{% endfor %}

templates/android/library/src/main/java/io/appwrite/services/ServiceTemplate.kt.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% if parameters.all|length > 0 %}{% for parameter in parameters.all %}{{ '\n\t\t' }}{{ _self.parameter(parameter) }}{% if not loop.last %}{{ ',' }}{% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, onProgress: ((UploadProgress) -> Unit)? = null{% endif %}{% endif %}
44
{% endmacro %}
55
{% macro methodNeedsSecurityParameters(method) %}
6-
{% if (method.type == "webAuth" or method.type == "location") and method.security|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
6+
{% if (method.type == "webAuth" or method.type == "location") and method.auth|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
77
{% endmacro %}
88
{% macro resultType(namespace, method) %}
99
{% if method.type == "webAuth" %}Bool{% elseif method.type == "location" %}ByteArray{% elseif not method.responseModel or method.responseModel == 'any' %}Any{% else %}{{ namespace | caseDot}}.models.{{method.responseModel | caseUcfirst}}{% endif %}
@@ -55,7 +55,7 @@ class {{ service.name | caseUcfirst }} : Service {
5555

5656
{% endfor %}
5757
{% if _self.methodNeedsSecurityParameters(method) %}
58-
{% for node in method.security %}
58+
{% for node in method.auth %}
5959
{% for key,header in node|keys %}
6060
"{{header|caseLower}}" to client.config["{{header|caseLower}}"]{% if not loop.last %},{% endif %}
6161

templates/dart/base/requests/location.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
final Map<String, dynamic> params = {
33
{{ utils.map_parameter(method.parameters.query) }}
44
{{ utils.map_parameter(method.parameters.body) }}
5-
{% if method.security|length > 0 %}{% for node in method.security %}
5+
{% if method.auth|length > 0 %}{% for node in method.auth %}
66
{% for key,header in node|keys %}
77
'{{header|caseLower}}': client.config['{{header|caseLower}}'],
88
{% endfor %}

templates/dart/base/requests/oauth.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
final Map<String, dynamic> params = {
33
{{ utils.map_parameter(method.parameters.query) }}
44
{{ utils.map_parameter(method.parameters.body) }}
5-
{% if method.security|length > 0 %}
6-
{% for node in method.security %}
5+
{% if method.auth|length > 0 %}
6+
{% for node in method.auth %}
77
{% for key,header in node|keys %}
88
'{{header|caseLower}}': client.config['{{header|caseLower}}'],
99
{% endfor %}

templates/dart/docs/example.md.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ void main() { // Init SDK
77
Client client = Client();
88
{{ service.name | caseUcfirst }} {{ service.name | caseCamel }} = {{service.name | caseUcfirst}}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter.name | caseCamel | overrideIdentifier }}: {{ parameter | paramExample }}{% endfor %}{% endif %});
99

10-
{% if method.security|length > 0 %}
10+
{% if method.auth|length > 0 %}
1111
client
1212
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
13-
{% for node in method.security %}
13+
{% for node in method.auth %}
1414
{% for key,header in node|keys %}
1515
.set{{header}}('{{node[header]['x-appwrite']['demo']}}') // {{node[header].description}}
1616
{% endfor %}

templates/deno/docs/example.md.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ let client = new sdk.Client();
88

99
let {{ service.name | caseCamel }} = new sdk.{{service.name | caseUcfirst}}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %});
1010

11-
{% if method.security|length > 0 %}
11+
{% if method.auth|length > 0 %}
1212
client
1313
.setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
14-
{% for node in method.security %}
14+
{% for node in method.auth %}
1515
{% for key,header in node|keys %}
1616
.set{{header}}('{{node[header]['x-appwrite']['demo']}}') // {{node[header].description}}
1717
{% endfor %}

templates/dotnet/docs/example.md.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ using {{ spec.title | caseUcfirst }};
22

33
Client client = new Client();
44

5-
{% if method.security|length > 0 %}
5+
{% if method.auth|length > 0 %}
66
client
77
.SetEndPoint("https://[HOSTNAME_OR_IP]/v1") // Your API Endpoint
8-
{% for node in method.security %}
8+
{% for node in method.auth %}
99
{% for key,header in node|keys %}
1010
.Set{{header | caseUcfirst}}("{{node[header]["x-appwrite"]["demo"]}}") // {{node[header].description}}
1111
{% endfor %}

templates/dotnet/src/Appwrite/Services/ServiceTemplate.cs.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{{ parameter.name | caseCamel | escapeKeyword }}{% endif %}
1111
{% endmacro %}
1212
{% macro methodNeedsSecurityParameters(method) %}
13-
{% if (method.type == "webAuth" or method.type == "location") and method.security|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
13+
{% if (method.type == "webAuth" or method.type == "location") and method.auth|length > 0 %}{{ true }}{% else %}{{false}}{% endif %}
1414
{% endmacro %}
1515

1616
using System.Collections.Generic;
@@ -46,7 +46,7 @@ namespace {{ spec.title | caseUcfirst }}
4646

4747
{% endfor %}
4848
};
49-
{% if _self.methodNeedsSecurityParameters(method) %}{% for node in method.security %}
49+
{% if _self.methodNeedsSecurityParameters(method) %}{% for node in method.auth %}
5050
{% for key,header in node|keys %}
5151
// { "{{header|caseLower}}", _client.GetConfig().get("{{header|caseLower}}") }{% if not loop.last %},{% endif %}
5252

0 commit comments

Comments
 (0)