Skip to content

Commit 4d75088

Browse files
committed
Merge remote-tracking branch 'origin/feat-service-level-params' into feat-service-level-params-more-langs
2 parents e170c34 + 62a1b53 commit 4d75088

File tree

8 files changed

+62
-35
lines changed

8 files changed

+62
-35
lines changed

specs/swagger2-latest-console.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use {{ spec.title | caseUcfirst }}\InputFile;
1010
class {{ service.name | caseUcfirst }} extends Service
1111
{
1212
{% if service.globalParams | length %}
13-
1413
{% for parameter in service.globalParams %}
1514
protected {{ parameter.type | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }};
1615

templates/ruby/lib/container/services/service.rb.twig

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
module {{spec.title | caseUcfirst}}
44
class {{ service.name | caseUcfirst }} < Service
55

6+
{% if service.globalParams | length %}
7+
{% for parameter in service.globalParams %}
8+
@{{ parameter.name | caseSnake | escapeKeyword }}{% if not parameter.required %}: nil{% endif %}
9+
{% endfor %}
10+
11+
def initialize(client, {% for parameter in service.globalParams %}{{ parameter.name | caseSnake | escapeKeyword }}:{% if not parameter.required %} nil{% endif %}{% if not loop.last %}, {% endif %}{% endfor %})
12+
@client = client
13+
{% for parameter in service.globalParams %}
14+
@{{ parameter.name | caseSnake | escapeKeyword }} = {{ parameter.name | caseSnake | escapeKeyword }}
15+
{% endfor %}
16+
end
17+
{% endif %}
18+
619
{% for method in service.methods %}
720
{{ method.description | rubyComment }}
821
#
@@ -11,23 +24,23 @@ module {{spec.title | caseUcfirst}}
1124
{% endfor %}
1225
#
1326
# @return [{{ method.responseModel | caseUcfirst }}]
14-
def {{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{{ parameter.name | caseSnake | escapeKeyword }}:{% if not parameter.required %} nil{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, on_progress: nil{% endif %})
27+
def {{ method.name | caseSnake }}({% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}{{ parameter.name | caseSnake | escapeKeyword }}:{% if not parameter.required %} nil{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, on_progress: nil{% endif %})
1528
{% for parameter in method.parameters.all %}
1629
{% if parameter.required %}
17-
if {{ parameter.name | caseSnake | escapeKeyword }}.nil?
30+
if {% if parameter.isGlobal %}@{% endif %}{{ parameter.name | caseSnake | escapeKeyword }}.nil?
1831
raise {{spec.title | caseUcfirst}}::Exception.new('Missing required parameter: "{{ parameter.name | caseCamel | escapeKeyword }}"')
1932
end
2033

2134
{% endif %}
2235
{% endfor %}
2336
path = '{{ method.path }}'
2437
{% for parameter in method.parameters.path %}
25-
.gsub('{{ '{' }}{{ parameter.name }}{{ '}' }}', {{ parameter.name | caseSnake | escapeKeyword }})
38+
.gsub('{{ '{' }}{{ parameter.name }}{{ '}' }}', {% if parameter.isGlobal %}@{% endif %}{{ parameter.name | caseSnake | escapeKeyword }})
2639
{% endfor %}
2740

2841
params = {
2942
{% for parameter in method.parameters.query | merge(method.parameters.body) %}
30-
{{ parameter.name }}: {{ parameter.name | caseSnake | escapeKeyword }},
43+
{{ parameter.name }}: {% if parameter.isGlobal %}@{% endif %}{{ parameter.name | caseSnake | escapeKeyword }},
3144
{% endfor %}
3245
}
3346

templates/swift/Sources/Services/Service.swift.twig

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ import NIO
1010
import {{spec.title | caseUcfirst}}Models
1111

1212
open class {{ service.name | caseUcfirst }}: Service {
13+
{% if service.globalParams | length %}
14+
{% for parameter in service.globalParams %}
15+
var {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName }}{% if not parameter.required %}?{% endif %}
16+
{% endfor %}
17+
18+
19+
public init(_ client: Client, {% for parameter in service.globalParams %}_ {{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName }}{% if not parameter.required %}? = nil{% endif %}{% if not loop.last %}, {% endif %}{% endfor %})
20+
{
21+
{% for parameter in service.globalParams %}
22+
self.{{ parameter.name | caseCamel | escapeKeyword }} = {{ parameter.name | caseCamel | escapeKeyword }}
23+
{% endfor %}
24+
super.init(client)
25+
}
26+
27+
{% endif %}
1328
{% for method in service.methods %}
1429
///
1530
/// {{ method.title }}
@@ -28,7 +43,7 @@ open class {{ service.name | caseUcfirst }}: Service {
2843
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
2944
{% endif %}
3045
open func {{ method.name | caseCamel }}(
31-
{% for parameter in method.parameters.all %}
46+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
3247
{{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName | raw }}{% if not parameter.required %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes %},{% endif %}
3348

3449
{% endfor %}
@@ -40,7 +55,7 @@ open class {{ service.name | caseUcfirst }}: Service {
4055
{% for parameter in method.parameters.path %}
4156
path = path.replacingOccurrences(
4257
of: "{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}",
43-
with: {% if method.parameters.path %}{{ parameter.name | caseCamel | escapeKeyword }}{% else %}""{% endif %}
58+
with: {% if method.parameters.path %}{% if parameter.isGlobal %}self.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% else %}""{% endif %}
4459

4560
)
4661
{% endfor %}
@@ -50,7 +65,7 @@ open class {{ service.name | caseUcfirst }}: Service {
5065
let params: [String: Any?] = [:]
5166
{% endif %}
5267
{% for parameter in method.parameters.query | merge(method.parameters.body) %}
53-
"{{ parameter.name }}": {{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last or _self.methodNeedsSecurityParameters(method) %},{% endif %}
68+
"{{ parameter.name }}": {% if parameter.isGlobal %}self.{% endif %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last or _self.methodNeedsSecurityParameters(method) %},{% endif %}
5469

5570
{% endfor %}
5671
{% if _self.methodNeedsSecurityParameters(method) %}
@@ -138,7 +153,7 @@ open class {{ service.name | caseUcfirst }}: Service {
138153
{{ method.description | swiftComment }}
139154
///
140155
{% endif %}
141-
{% for parameter in method.parameters.all %}
156+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
142157
/// @param {{ parameter.type | typeName | raw}} {{ parameter.name | caseCamel }}
143158
{% endfor %}
144159
/// @throws Exception
@@ -149,7 +164,7 @@ open class {{ service.name | caseUcfirst }}: Service {
149164
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
150165
{% endif %}
151166
open func {{ method.name | caseCamel }}(
152-
{% for parameter in method.parameters.all %}
167+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
153168
{{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.type | typeName | raw }}{% if not parameter.required %}? = nil{% endif %},
154169
{% endfor %}
155170
{% if 'multipart/form-data' in method.consumes %}
@@ -160,7 +175,7 @@ open class {{ service.name | caseUcfirst }}: Service {
160175
Task {
161176
do {
162177
let result = try await {{ method.name | caseCamel }}(
163-
{% for parameter in method.parameters.all %}
178+
{% for parameter in method.parameters.all | filter((param) => not param.isGlobal) %}
164179
{{ parameter.name | caseCamel | escapeKeyword }}: {{ parameter.name | caseCamel | escapeKeyword }}{% if not loop.last or 'multipart/form-data' in method.consumes %},{% endif %}
165180

166181
{% endfor %}

tests/languages/flutter/tests.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ void main() async {
2323
print('\nTest Started');
2424

2525
Mock response;
26-
response = await foo.get(x: 'string', y: 123, z: ['string in array']);
26+
response = await foo.get(y: 123, z: ['string in array']);
2727
print(response.result);
2828

29-
response = await foo.post(x: 'string', y: 123, z: ['string in array']);
29+
response = await foo.post(y: 123, z: ['string in array']);
3030
print(response.result);
3131

32-
response = await foo.put(x: 'string', y: 123, z: ['string in array']);
32+
response = await foo.put(y: 123, z: ['string in array']);
3333
print(response.result);
3434

35-
response = await foo.patch(x: 'string', y: 123, z: ['string in array']);
35+
response = await foo.patch(y: 123, z: ['string in array']);
3636
print(response.result);
3737

38-
response = await foo.delete(x: 'string', y: 123, z: ['string in array']);
38+
response = await foo.delete(y: 123, z: ['string in array']);
3939
print(response.result);
4040

4141
// Bar Tests

tests/languages/ruby/tests.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
client = Appwrite::Client.new
44
client.add_header('Origin', 'http://localhost')
55

6-
foo = Appwrite::Foo.new(client)
6+
foo = Appwrite::Foo.new(client, x: 'string')
77
bar = Appwrite::Bar.new(client)
88
general = Appwrite::General.new(client)
99

@@ -12,19 +12,19 @@
1212

1313
# Foo
1414

15-
response = foo.get(x: 'string', y: 123, z: ['string in array'])
15+
response = foo.get(y: 123, z: ['string in array'])
1616
puts response.result
1717

18-
response = foo.post(x: 'string', y: 123, z: ['string in array'])
18+
response = foo.post(y: 123, z: ['string in array'])
1919
puts response.result
2020

21-
response = foo.put(x: 'string', y: 123, z: ['string in array'])
21+
response = foo.put(y: 123, z: ['string in array'])
2222
puts response.result
2323

24-
response = foo.patch(x: 'string', y: 123, z: ['string in array'])
24+
response = foo.patch(y: 123, z: ['string in array'])
2525
puts response.result
2626

27-
response = foo.delete(x: 'string', y: 123, z: ['string in array'])
27+
response = foo.delete(y: 123, z: ['string in array'])
2828
puts response.result
2929

3030
# Bar

tests/languages/swift-client/Tests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Tests: XCTestCase {
2525
.addHeader(key: "Origin", value: "http://localhost")
2626
.setSelfSigned()
2727

28-
let foo = Foo(client)
28+
let foo = Foo(client, "string")
2929
let bar = Bar(client)
3030
let general = General(client)
3131
let realtime = Realtime(client)
@@ -41,19 +41,19 @@ class Tests: XCTestCase {
4141
var mock: Mock
4242

4343
// Foo Tests
44-
mock = try await foo.get(x: "string", y: 123, z: ["string in array"])
44+
mock = try await foo.get(y: 123, z: ["string in array"])
4545
print(mock.result)
4646

47-
mock = try await foo.post(x: "string", y: 123, z: ["string in array"])
47+
mock = try await foo.post(y: 123, z: ["string in array"])
4848
print(mock.result)
4949

50-
mock = try await foo.put(x: "string", y: 123, z: ["string in array"])
50+
mock = try await foo.put(y: 123, z: ["string in array"])
5151
print(mock.result)
5252

53-
mock = try await foo.patch(x: "string", y: 123, z: ["string in array"])
53+
mock = try await foo.patch(y: 123, z: ["string in array"])
5454
print(mock.result)
5555

56-
mock = try await foo.delete(x: "string", y: 123, z: ["string in array"])
56+
mock = try await foo.delete(y: 123, z: ["string in array"])
5757
print(mock.result)
5858

5959

tests/languages/swift-server/Tests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ class Tests: XCTestCase {
2424
.addHeader(key: "Origin", value: "http://localhost")
2525
.setSelfSigned()
2626

27-
let foo = Foo(client)
27+
let foo = Foo(client, "string")
2828
let bar = Bar(client)
2929
let general = General(client)
3030

3131
var mock: Mock
3232

3333
// Foo Tests
34-
mock = try await foo.get(x: "string", y: 123, z: ["string in array"])
34+
mock = try await foo.get(y: 123, z: ["string in array"])
3535
print(mock.result)
3636

37-
mock = try await foo.post(x: "string", y: 123, z: ["string in array"])
37+
mock = try await foo.post(y: 123, z: ["string in array"])
3838
print(mock.result)
3939

40-
mock = try await foo.put(x: "string", y: 123, z: ["string in array"])
40+
mock = try await foo.put(y: 123, z: ["string in array"])
4141
print(mock.result)
4242

43-
mock = try await foo.patch(x: "string", y: 123, z: ["string in array"])
43+
mock = try await foo.patch(y: 123, z: ["string in array"])
4444
print(mock.result)
4545

46-
mock = try await foo.delete(x: "string", y: 123, z: ["string in array"])
46+
mock = try await foo.delete(y: 123, z: ["string in array"])
4747
print(mock.result)
4848

4949

0 commit comments

Comments
 (0)