Skip to content

Commit 7ece1a2

Browse files
authored
fix: skip importing response types for binary endpoints (#30)
Operations that return application/octet-stream (binary data) don't have response model classes generated in models.j2, since those templates only generate models for application/json responses. However, the client_class.j2 templates were importing response types for ALL operations with 200/201 responses, causing import errors like: Module '"./models.js"' has no exported member 'MediaDownloadResponse' This fix adds a check in both TypeScript and Python client_class.j2 templates to only import response types for operations that actually return JSON content, matching the behavior of the models templates. Binary response operations (like chatMediaDownload) correctly use ArrayBuffer (TypeScript) or bytes (Python) as return types and don't need imported response model types.
1 parent db99bee commit 7ece1a2

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

xdk-gen/templates/python/client_class.j2

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ from .models import (
2525
{% for operation in operations %}
2626
{% if operation.request_body %}
2727
{{ operation.class_name }}Request,
28-
{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}
29-
{{ operation.class_name }}Response,
3028
{% endif %}
31-
{% elif operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses %}
29+
{# Only import response types for operations that return JSON (not binary) #}
30+
{% set response_200 = operation.responses["200"] if operation.responses and "200" in operation.responses else none %}
31+
{% set response_201 = operation.responses["201"] if operation.responses and "201" in operation.responses else none %}
32+
{% set has_json_response = (response_200 and response_200.content and "application/json" in response_200.content) or (response_201 and response_201.content and "application/json" in response_201.content) %}
33+
{% if has_json_response %}
3234
{{ operation.class_name }}Response,
3335
{% endif %}
3436
{% endfor %}

xdk-gen/templates/typescript/client_class.j2

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import {
1616
{% for operation in operations -%}
1717
{% if operation.request_body -%}
1818
{{ operation.class_name }}Request,
19-
{% if operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses -%}
20-
{{ operation.class_name }}Response,
2119
{% endif -%}
22-
{% elif operation.responses and "200" in operation.responses or operation.responses and "201" in operation.responses -%}
20+
{# Only import response types for operations that return JSON (not binary) #}
21+
{% set response_200 = operation.responses["200"] if operation.responses and "200" in operation.responses else none -%}
22+
{% set response_201 = operation.responses["201"] if operation.responses and "201" in operation.responses else none -%}
23+
{% set has_json_response = (response_200 and response_200.content and "application/json" in response_200.content) or (response_201 and response_201.content and "application/json" in response_201.content) -%}
24+
{% if has_json_response -%}
2325
{{ operation.class_name }}Response,
2426
{% endif -%}
2527
{% endfor -%}

0 commit comments

Comments
 (0)