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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- `datacontract import odata` creates a datacontract from OData 4 metadata at an URL or from a local file.

## [1.2.1] - 2026-09-22

### Highlights
Expand Down
51 changes: 51 additions & 0 deletions datacontract/command_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,54 @@ def import_athena(
id=id,
)
_write_result(result, output)


@import_app.command(
name="odata",
epilog="Example: datacontract import odata --service-root-url https://example.com/odata/ --entity-set Products --output datacontract.yaml",
)
def import_odata(
service_root_url: Annotated[str, typer.Option(help="HTTP(S) root URL of the OData service.")],
service_root_file: Annotated[
Optional[Path],
typer.Option(help="Local JSON service document. Ignored when --entity-set is supplied."),
] = None,
entity_set: Annotated[
Optional[List[str]],
typer.Option(help="EntitySet to import (repeat for multiple sets). If omitted, use the service document."),
] = None,
metadata_url: Annotated[
Optional[str],
typer.Option(
"--metadata-url",
help="CSDL XML or JSON URL. Defaults to SERVICE_ROOT_URL/$metadata unless --metadata-file is supplied.",
),
] = None,
metadata_file: Annotated[
Optional[Path],
typer.Option(
"--metadata-file",
help="Path to a local OData CSDL XML or JSON file. Use either --metadata-file or --metadata-url.",
),
] = None,
output: output_option = None,
owner: owner_option = None,
id: id_option = None,
debug: debug_option = None,
):
"""Import a data contract from OData 4.x CSDL XML or JSON metadata, using a URL or local file."""
if metadata_url is not None and metadata_file is not None:
raise typer.BadParameter("--metadata-url and --metadata-file are mutually exclusive.")
enable_debug_logging(debug)
result = DataContract.import_from_source(
config=cli_config(),
format="odata",
source=service_root_url,
odata_service_root_file=service_root_file,
odata_entity_set=entity_set,
odata_metadata_url=metadata_url,
odata_metadata_file=metadata_file,
owner=owner,
id=id,
)
_write_result(result, output)
1 change: 1 addition & 0 deletions datacontract/imports/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ImportFormat(str, Enum):
json = "json"
bigquery = "bigquery"
odcs = "odcs"
odata = "odata"
unity = "unity"
databricks = "databricks"
spark = "spark"
Expand Down
5 changes: 5 additions & 0 deletions datacontract/imports/importer_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,8 @@ def load_module_class(module_path, class_name):
module_path="datacontract.imports.json_importer",
class_name="JsonImporter",
)
importer_factory.register_lazy_importer(
name=ImportFormat.odata,
module_path="datacontract.imports.odata_importer",
class_name="ODataImporter",
)
Loading