Skip to content

Commit 1baaa7f

Browse files
authored
Merge pull request #21 from xdevplatform/address-xdk-bugs
Address bugs and stuf
2 parents b5e56ac + b5fcb10 commit 1baaa7f

11 files changed

Lines changed: 1425 additions & 74 deletions

File tree

latest-openapi.json

Lines changed: 826 additions & 22 deletions
Large diffs are not rendered by default.

xdk-gen/templates/typescript/client_class.j2

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This module provides a client for interacting with the {{ tag.display_name }} endpoints of the X API.
66
*/
77

8-
import { Client, ApiResponse, RequestOptions } from '../client.js';
8+
import { Client, ApiResponse, RequestOptions, normalizeFields, transformKeysToSnake } from '../client.js';
99
import {
1010
Paginator,
1111
PostPaginator,
@@ -117,9 +117,49 @@ export class {{ tag.class_name }}Client {
117117
{% if operation.request_body and operation.request_body.required %}
118118
* @param body {% if operation.request_body.content and operation.request_body.content["application/json"] and operation.request_body.content["application/json"].schema and operation.request_body.content["application/json"].schema.description %}{{ operation.request_body.content["application/json"].schema.description }}{% else %}Request body{% endif %}
119119
{% endif %}
120-
* @returns {Promise<{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}{{ operation.class_name }}Response{% else %}any{% endif %}>} Promise resolving to the API response
120+
* @returns {Promise<{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}{{ operation.class_name }}Response{% else %}any{% endif %}>} Promise resolving to the API response, or raw Response if requestOptions.raw is true
121121
*/
122-
// Overload 1: Default behavior (unwrapped response)
122+
// Overload 1: raw: true returns Response
123+
{{ operation.method_name }}(
124+
{% for param in operation.parameters | selectattr('location', 'equalto', 'path') %}
125+
{% if param.variable_name %}
126+
{{ param.variable_name }}: {% if param.schema and param.schema.type %}{{ param.schema.type | typescript_type }}{% else %}string{% endif %},
127+
{% endif %}
128+
{% endfor %}
129+
{% for param in operation.parameters | selectattr('required') | rejectattr('location', 'equalto', 'path') %}
130+
{% if param.variable_name %}
131+
{{ param.variable_name }}: {% if param.schema and param.schema.type %}{{ param.schema.type | typescript_type }}{% else %}any{% endif %},
132+
{% endif %}
133+
{% endfor %}
134+
{% if operation.request_body and operation.request_body.required %}
135+
body: {{ operation.class_name }}Request,
136+
{% endif %}
137+
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 or (operation.request_body and not operation.request_body.required) %}
138+
options: {{ operation.class_name }}Options & { requestOptions: { raw: true } }
139+
{% else %}
140+
options: { requestOptions: { raw: true } }
141+
{% endif %}
142+
): Promise<Response>;
143+
// Overload 2: Default behavior returns parsed response
144+
{{ operation.method_name }}(
145+
{% for param in operation.parameters | selectattr('location', 'equalto', 'path') %}
146+
{% if param.variable_name %}
147+
{{ param.variable_name }}: {% if param.schema and param.schema.type %}{{ param.schema.type | typescript_type }}{% else %}string{% endif %},
148+
{% endif %}
149+
{% endfor %}
150+
{% for param in operation.parameters | selectattr('required') | rejectattr('location', 'equalto', 'path') %}
151+
{% if param.variable_name %}
152+
{{ param.variable_name }}: {% if param.schema and param.schema.type %}{{ param.schema.type | typescript_type }}{% else %}any{% endif %},
153+
{% endif %}
154+
{% endfor %}
155+
{% if operation.request_body and operation.request_body.required %}
156+
body: {{ operation.class_name }}Request,
157+
{% endif %}
158+
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 or (operation.request_body and not operation.request_body.required) %}
159+
options?: {{ operation.class_name }}Options
160+
{% endif %}
161+
): Promise<{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}{{ operation.class_name }}Response{% else %}any{% endif %}>;
162+
// Implementation
123163
async {{ operation.method_name }}(
124164
{# Path parameters are always required - use location field #}
125165
{% for param in operation.parameters | selectattr('location', 'equalto', 'path') %}
@@ -141,7 +181,7 @@ export class {{ tag.class_name }}Client {
141181
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 or (operation.request_body and not operation.request_body.required) %}
142182
options: {{ operation.class_name }}Options = {}
143183
{% endif %}
144-
): Promise<{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}{{ operation.class_name }}Response{% else %}any{% endif %}> {
184+
): Promise<{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}{{ operation.class_name }}Response{% else %}any{% endif %} | Response> {
145185
// Normalize options to handle both camelCase and original API parameter names
146186
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 or (operation.request_body and not operation.request_body.required) %}
147187
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 %}
@@ -189,15 +229,23 @@ export class {{ tag.class_name }}Client {
189229
{% if param.required %}
190230
if ({{ var_name }} !== undefined{% if param.schema and param.schema.type == 'array' %} && {{ var_name }}.length > 0{% endif %}) {
191231
{% if param.schema and param.schema.type == 'array' %}
232+
{% if '.fields' in param.original_name or '_fields' in param.original_name %}
233+
params.append('{{ param.original_name }}', normalizeFields({{ var_name }}).join(','));
234+
{% else %}
192235
params.append('{{ param.original_name }}', {{ var_name }}.join(','));
236+
{% endif %}
193237
{% else %}
194238
params.append('{{ param.original_name }}', String({{ var_name }}));
195239
{% endif %}
196240
}
197241
{% else %}
198242
if ({{ var_name }} !== undefined{% if param.schema and param.schema.type == 'array' %} && {{ var_name }}.length > 0{% endif %}) {
199243
{% if param.schema and param.schema.type == 'array' %}
244+
{% if '.fields' in param.original_name or '_fields' in param.original_name %}
245+
params.append('{{ param.original_name }}', normalizeFields({{ var_name }}).join(','));
246+
{% else %}
200247
params.append('{{ param.original_name }}', {{ var_name }}.join(','));
248+
{% endif %}
201249
{% else %}
202250
params.append('{{ param.original_name }}', String({{ var_name }}));
203251
{% endif %}
@@ -209,9 +257,9 @@ export class {{ tag.class_name }}Client {
209257
// Prepare request options
210258
const finalRequestOptions: RequestOptions = {
211259
{% if operation.request_body and operation.request_body.required %}
212-
body: JSON.stringify(body || {}),
260+
body: JSON.stringify(transformKeysToSnake(body || {})),
213261
{% elif operation.request_body and not operation.request_body.required %}
214-
body: body ? JSON.stringify(body) : undefined,
262+
body: body ? JSON.stringify(transformKeysToSnake(body)) : undefined,
215263
{% endif %}
216264
{% if operation.security %}
217265
// Pass security requirements for smart auth selection
@@ -327,15 +375,23 @@ export class {{ tag.class_name }}Client {
327375
{% if param.required %}
328376
if ({{ var_name }} !== undefined{% if param.schema and param.schema.type == 'array' %} && {{ var_name }}.length > 0{% endif %}) {
329377
{% if param.schema and param.schema.type == 'array' %}
378+
{% if '.fields' in param.original_name or '_fields' in param.original_name %}
379+
params.append('{{ param.original_name }}', normalizeFields({{ var_name }}).join(','));
380+
{% else %}
330381
params.append('{{ param.original_name }}', {{ var_name }}.join(','));
382+
{% endif %}
331383
{% else %}
332384
params.append('{{ param.original_name }}', String({{ var_name }}));
333385
{% endif %}
334386
}
335387
{% else %}
336388
if ({{ var_name }} !== undefined{% if param.schema and param.schema.type == 'array' %} && {{ var_name }}.length > 0{% endif %}) {
337389
{% if param.schema and param.schema.type == 'array' %}
390+
{% if '.fields' in param.original_name or '_fields' in param.original_name %}
391+
params.append('{{ param.original_name }}', normalizeFields({{ var_name }}).join(','));
392+
{% else %}
338393
params.append('{{ param.original_name }}', {{ var_name }}.join(','));
394+
{% endif %}
339395
{% else %}
340396
params.append('{{ param.original_name }}', String({{ var_name }}));
341397
{% endif %}

0 commit comments

Comments
 (0)