@@ -28,16 +28,16 @@ export class {{ service.name | caseUcfirst }} extends Service {
28
28
{
29
29
super(client);
30
30
}
31
- {% for method in service .methods %}
31
+ {%~ for method in service .methods %}
32
32
33
33
/**
34
- {% if method .description %}
35
- {{ method .description | comment2 }}
36
- {% endif %}
34
+ {%~ if method .description %}
35
+ * {{ method .description | replace({ ' \n ' : ' \n * ' }) | raw }}
36
+ {%~ endif %}
37
37
*
38
- {% for parameter in method .parameters .all %}
39
- * @param {{ ' {' }}{{ parameter | getPropertyType(method ) | raw }}{{ ' }' }} {{ parameter .name | caseCamel | escapeKeyword }}
40
- {% endfor %}
38
+ {%~ for parameter in method .parameters .all %}
39
+ * @param {{ ' {' }}{{ parameter | getPropertyType(method ) | raw }}{{ ' }' }} {{ parameter .name | caseCamel | escapeKeyword }} - {{ parameter . description | raw }}
40
+ {%~ endfor %}
41
41
* @throws {{ ' {' }}{{ spec .title | caseUcfirst }}Exception}
42
42
* @returns {% if method .type == ' webAuth' %}{void|string}{% elseif method .type == ' location' %}{ArrayBuffer}{% else %}{Promise}{% endif %}
43
43
@@ -49,7 +49,63 @@ export class {{ service.name | caseUcfirst }} extends Service {
49
49
{%~ endif %}
50
50
{%~ endif %}
51
51
*/
52
- {% if method .type == ' upload' %}async {% endif %}{{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}({% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %}{% if ' multipart/form-data' in method .consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec ) | raw }} {
52
+ {%~ if method .parameters .all | length > 0 %}
53
+ {% if method .type == ' upload' %}async {% endif %}{{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}(params: { {% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %} {% if ' multipart/form-data' in method .consumes %}, onProgress?: (progress: UploadProgress) => {}{% endif %} }): {{ method | getReturn(spec ) | raw }};
54
+ /**
55
+ * @deprecated Parameter-based methods will be removed in the upcoming version.
56
+ * Please use the object based method instead for better developer experience.
57
+ *
58
+ * @example
59
+ * // Old (deprecated)
60
+ * {% if method .type == ' upload' %}async {% endif %}{{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}({% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %}{% if ' multipart/form-data' in method .consumes %}, onProgress?: (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec ) | raw }};
61
+ *
62
+ * // New (object based)
63
+ * {% if method .type == ' upload' %}async {% endif %}{{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}(params: { {% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %} {% if ' multipart/form-data' in method .consumes %}, onProgress?: (progress: UploadProgress) => {}{% endif %} }): {{ method | getReturn(spec ) | raw }};
64
+ */
65
+ {% if method .type == ' upload' %}async {% endif %}{{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}({% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %}{% if ' multipart/form-data' in method .consumes %}, onProgress?: (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec ) | raw }};
66
+ {% if method .type == ' upload' %}async {% endif %}{{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}(
67
+ {% if method .parameters .all | length > 0 %}paramsOrFirst{% if not method .parameters .all [0 ].required or method .parameters .all [0 ].nullable %}?{% endif %}: { {% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %}{% if ' multipart/form-data' in method .consumes %}, onProgress?: (progress: UploadProgress) => {} {% endif %} } | {{ method .parameters .all [0 ] | getPropertyType(method ) | raw }}{% if method .parameters .all | length > 1 %},
68
+ ...rest: [{% for parameter in method .parameters .all [1:] %}({{ parameter | getPropertyType(method ) | raw }})?{% if not loop .last %}, {% endif %}{% endfor %}{% if ' multipart/form-data' in method .consumes %},((progress: UploadProgress) => {})?{% endif %}]{% endif %}{% endif %}
69
+
70
+ ): {{ method | getReturn(spec ) | raw }} {
71
+ {%~ if method .parameters .all | length > 0 %}
72
+ let params: { {% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %} };
73
+ {%~ if ' multipart/form-data' in method .consumes %}
74
+ let onProgress: ((progress: UploadProgress) => {});
75
+ {%~ endif %}
76
+
77
+ if (paramsOrFirst && typeof paramsOrFirst === 'object' && !Array.isArray(paramsOrFirst){% set firstParamType = method .parameters .all [0 ] | getPropertyType(method ) | raw %}{% if not (firstParamType starts with ' string' or firstParamType starts with ' number' or firstParamType starts with ' boolean' ) %} && '{{ method .parameters .all [0 ].name | caseCamel | escapeKeyword }}' in paramsOrFirst{% endif %}) {
78
+ params = paramsOrFirst as { {% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %} };
79
+ {%~ if ' multipart/form-data' in method .consumes %}
80
+ onProgress = paramsOrFirst.onProgress as ((progress: UploadProgress) => {});
81
+ {%~ endif %}
82
+ } else {
83
+ params = {
84
+ {%~ for parameter in method .parameters .all %}
85
+ {{ parameter .name | caseCamel | escapeKeyword }}: {% if loop .index0 == 0 %}paramsOrFirst{% else %}rest[{{ loop .index0 - 1 }}]{% endif %} as {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %},
86
+ {% endif %}
87
+ {%~ endfor %}
88
+
89
+ };
90
+ {%~ if ' multipart/form-data' in method .consumes %}
91
+ onProgress = rest[{{ method .parameters .all | length - 1 }}] as ((progress: UploadProgress) => {});
92
+ {%~ endif %}
93
+ }
94
+
95
+ {%~ for parameter in method .parameters .all %}
96
+ const {{ parameter .name | caseCamel | escapeKeyword }} = params.{{ parameter .name | caseCamel | escapeKeyword }};
97
+ {%~ endfor %}
98
+
99
+ {%~ else %}
100
+ {%~ if ' multipart/form-data' in method .consumes %}
101
+ if (typeof paramsOrFirst === 'function') {
102
+ onProgress = paramsOrFirst;
103
+ }
104
+ {%~ endif %}
105
+ {%~ endif %}
106
+ {%~ else %}
107
+ {{ method .name | caseCamel }}{{ method .responseModel | getGenerics(spec ) | raw }}({% for parameter in method .parameters .all %}{{ parameter .name | caseCamel | escapeKeyword }}{% if not parameter .required or parameter .nullable %}?{% endif %}: {{ parameter | getPropertyType(method ) | raw }}{% if not loop .last %}, {% endif %}{% endfor %}{% if ' multipart/form-data' in method .consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec ) | raw }} {
108
+ {%~ endif %}
53
109
{% for parameter in method .parameters .all %}
54
110
{% if parameter .required %}
55
111
if (typeof {{ parameter .name | caseCamel | escapeKeyword }} === 'undefined') {
0 commit comments