1
1
import { Service } from '../service';
2
2
import { {{ spec .title | caseUcfirst }}Exception, Client } from '../client';
3
3
import type { Models } from '../models';
4
- import type { UploadProgress } from '../client';
5
-
6
- type Payload = {
7
- [key: string]: any;
8
- }
4
+ import type { UploadProgress, Payload } from '../client';
9
5
10
6
export class {{ service .name | caseUcfirst }} extends Service {
11
- {% if service .globalParams | length %}
12
- {% for parameter in service .globalParams %}
13
- protected {{ parameter .name | caseCamel | escapeKeyword }}: {{ parameter .type | typeName }};
14
- public set{{ parameter .name | caseUcfirst | escapeKeyword }}({{ parameter .name | caseCamel | escapeKeyword }}: {{ parameter .type | typeName }}): void
15
- {
16
- this.{{ parameter .name | caseCamel | escapeKeyword }} = {{ parameter .name | caseCamel | escapeKeyword }};
17
- }
18
- public get{{ parameter .name | caseUcfirst | escapeKeyword }}(): {{ parameter .type | typeName }}
19
- {
20
- return this.{{ parameter .name | caseCamel | escapeKeyword }};
21
- }
22
- {% endfor %}
23
- constructor(client: Client, {% for parameter in service .globalParams %} {{ parameter .name | caseCamel | escapeKeyword }}:{{ parameter .type | typeName }}{% if not parameter .required %}|null = null{% endif %}{% if not loop .last %}, {% endif %}{% endfor %})
7
+ constructor(client: Client)
24
8
{
25
9
super(client);
26
-
27
- {% for parameter in service .globalParams %}
28
- this.{{ parameter .name | caseCamel | escapeKeyword }} = {{ parameter .name | caseCamel | escapeKeyword }};
29
- {% endfor %}
30
10
}
31
- {% endif %}
32
11
{% for method in service .methods %}
33
12
34
13
/**
@@ -38,34 +17,34 @@ export class {{ service.name | caseUcfirst }} extends Service {
38
17
{{ method .description | comment3 }}
39
18
{% endif %}
40
19
*
41
- {% for parameter in method .parameters .all | filter(( param ) => not param . isGlobal ) %}
20
+ {% for parameter in method .parameters .all %}
42
21
* @param {{ ' {' }}{{ parameter .type | getPropertyType(method ) | raw }}{{ ' }' }} {{ parameter .name | caseCamel | escapeKeyword }}
43
22
{% endfor %}
44
23
* @throws {{ ' {' }}{{ spec .title | caseUcfirst }}Exception}
45
24
* @returns {% if method .type == ' webAuth' %}{void|string}{% elseif method .type == ' location' %}{URL}{% else %}{Promise}{% endif %}
46
25
47
26
*/
48
- {% if method .type != ' location' and method .type != ' webAuth' %}async {% endif %}{{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}({% for parameter in method .parameters .all | filter(( param ) => not param . isGlobal ) %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required %}?{% endif %}: {{ parameter .type | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %}{% if ' multipart/form-data' in method .consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec ) | raw }} {
49
- {% for parameter in method .parameters .all | filter(( param ) => not param . isGlobal ) %}
27
+ {% if method .type != ' location' and method .type != ' webAuth' %}async {% endif %}{{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}({% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required %}?{% endif %}: {{ parameter .type | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %}{% if ' multipart/form-data' in method .consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec ) | raw }} {
28
+ {% for parameter in method .parameters .all %}
50
29
{% if parameter .required %}
51
30
if (typeof {{ parameter .name | caseCamel | escapeKeyword }} === 'undefined') {
52
31
throw new {{spec .title | caseUcfirst }}Exception('Missing required parameter: "{{ parameter .name | caseCamel | escapeKeyword }}"');
53
32
}
54
33
55
34
{% endif %}
56
35
{% endfor %}
57
- let path = '{{ method .path }}'{% for parameter in method .parameters .path %}.replace('{{ ' {' }}{{ parameter .name | caseCamel | escapeKeyword }}{{ ' }' }}', {% if parameter . isGlobal %}this.{% endif %}{ { parameter .name | caseCamel | escapeKeyword }}){% endfor %};
36
+ let path = '{{ method .path }}'{% for parameter in method .parameters .path %}.replace('{{ ' {' }}{{ parameter .name | caseCamel | escapeKeyword }}{{ ' }' }}', {{ parameter .name | caseCamel | escapeKeyword }}){% endfor %};
58
37
let payload: Payload = {};
59
38
60
39
{% for parameter in method .parameters .query %}
61
- if (typeof {% if parameter . isGlobal %}this.{% endif %}{ { parameter .name | caseCamel | escapeKeyword }} !== 'undefined') {
62
- payload['{{ parameter .name }}'] = {% if parameter . isGlobal %}this.{% endif %}{ { parameter .name | caseCamel | escapeKeyword }};
40
+ if (typeof {{ parameter .name | caseCamel | escapeKeyword }} !== 'undefined') {
41
+ payload['{{ parameter .name }}'] = {{ parameter .name | caseCamel | escapeKeyword }};
63
42
}
64
43
65
44
{% endfor %}
66
45
{% for parameter in method .parameters .body %}
67
- if (typeof {% if parameter . isGlobal %}this.{% endif %}{ { parameter .name | caseCamel | escapeKeyword }} !== 'undefined') {
68
- payload['{{ parameter .name }}'] = {% if parameter . isGlobal %}this.{% endif %}{ { parameter .name | caseCamel | escapeKeyword }};
46
+ if (typeof {{ parameter .name | caseCamel | escapeKeyword }} !== 'undefined') {
47
+ payload['{{ parameter .name }}'] = {{ parameter .name | caseCamel | escapeKeyword }};
69
48
}
70
49
71
50
{% endfor %}
0 commit comments