|
25 | 25 | re.DOTALL, |
26 | 26 | ) |
27 | 27 |
|
| 28 | +STDIO_TYPE_LITERAL = 'Literal["2#-datamodel-code-generator-#-object-#-special-#"]' |
| 29 | +STDIO_TYPE_PATTERN = re.compile( |
| 30 | + r"^ type:\s*Literal\[['\"]2#-datamodel-code-generator-#-object-#-special-#['\"]\]" |
| 31 | + r"(?:\s*=\s*['\"][^'\"]+['\"])?\s*$", |
| 32 | + re.MULTILINE, |
| 33 | +) |
| 34 | + |
28 | 35 | # Map of numbered classes produced by datamodel-code-generator to descriptive names. |
29 | 36 | # Keep this in sync with the Rust/TypeScript SDK nomenclature. |
30 | 37 | RENAME_MAP: dict[str, str] = { |
@@ -198,6 +205,7 @@ def rename_types(output_path: Path) -> list[str]: |
198 | 205 | header_block = "\n".join(header_lines) + "\n\n" |
199 | 206 | content = _apply_field_overrides(content) |
200 | 207 | content = _apply_default_overrides(content) |
| 208 | + content = _normalize_stdio_model(content) |
201 | 209 | content = _add_description_comments(content) |
202 | 210 | content = _ensure_custom_base_model(content) |
203 | 211 |
|
@@ -323,6 +331,19 @@ def replace_block( |
323 | 331 | return content |
324 | 332 |
|
325 | 333 |
|
| 334 | +def _normalize_stdio_model(content: str) -> str: |
| 335 | + replacement_line = ' type: Literal["stdio"] = "stdio"' |
| 336 | + new_content, count = STDIO_TYPE_PATTERN.subn(replacement_line, content) |
| 337 | + if count == 0: |
| 338 | + return content |
| 339 | + if count > 1: |
| 340 | + print( |
| 341 | + "Warning: multiple stdio type placeholders detected; manual review required.", |
| 342 | + file=sys.stderr, |
| 343 | + ) |
| 344 | + return new_content |
| 345 | + |
| 346 | + |
326 | 347 | def _add_description_comments(content: str) -> str: |
327 | 348 | lines = content.splitlines() |
328 | 349 | new_lines: list[str] = [] |
|
0 commit comments