Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/server/src/mdl_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def export_model(fmt: str, dialect: str = "postgres"):
"""Export the model to an interchange format. Returns text/plain (or CSV) so
the browser can offer it as a download."""
from fastapi.responses import PlainTextResponse
from mdl_emit_erd import emit_csv, emit_dbml, emit_mermaid, emit_sql_ddl
from mdl_emit_erd import emit_csv, emit_dbml, emit_erwin, emit_mermaid, emit_sql_ddl

model = _load().model
try:
Expand All @@ -224,6 +224,10 @@ def export_model(fmt: str, dialect: str = "postgres"):
text, media, ext = emit_mermaid(model), "text/plain", "mmd"
elif fmt == "dbml":
text, media, ext = emit_dbml(model), "text/plain", "dbml"
elif fmt == "erwin":
# the team naming convention (if any) travels in the project config, same as the CLI
text = emit_erwin(model, naming=model.config.export.erwin.naming)
media, ext = "application/xml", "xml"
elif fmt == "csv":
text, media, ext = emit_csv(model), "text/csv", "csv"
elif fmt == "contract":
Expand Down Expand Up @@ -260,6 +264,7 @@ def export_formats() -> JSONResponse:
},
{"id": "mermaid", "label": "Mermaid erDiagram"},
{"id": "dbml", "label": "DBML (dbdiagram.io)"},
{"id": "erwin", "label": "erwin XML"},
{"id": "csv", "label": "CSV (spreadsheet)"},
{"id": "contract", "label": "Data contract (ODCS)"},
{"id": "cypher", "label": "Neo4j Cypher"},
Expand Down
13 changes: 12 additions & 1 deletion packages/server/tests/test_import_export_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ def client(model_dir):
def test_export_formats_list(client):
body = client.get("/api/export").json()
ids = {f["id"] for f in body["formats"]}
assert {"sql", "mermaid", "dbml", "csv"} <= ids
assert {"sql", "mermaid", "dbml", "erwin", "csv"} <= ids


def test_export_erwin(client):
"""The Export menu's erwin option serves a downloadable erwin XML document."""
r = client.get("/api/export/erwin")
assert r.status_code == 200
assert r.headers["content-type"].startswith("application/xml")
assert 'filename="' in r.headers["content-disposition"] and ".xml" in (
r.headers["content-disposition"]
)
assert r.text.lstrip().startswith("<?xml") and 'Format="erwin"' in r.text


def test_export_sql(client):
Expand Down
Loading