Skip to content
Open
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
23 changes: 22 additions & 1 deletion converters/dbt/src/ossie_dbt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ def _cmd_msi_to_osi(args: argparse.Namespace) -> None:
print(f"Written to {output_path}", file=sys.stderr)


def safe_model_dump(obj, **kwargs):
"""compatible pydantic v1 和 v2"""
if hasattr(obj, 'model_dump_json'):
return obj.model_dump_json(**kwargs)
elif hasattr(obj, 'json'):
return obj.json(**kwargs)
elif hasattr(obj, 'dict'):
# Pydantic v1
return json.dumps(obj.dict(**kwargs), indent=kwargs.get('indent', 2))
elif hasattr(obj, 'model_dump'):
# Pydantic v2
return json.dumps(obj.model_dump(**kwargs), indent=kwargs.get('indent', 2))
else:
return json.dumps(obj.__dict__, indent=kwargs.get('indent', 2))

def _cmd_osi_to_msi(args: argparse.Namespace) -> None:
input_path = Path(args.input)
output_path = Path(args.output)
Expand All @@ -75,7 +90,13 @@ def _cmd_osi_to_msi(args: argparse.Namespace) -> None:
document = OSIDocument.model_validate(raw)
result = OSIToMSIConverter().convert(document)

output_path.write_text(result.output.model_dump_json(by_alias=True, exclude_none=True, indent=2))
json_output = safe_model_dump(
result.output,
by_alias=True,
exclude_none=True,
indent=2
)
output_path.write_text(json_output)
print(f"Written to {output_path}", file=sys.stderr)


Expand Down
9 changes: 5 additions & 4 deletions examples/flights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,8 @@ ontology:
- '{Route} connects to departure- {Airport}' # The hyphen after "departure" has significance when verbalizing constraints
multiplicity: ManyToOne # Each Route connects to at most one departure Airport
requires: [ 'NOT Route.destination(Airport)' ]
ontology_mappings:
- name: flights_mapping
semantic_model:
name: Flights semantic model
semantic_model:
- name: Flights semantic model
datasets:
- name: RUNWAY
source: DATABASE.SCHEMA.RUNWAYS
Expand Down Expand Up @@ -821,6 +819,9 @@ ontology_mappings:
dialects:
- dialect: ANSI_SQL
expression: name

ontology_mappings:
- name: flights_mapping
concept_mappings:
- concept: Runway
object_mappings:
Expand Down