Skip to content

Commit 68454ba

Browse files
committed
updated spec and fixes for testing
1 parent bbf4db9 commit 68454ba

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

src/SDK/Language/Dart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function getKeywords()
112112
*/
113113
public function getIdentifierOverrides()
114114
{
115-
return ['Function' => 'Func'];
115+
return ['Function' => 'Func', 'default' => 'xdefault', 'required' => 'xrequired'];
116116
}
117117

118118
/**

templates/dart/lib/services/service.dart.twig

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
part of {{ language.params.packageName }};
2-
{% macro parameter(parameter) %}
3-
{% if parameter.required %}required {{ parameter.type | typeName }}{% else %}{{ parameter.type | typeName }}?{% endif %} {{ parameter.name | caseCamel | escapeKeyword }}{% endmacro %}
2+
{% macro parameter(parameter) %}{% if parameter.required %}required {{ parameter.type | typeName }}{% else %}{{ parameter.type | typeName }}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %}
43
{% macro method_parameters(parameters, consumes) %}
54
{% if parameters|length > 0 %}{{ '{' }}{% for parameter in parameters %}{{ _self.parameter(parameter) }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, Function(UploadProgress)? onProgress{% endif %}{{ '}' }}{% endif %}
65
{% endmacro %}
6+
{% macro service_params(parameters) %}
7+
{% if parameters|length > 0 %}{{ ', {' }}{% for parameter in parameters %}{% if parameter.required %}required {% endif %}this.{{ parameter.name | caseCamel | overrideIdentifier }}{% if not loop.last %}, {% endif %}{% endfor %}{{ '}' }}{% endif %}
8+
{% endmacro %}
79

810
{%if service.description %}
911
{{ service.description|dartComment}}
1012
{% endif %}
1113
class {{ service.name | caseUcfirst }} extends Service {
12-
{{ service.name | caseUcfirst }}(Client client{% if service.globalParams | length %}, {{ _self.method_parameters(service.globalParams, []) }}{% endif %}): super(client);
14+
{{ service.name | caseUcfirst }}(Client client{{ _self.service_params(service.globalParams) }}): super(client);
15+
{% if service.globalParams | length %}
16+
{% for parameter in service.globalParams %}
17+
{{ parameter.type | typeName }}{% if not parameter.required %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }};
18+
{% endfor %}
19+
{% endif %}
1320
{% for method in service.methods %}
1421

1522
/// {{ method.title }}

templates/flutter/lib/services/service.dart.twig

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
part of {{ language.params.packageName }};
2-
{% macro parameter(parameter) %}{% if parameter.required %}required {{ parameter.type | typeName }}{% else %}{{ parameter.type | typeName }}?{% endif %} {{ parameter.name | caseCamel | escapeKeyword }}{% endmacro %}
2+
{% macro parameter(parameter) %}{% if parameter.required %}required {{ parameter.type | typeName }}{% else %}{{ parameter.type | typeName }}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }}{% endmacro %}
33
{% macro method_parameters(parameters, consumes) %}
44
{% if parameters|length > 0 %}{{ '{' }}{% for parameter in parameters %}{{ _self.parameter(parameter) }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in consumes %}, Function(UploadProgress)? onProgress{% endif %}{{ '}' }}{% endif %}
55
{% endmacro %}
6+
{% macro service_params(parameters) %}
7+
{% if parameters|length > 0 %}{{ ', {' }}{% for parameter in parameters %}{% if parameter.required %}required {% endif %}this.{{ parameter.name | caseCamel | overrideIdentifier }}{% if not loop.last %}, {% endif %}{% endfor %}{{ '}' }}{% endif %}
8+
{% endmacro %}
69

710
{%if service.description %}
811
{{ service.description|dartComment}}
912
{% endif %}
1013
class {{ service.name | caseUcfirst }} extends Service {
11-
{{ service.name | caseUcfirst }}(Client client{% if service.globalParams | length %}, {{ _self.method_parameters(service.globalParams, []) }}{% endif %}): super(client);
14+
{{ service.name | caseUcfirst }}(Client client{{ _self.service_params(service.globalParams) }}): super(client);
15+
{% if service.globalParams | length %}
16+
{% for parameter in service.globalParams %}
17+
{{ parameter.type | typeName }}{% if not parameter.required %}?{% endif %} {{ parameter.name | caseCamel | overrideIdentifier }};
18+
{% endfor %}
19+
{% endif %}
1220
{% for method in service.methods %}
1321

1422
/// {{ method.title }}
@@ -18,7 +26,7 @@ class {{ service.name | caseUcfirst }} extends Service {
1826
///
1927
{% endif %}
2028
{% if method.type == 'webAuth' %}Future{% elseif method.type == 'location' %} Future<Uint8List> {% else %} {% if method.responseModel and method.responseModel != 'any' %}Future<models.{{method.responseModel | caseUcfirst}}>{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel }}({{ _self.method_parameters(method.parameters.all | filter((param) => not param.isGlobal), method.consumes) }}) async {
21-
{% if method.parameters.path | length > 0 %}final{% else %}const{% endif %} String path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %};
29+
{% if method.parameters.path | length > 0 %}final{% else %}const{% endif %} String path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}){% endfor %};
2230

2331
{% if 'multipart/form-data' in method.consumes %}
2432
{{ include('flutter/base/requests/file.twig') }}

tests/languages/dart/tests.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import '../lib/models.dart';
33

44
void main() async {
55
Client client = Client();
6-
Foo foo = Foo(client);
6+
Foo foo = Foo(client, x: 'string');
77
Bar bar = Bar(client);
88
General general = General(client);
99

@@ -14,19 +14,19 @@ void main() async {
1414

1515
// Foo Tests
1616
Mock response;
17-
response = await foo.get(x: 'string', y: 123, z: ['string in array']);
17+
response = await foo.get(y: 123, z: ['string in array']);
1818
print(response.result);
1919

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

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

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

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

3232
// Bar Tests

tests/resources/spec.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@
383383
"description": "Sample string param",
384384
"required": true,
385385
"type": "string",
386+
"x-global": true,
386387
"x-example": "[]",
387388
"in": "query"
388389
},
@@ -445,6 +446,7 @@
445446
"type": "string",
446447
"description": "Sample string param",
447448
"default": null,
449+
"x-global": true,
448450
"x-example": "[]"
449451
},
450452
"y": {
@@ -506,6 +508,7 @@
506508
"type": "string",
507509
"description": "Sample string param",
508510
"default": null,
511+
"x-global": true,
509512
"x-example": "[]"
510513
},
511514
"y": {
@@ -567,6 +570,7 @@
567570
"type": "string",
568571
"description": "Sample string param",
569572
"default": null,
573+
"x-global": true,
570574
"x-example": "[]"
571575
},
572576
"y": {
@@ -628,6 +632,7 @@
628632
"type": "string",
629633
"description": "Sample string param",
630634
"default": null,
635+
"x-global": true,
631636
"x-example": "[]"
632637
},
633638
"y": {

0 commit comments

Comments
 (0)