From 7ff9c0dbb8b522f64f89d4b680c98305c95046b1 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Mon, 25 May 2026 15:44:42 +0530 Subject: [PATCH] fix(sdk-ts): normalize generated client --- .../scripts/normalize_generated_sdk.py | 18 +++++++ .../models/template-control-input.ts | 3 -- .../tests/test_normalize_generated_sdk.py | 50 +++++++++++++++++++ 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/sdks/typescript/scripts/normalize_generated_sdk.py b/sdks/typescript/scripts/normalize_generated_sdk.py index 33d8e29d..3eedfeb2 100644 --- a/sdks/typescript/scripts/normalize_generated_sdk.py +++ b/sdks/typescript/scripts/normalize_generated_sdk.py @@ -62,12 +62,30 @@ def _normalize_sdk_metadata_version(file_path: Path) -> None: file_path.write_text(normalized, encoding="utf-8") +def _strip_unstable_type_comments(file_path: Path) -> None: + original = file_path.read_text(encoding="utf-8") + normalized = original.replace( + "/**\n" + " * Template-backed input payload for control create/update requests.\n" + " */\n" + "export type TemplateControlInput = {", + "export type TemplateControlInput = {", + ) + + if normalized != original: + file_path.write_text(normalized, encoding="utf-8") + + def normalize_generated_sdk(_schema_path: Path, generated_dir: Path) -> None: """Normalize generated SDK output to keep generation deterministic.""" config_file = generated_dir / "lib" / "config.ts" if config_file.exists(): _normalize_sdk_metadata_version(config_file) + template_control_input_file = generated_dir / "models" / "template-control-input.ts" + if template_control_input_file.exists(): + _strip_unstable_type_comments(template_control_input_file) + validation_error_file = generated_dir / "models" / "validation-error.ts" if not validation_error_file.exists(): return diff --git a/sdks/typescript/src/generated/models/template-control-input.ts b/sdks/typescript/src/generated/models/template-control-input.ts index 2bf49fed..c48d7110 100644 --- a/sdks/typescript/src/generated/models/template-control-input.ts +++ b/sdks/typescript/src/generated/models/template-control-input.ts @@ -15,9 +15,6 @@ import { TemplateValue$outboundSchema, } from "./template-value.js"; -/** - * Template-backed input payload for control create/update requests. - */ export type TemplateControlInput = { /** * Reusable template with typed parameters and a JSON definition template. diff --git a/sdks/typescript/tests/test_normalize_generated_sdk.py b/sdks/typescript/tests/test_normalize_generated_sdk.py index 87ab2497..1f23f6df 100644 --- a/sdks/typescript/tests/test_normalize_generated_sdk.py +++ b/sdks/typescript/tests/test_normalize_generated_sdk.py @@ -103,6 +103,25 @@ """ +TEMPLATE_CONTROL_INPUT_WITHOUT_UNSTABLE_TYPE_COMMENT = """/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +export type TemplateControlInput = {}; +""" + + +TEMPLATE_CONTROL_INPUT_WITH_UNSTABLE_TYPE_COMMENT = """/* + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. + */ + +/** + * Template-backed input payload for control create/update requests. + */ +export type TemplateControlInput = {}; +""" + + def _write_schema(tmp_path: Path, *, include_context_fields: bool) -> Path: properties: dict[str, object] = { "loc": {"type": "array"}, @@ -140,6 +159,10 @@ def _write_generated_file(tmp_path: Path) -> Path: lib_dir.mkdir(parents=True) file_path = models_dir / "validation-error.ts" file_path.write_text(VALIDATION_ERROR_WITH_CONTEXT, encoding="utf-8") + (models_dir / "template-control-input.ts").write_text( + TEMPLATE_CONTROL_INPUT_WITHOUT_UNSTABLE_TYPE_COMMENT, + encoding="utf-8", + ) (lib_dir / "config.ts").write_text(CONFIG_WITH_VERSIONED_METADATA, encoding="utf-8") return generated_dir @@ -212,3 +235,30 @@ def test_normalizer_rewrites_sdk_metadata_to_stable_version(tmp_path: Path) -> N 'userAgent: "speakeasy-sdk/typescript 0.1.0 2.827.0 0.0.0 agent-control"' in normalized ) + + +def test_normalizer_removes_unstable_template_control_input_type_comment( + tmp_path: Path, +) -> None: + schema_path = _write_schema(tmp_path, include_context_fields=True) + generated_dir = _write_generated_file(tmp_path) + template_control_input = generated_dir / "models" / "template-control-input.ts" + template_control_input.write_text( + TEMPLATE_CONTROL_INPUT_WITH_UNSTABLE_TYPE_COMMENT, + encoding="utf-8", + ) + + subprocess.run( + [ + sys.executable, + str(SCRIPT_PATH), + "--schema", + str(schema_path), + "--generated-dir", + str(generated_dir), + ], + check=True, + ) + + normalized = template_control_input.read_text(encoding="utf-8") + assert normalized == TEMPLATE_CONTROL_INPUT_WITHOUT_UNSTABLE_TYPE_COMMENT