diff --git a/converters/dbt/src/ossie_dbt/cli.py b/converters/dbt/src/ossie_dbt/cli.py index 8d71faad..96509f00 100644 --- a/converters/dbt/src/ossie_dbt/cli.py +++ b/converters/dbt/src/ossie_dbt/cli.py @@ -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) @@ -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) diff --git a/examples/flights.yaml b/examples/flights.yaml index 803ff73d..1f10c210 100644 --- a/examples/flights.yaml +++ b/examples/flights.yaml @@ -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 @@ -821,6 +819,9 @@ ontology_mappings: dialects: - dialect: ANSI_SQL expression: name + +ontology_mappings: +- name: flights_mapping concept_mappings: - concept: Runway object_mappings: