Skip to content
Closed
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix BigQuery import for repeated fields
- Make Markdown export compatible with XHTML by replacing `<br>` with `<br />` (#1030)

### Added

- Mermaid Exporter - Added mapping `relationships[].customProperties.label` to override the default display of the relationship property/name so diagrams can show UML-like "Association Names" when desired.

## [0.11.4] - 2026-01-19

### Changed
Expand Down
14 changes: 12 additions & 2 deletions datacontract/export/mermaid_exporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from open_data_contract_standard.model import OpenDataContractStandard
from open_data_contract_standard.model import OpenDataContractStandard, Relationship

from datacontract.export.exporter import Exporter

Expand All @@ -7,6 +7,14 @@ class MermaidExporter(Exporter):
def export(self, data_contract, schema_name, server, sql_server_type, export_args) -> dict:
return to_mermaid(data_contract)

def _get_custom_property_value(prop: Relationship, key: str):
"""Get a custom property value."""
if prop.customProperties is None:
return None
for cp in prop.customProperties:
if cp.property == key:
return cp.value
return None

def to_mermaid(data_contract: OpenDataContractStandard) -> str | None:
"""Convert ODCS data contract to Mermaid ER diagram."""
Expand Down Expand Up @@ -37,13 +45,15 @@ def to_mermaid(data_contract: OpenDataContractStandard) -> str | None:
if prop.relationships:
for rel in prop.relationships:
ref_target = getattr(rel, 'to', None) or getattr(rel, 'ref', None)
custom_label = _get_custom_property_value(rel, "label")
Comment thread
garrettsutula marked this conversation as resolved.

if ref_target:
references = ref_target.replace(".", "·")
parts = references.split("·")
referenced_model = _sanitize_name(parts[0]) if len(parts) > 0 else ""
referenced_field = _sanitize_name(parts[1]) if len(parts) > 1 else ""
if referenced_model:
label = referenced_field or clean_name
label = custom_label or referenced_field or clean_name
mmd_references.append(f'"**{referenced_model}**" ||--o{{ "**{clean_model}**" : {label}')

mmd_entity += f'\t"**{clean_model}**" {{\n{entity_block}}}\n'
Expand Down