-
Notifications
You must be signed in to change notification settings - Fork 427
Expand file tree
/
Copy pathnormal.pebble
More file actions
69 lines (63 loc) · 2.75 KB
/
normal.pebble
File metadata and controls
69 lines (63 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{# @pebvariable name="op" type="org.openapitools.codegen.CodegenOperation" #}
{% if op.isResponseFile %}
const response = await this.httpClient.{{op.httpMethod|lower}}("{{op.path}}"
{% for param in op.pathParams %}
.replace('{' + "{{param.baseName}}" + '}', String({{param.paramName}}))
{% endfor %}
);
return {httpResponse: response, body: convertResponseToReadable(response)};
{% else %}
{% if op.hasBodyParam %}const params = {{op.bodyParam.paramName}};
{% elseif op.hasFormParams %}const formParams = {
{% for param in op.formParams -%}
"{{param.baseName}}": {{param.paramName}},
{% endfor %}
};
{% for param in op.formParams -%}
{% if param.required == false %}
if (formParams["{{param.baseName}}"] === undefined) {
delete formParams["{{param.baseName}}"];
}
{% endif -%}
{% endfor %}
{% elseif op.hasQueryParams %}const queryParams = {
{% for param in op.queryParams -%}
{% if param.isArray and param.required == false -%}
"{{param.baseName}}": {{param.paramName}} != null
? [...{{param.paramName}}].join(",")
: undefined,
{% elseif param.isArray -%}
"{{param.baseName}}": [...{{param.paramName}}].join(","),
{% else -%}
"{{param.baseName}}": {{param.paramName}},
{% endif -%}
{% endfor %}
};
{% for param in op.queryParams -%}
{% if param.required == false %}
if (queryParams["{{param.baseName}}"] === undefined) {
delete queryParams["{{param.baseName}}"];
}
{% endif -%}
{% endfor %}
{% endif %}
{% if op.hasHeaderParams %}const headerParams = {
{% for param in op.headerParams -%}
...({{ param.paramName }} != null ? {"{{param.baseName}}": {{param.paramName}}} : {}),
{% endfor %}
};
{% endif %}
const res = await this.httpClient.{{op.httpMethod|lower}}{% if op.hasFormParams %}Form{% endif %}{% if op.isMultipart %}Multipart{% endif %}{% if op.hasBodyParam and op.bodyParam.isFile %}BinaryContent{% endif %}(
"{{ op.path }}"
{% for param in op.pathParams %}
.replace("{{ "{" + param.paramName + "}" }}", String({{ param.paramName }}))
{% endfor %},
{% if op.hasBodyParam %}params,
{% elseif op.hasFormParams %}formParams,
{% elseif op.hasQueryParams %}queryParams,{% endif %}
{% if op.hasHeaderParams %}{headers: headerParams},{% endif %}
);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
{% endif %}