Skip to content

Commit f8cf0b7

Browse files
improve(web): param checks
1 parent f47263e commit f8cf0b7

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

templates/web/src/sdk.ts.twig

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,29 +178,18 @@ class {{ spec.title | caseUcfirst }} {
178178

179179
*/
180180
{{ method.name | caseCamel }}: {% if method.type != "location" and method.type != 'webAuth'%}async <T extends unknown>{% endif %}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel }}{% if not parameter.required %}?{% endif %}: {{ parameter.type | typeName }}{% if not loop.last %}, {% endif %}{% endfor %}): {% if method.type == 'webAuth' %}void | URL{% elseif method.type == 'location' %}URL{% else %}Promise<T>{% endif %} => {
181-
{% for parameter in method.parameters.all %}
182-
{% if parameter.required %}
183-
if ({{ parameter.name | caseCamel }} === undefined) {
184-
throw new {{spec.title | caseUcfirst}}Exception('Missing required parameter: "{{ parameter.name | caseCamel }}"');
185-
}
186-
187-
{% endif %}
188-
{% endfor %}
189181
let path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel }}){% endfor %};
190182
let payload: Payload = {};
183+
{% for parameter in method.parameters.all %}
191184

192-
{% for parameter in method.parameters.query %}
193-
if ({{ parameter.name | caseCamel }}) {
194-
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel }};
195-
}
196-
197-
{% endfor %}
198-
{% for parameter in method.parameters.body %}
199185
if (typeof {{ parameter.name | caseCamel }} !== 'undefined') {
200186
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel }};
201-
}
187+
}{% if parameter.required %} else {
188+
throw new {{spec.title | caseUcfirst}}Exception('Missing required parameter: "{{ parameter.name | caseCamel }}"');
189+
}{% endif %}
202190

203191
{% endfor %}
192+
204193
const uri = new URL(this.config.endpoint + path);
205194
{% if method.type == 'location' or method.type == 'webAuth' %}
206195
{% if method.security|length > 0 %}

0 commit comments

Comments
 (0)