Skip to content

Commit 42b4733

Browse files
Revert "improve(web): param checks"
This reverts commit f8cf0b7.
1 parent f8cf0b7 commit 42b4733

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

templates/web/src/sdk.ts.twig

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,29 @@ 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 %}
181189
let path = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel }}){% endfor %};
182190
let payload: Payload = {};
183-
{% for parameter in method.parameters.all %}
184191

185-
if (typeof {{ parameter.name | caseCamel }} !== 'undefined') {
192+
{% for parameter in method.parameters.query %}
193+
if ({{ parameter.name | caseCamel }}) {
186194
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel }};
187-
}{% if parameter.required %} else {
188-
throw new {{spec.title | caseUcfirst}}Exception('Missing required parameter: "{{ parameter.name | caseCamel }}"');
189-
}{% endif %}
195+
}
190196

191197
{% endfor %}
198+
{% for parameter in method.parameters.body %}
199+
if (typeof {{ parameter.name | caseCamel }} !== 'undefined') {
200+
payload['{{ parameter.name }}'] = {{ parameter.name | caseCamel }};
201+
}
192202

203+
{% endfor %}
193204
const uri = new URL(this.config.endpoint + path);
194205
{% if method.type == 'location' or method.type == 'webAuth' %}
195206
{% if method.security|length > 0 %}

0 commit comments

Comments
 (0)