From cb17c93a1d2d2f4c60a4944b349a245ba7db7f37 Mon Sep 17 00:00:00 2001 From: DevForge Engineer Date: Mon, 18 May 2026 14:09:39 -0400 Subject: [PATCH] fix(cli): improve format detection to support all 11 schema formats - Update _detect_format to correctly map all format extensions - Fix .json mapping from typeorm to json_schema - Add .graphql, .gql, .cs, .scala extension support - Add 12 tests for _detect_format covering all extensions - Fix MCP server docstring: 9 -> 11 formats --- src/schemaforge/cli.py | 24 +++++++++--------- src/schemaforge/mcp_server.py | 2 +- tests/test_cli.py | 46 ++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/schemaforge/cli.py b/src/schemaforge/cli.py index b743107..63553ed 100644 --- a/src/schemaforge/cli.py +++ b/src/schemaforge/cli.py @@ -136,15 +136,17 @@ def check(directory: str, canonical: str, type_map_path: str | None) -> None: def _detect_format(path: str) -> str: ext = Path(path).suffix.lower() - if ext == ".sql": - return "sql" - if ext == ".prisma": - return "prisma" - if ext in (".ts", ".tsx"): - return "drizzle" - if ext == ".py": - return "django" - if ext in (".json",): - return "typeorm" - return "sql" # default + ext_map = { + ".sql": "sql", + ".prisma": "prisma", + ".ts": "drizzle", + ".tsx": "drizzle", + ".py": "django", + ".json": "json_schema", + ".graphql": "graphql", + ".gql": "graphql", + ".cs": "ef", + ".scala": "scala", + } + return ext_map.get(ext, "sql") diff --git a/src/schemaforge/mcp_server.py b/src/schemaforge/mcp_server.py index 17f395e..450c3cd 100644 --- a/src/schemaforge/mcp_server.py +++ b/src/schemaforge/mcp_server.py @@ -55,7 +55,7 @@ def create_server() -> Any: @server.tool( name="convert", description="Convert a schema from one format to another. " - "All 9 formats support conversion to and from every other format. " + "All 11 formats support conversion to and from every other format. " "Returns the converted schema as text.", ) def convert_tool( diff --git a/tests/test_cli.py b/tests/test_cli.py index 979a122..2a20faf 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -12,7 +12,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent / "src")) -from schemaforge.cli import main +from schemaforge.cli import _detect_format, main # ── Helpers ── @@ -459,3 +459,47 @@ def test_check_help(self): assert result.exit_code == 0 assert "Usage:" in result.output assert "--dir" in result.output + + +# ═══════════════════════════════════════════════════════════════ +# _detect_format +# ═══════════════════════════════════════════════════════════════ + +class TestDetectFormat: + """Tests for the private _detect_format helper.""" + + def test_sql_extension(self): + assert _detect_format("schema.sql") == "sql" + + def test_prisma_extension(self): + assert _detect_format("schema.prisma") == "prisma" + + def test_drizzle_ts(self): + assert _detect_format("schema.ts") == "drizzle" + + def test_drizzle_tsx(self): + assert _detect_format("schema.tsx") == "drizzle" + + def test_django_python(self): + assert _detect_format("models.py") == "django" + + def test_json_schema(self): + assert _detect_format("schema.json") == "json_schema" + + def test_graphql(self): + assert _detect_format("schema.graphql") == "graphql" + + def test_graphql_gql(self): + assert _detect_format("schema.gql") == "graphql" + + def test_ef_csharp(self): + assert _detect_format("entities.cs") == "ef" + + def test_scala(self): + assert _detect_format("models.scala") == "scala" + + def test_unknown_extension_defaults_to_sql(self): + assert _detect_format("schema.txt") == "sql" + + def test_no_extension_defaults_to_sql(self): + assert _detect_format("schema") == "sql"