|
25 | 25 | REPO_ROOT = Path(__file__).resolve().parent.parent |
26 | 26 | SCHEMA_DIR = REPO_ROOT / "schema" |
27 | 27 | TYPES_DIR = REPO_ROOT / "src" / "mcp-types" / "mcp_types" |
| 28 | +TEMPLATE_DIR = REPO_ROOT / "scripts" / "codegen_templates" |
28 | 29 |
|
29 | 30 | # The result-meta serverInfo stamp: every `$defs` entry carrying this property |
30 | 31 | # gets its typed `$ref` stripped by `make_server_info_opaque` below. |
@@ -191,6 +192,7 @@ def run_codegen(schema_path: Path, output_path: Path) -> None: |
191 | 192 | "--output-model-type", "pydantic_v2.BaseModel", |
192 | 193 | "--target-python-version", "3.10", |
193 | 194 | "--base-class", "mcp_types._wire_base.WireModel", |
| 195 | + "--custom-template-dir", str(TEMPLATE_DIR), |
194 | 196 | "--snake-case-field", "--remove-special-field-name-prefix", |
195 | 197 | "--use-annotated", "--use-field-description", "--use-schema-description", |
196 | 198 | "--enum-field-as-literal", "all", |
@@ -246,7 +248,13 @@ def build(entry: dict[str, str]) -> str: |
246 | 248 | source = raw.read_text(encoding="utf-8") |
247 | 249 |
|
248 | 250 | source = re.sub(r"\A# generated by datamodel-codegen:\n#[^\n]*\n", "", source) |
249 | | - source = re.sub(r"^class Model\(RootModel\[Any\]\):\n {4}root: Any\n+", "", source, count=1, flags=re.MULTILINE) |
| 251 | + source = re.sub( |
| 252 | + r"^class Model\(RootModel\): # pyright: ignore\[reportMissingTypeArgument\]\n {4}root: Any\n+", |
| 253 | + "", |
| 254 | + source, |
| 255 | + count=1, |
| 256 | + flags=re.MULTILINE, |
| 257 | + ) |
250 | 258 | # Codegen appends `| None` to forward refs of nullable models, which is a |
251 | 259 | # runtime TypeError on a string ref and redundant since `JSONValue` includes None. |
252 | 260 | source = source.replace('"JSONValue" | None', '"JSONValue"') |
|
0 commit comments