Skip to content

Commit 7ff9c0d

Browse files
fix(sdk-ts): normalize generated client
1 parent 2769c8c commit 7ff9c0d

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

sdks/typescript/scripts/normalize_generated_sdk.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,30 @@ def _normalize_sdk_metadata_version(file_path: Path) -> None:
6262
file_path.write_text(normalized, encoding="utf-8")
6363

6464

65+
def _strip_unstable_type_comments(file_path: Path) -> None:
66+
original = file_path.read_text(encoding="utf-8")
67+
normalized = original.replace(
68+
"/**\n"
69+
" * Template-backed input payload for control create/update requests.\n"
70+
" */\n"
71+
"export type TemplateControlInput = {",
72+
"export type TemplateControlInput = {",
73+
)
74+
75+
if normalized != original:
76+
file_path.write_text(normalized, encoding="utf-8")
77+
78+
6579
def normalize_generated_sdk(_schema_path: Path, generated_dir: Path) -> None:
6680
"""Normalize generated SDK output to keep generation deterministic."""
6781
config_file = generated_dir / "lib" / "config.ts"
6882
if config_file.exists():
6983
_normalize_sdk_metadata_version(config_file)
7084

85+
template_control_input_file = generated_dir / "models" / "template-control-input.ts"
86+
if template_control_input_file.exists():
87+
_strip_unstable_type_comments(template_control_input_file)
88+
7189
validation_error_file = generated_dir / "models" / "validation-error.ts"
7290
if not validation_error_file.exists():
7391
return

sdks/typescript/src/generated/models/template-control-input.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ import {
1515
TemplateValue$outboundSchema,
1616
} from "./template-value.js";
1717

18-
/**
19-
* Template-backed input payload for control create/update requests.
20-
*/
2118
export type TemplateControlInput = {
2219
/**
2320
* Reusable template with typed parameters and a JSON definition template.

sdks/typescript/tests/test_normalize_generated_sdk.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,25 @@
103103
"""
104104

105105

106+
TEMPLATE_CONTROL_INPUT_WITHOUT_UNSTABLE_TYPE_COMMENT = """/*
107+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
108+
*/
109+
110+
export type TemplateControlInput = {};
111+
"""
112+
113+
114+
TEMPLATE_CONTROL_INPUT_WITH_UNSTABLE_TYPE_COMMENT = """/*
115+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
116+
*/
117+
118+
/**
119+
* Template-backed input payload for control create/update requests.
120+
*/
121+
export type TemplateControlInput = {};
122+
"""
123+
124+
106125
def _write_schema(tmp_path: Path, *, include_context_fields: bool) -> Path:
107126
properties: dict[str, object] = {
108127
"loc": {"type": "array"},
@@ -140,6 +159,10 @@ def _write_generated_file(tmp_path: Path) -> Path:
140159
lib_dir.mkdir(parents=True)
141160
file_path = models_dir / "validation-error.ts"
142161
file_path.write_text(VALIDATION_ERROR_WITH_CONTEXT, encoding="utf-8")
162+
(models_dir / "template-control-input.ts").write_text(
163+
TEMPLATE_CONTROL_INPUT_WITHOUT_UNSTABLE_TYPE_COMMENT,
164+
encoding="utf-8",
165+
)
143166
(lib_dir / "config.ts").write_text(CONFIG_WITH_VERSIONED_METADATA, encoding="utf-8")
144167
return generated_dir
145168

@@ -212,3 +235,30 @@ def test_normalizer_rewrites_sdk_metadata_to_stable_version(tmp_path: Path) -> N
212235
'userAgent: "speakeasy-sdk/typescript 0.1.0 2.827.0 0.0.0 agent-control"'
213236
in normalized
214237
)
238+
239+
240+
def test_normalizer_removes_unstable_template_control_input_type_comment(
241+
tmp_path: Path,
242+
) -> None:
243+
schema_path = _write_schema(tmp_path, include_context_fields=True)
244+
generated_dir = _write_generated_file(tmp_path)
245+
template_control_input = generated_dir / "models" / "template-control-input.ts"
246+
template_control_input.write_text(
247+
TEMPLATE_CONTROL_INPUT_WITH_UNSTABLE_TYPE_COMMENT,
248+
encoding="utf-8",
249+
)
250+
251+
subprocess.run(
252+
[
253+
sys.executable,
254+
str(SCRIPT_PATH),
255+
"--schema",
256+
str(schema_path),
257+
"--generated-dir",
258+
str(generated_dir),
259+
],
260+
check=True,
261+
)
262+
263+
normalized = template_control_input.read_text(encoding="utf-8")
264+
assert normalized == TEMPLATE_CONTROL_INPUT_WITHOUT_UNSTABLE_TYPE_COMMENT

0 commit comments

Comments
 (0)