Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
848 changes: 826 additions & 22 deletions latest-openapi.json

Large diffs are not rendered by default.

68 changes: 62 additions & 6 deletions xdk-gen/templates/typescript/client_class.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This module provides a client for interacting with the {{ tag.display_name }} endpoints of the X API.
*/

import { Client, ApiResponse, RequestOptions } from '../client.js';
import { Client, ApiResponse, RequestOptions, normalizeFields, transformKeysToSnake } from '../client.js';
import {
Paginator,
PostPaginator,
Expand Down Expand Up @@ -117,9 +117,49 @@ export class {{ tag.class_name }}Client {
{% if operation.request_body and operation.request_body.required %}
* @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 %}
{% endif %}
* @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
* @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
*/
// Overload 1: Default behavior (unwrapped response)
// Overload 1: raw: true returns Response
{{ operation.method_name }}(
{% for param in operation.parameters | selectattr('location', 'equalto', 'path') %}
{% if param.variable_name %}
{{ param.variable_name }}: {% if param.schema and param.schema.type %}{{ param.schema.type | typescript_type }}{% else %}string{% endif %},
{% endif %}
{% endfor %}
{% for param in operation.parameters | selectattr('required') | rejectattr('location', 'equalto', 'path') %}
{% if param.variable_name %}
{{ param.variable_name }}: {% if param.schema and param.schema.type %}{{ param.schema.type | typescript_type }}{% else %}any{% endif %},
{% endif %}
{% endfor %}
{% if operation.request_body and operation.request_body.required %}
body: {{ operation.class_name }}Request,
{% endif %}
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 or (operation.request_body and not operation.request_body.required) %}
options: {{ operation.class_name }}Options & { requestOptions: { raw: true } }
{% else %}
options: { requestOptions: { raw: true } }
{% endif %}
): Promise<Response>;
// Overload 2: Default behavior returns parsed response
{{ operation.method_name }}(
{% for param in operation.parameters | selectattr('location', 'equalto', 'path') %}
{% if param.variable_name %}
{{ param.variable_name }}: {% if param.schema and param.schema.type %}{{ param.schema.type | typescript_type }}{% else %}string{% endif %},
{% endif %}
{% endfor %}
{% for param in operation.parameters | selectattr('required') | rejectattr('location', 'equalto', 'path') %}
{% if param.variable_name %}
{{ param.variable_name }}: {% if param.schema and param.schema.type %}{{ param.schema.type | typescript_type }}{% else %}any{% endif %},
{% endif %}
{% endfor %}
{% if operation.request_body and operation.request_body.required %}
body: {{ operation.class_name }}Request,
{% endif %}
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 or (operation.request_body and not operation.request_body.required) %}
options?: {{ operation.class_name }}Options
{% endif %}
): Promise<{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}{{ operation.class_name }}Response{% else %}any{% endif %}>;
// Implementation
async {{ operation.method_name }}(
{# Path parameters are always required - use location field #}
{% for param in operation.parameters | selectattr('location', 'equalto', 'path') %}
Expand All @@ -141,7 +181,7 @@ export class {{ tag.class_name }}Client {
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 or (operation.request_body and not operation.request_body.required) %}
options: {{ operation.class_name }}Options = {}
{% endif %}
): 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<{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}{{ operation.class_name }}Response{% else %}any{% endif %} | Response> {
// Normalize options to handle both camelCase and original API parameter names
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 or (operation.request_body and not operation.request_body.required) %}
{% if operation.parameters | rejectattr('required') | rejectattr('location', 'equalto', 'path') | list | length > 0 %}
Expand Down Expand Up @@ -189,15 +229,23 @@ export class {{ tag.class_name }}Client {
{% if param.required %}
if ({{ var_name }} !== undefined{% if param.schema and param.schema.type == 'array' %} && {{ var_name }}.length > 0{% endif %}) {
{% if param.schema and param.schema.type == 'array' %}
{% if '.fields' in param.original_name or '_fields' in param.original_name %}
params.append('{{ param.original_name }}', normalizeFields({{ var_name }}).join(','));
{% else %}
params.append('{{ param.original_name }}', {{ var_name }}.join(','));
{% endif %}
{% else %}
params.append('{{ param.original_name }}', String({{ var_name }}));
{% endif %}
}
{% else %}
if ({{ var_name }} !== undefined{% if param.schema and param.schema.type == 'array' %} && {{ var_name }}.length > 0{% endif %}) {
{% if param.schema and param.schema.type == 'array' %}
{% if '.fields' in param.original_name or '_fields' in param.original_name %}
params.append('{{ param.original_name }}', normalizeFields({{ var_name }}).join(','));
{% else %}
params.append('{{ param.original_name }}', {{ var_name }}.join(','));
{% endif %}
{% else %}
params.append('{{ param.original_name }}', String({{ var_name }}));
{% endif %}
Expand All @@ -209,9 +257,9 @@ export class {{ tag.class_name }}Client {
// Prepare request options
const finalRequestOptions: RequestOptions = {
{% if operation.request_body and operation.request_body.required %}
body: JSON.stringify(body || {}),
body: JSON.stringify(transformKeysToSnake(body || {})),
{% elif operation.request_body and not operation.request_body.required %}
body: body ? JSON.stringify(body) : undefined,
body: body ? JSON.stringify(transformKeysToSnake(body)) : undefined,
{% endif %}
{% if operation.security %}
// Pass security requirements for smart auth selection
Expand Down Expand Up @@ -327,15 +375,23 @@ export class {{ tag.class_name }}Client {
{% if param.required %}
if ({{ var_name }} !== undefined{% if param.schema and param.schema.type == 'array' %} && {{ var_name }}.length > 0{% endif %}) {
{% if param.schema and param.schema.type == 'array' %}
{% if '.fields' in param.original_name or '_fields' in param.original_name %}
params.append('{{ param.original_name }}', normalizeFields({{ var_name }}).join(','));
{% else %}
params.append('{{ param.original_name }}', {{ var_name }}.join(','));
{% endif %}
{% else %}
params.append('{{ param.original_name }}', String({{ var_name }}));
{% endif %}
}
{% else %}
if ({{ var_name }} !== undefined{% if param.schema and param.schema.type == 'array' %} && {{ var_name }}.length > 0{% endif %}) {
{% if param.schema and param.schema.type == 'array' %}
{% if '.fields' in param.original_name or '_fields' in param.original_name %}
params.append('{{ param.original_name }}', normalizeFields({{ var_name }}).join(','));
{% else %}
params.append('{{ param.original_name }}', {{ var_name }}.join(','));
{% endif %}
{% else %}
params.append('{{ param.original_name }}', String({{ var_name }}));
{% endif %}
Expand Down
Loading