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

### Added
- `datacontract api`: `--contract-variables` and `--allow-local-files` options, as alternatives to their environment variables
- `datacontract import odata` creates a datacontract from OData 4 metadata at an URL or from a local file.
- `datacontract test` checks constraints and quality rules of nested properties on servers read through DuckDB (#1278)

### Changed
Expand Down
49 changes: 49 additions & 0 deletions datacontract/command_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,52 @@ 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_document_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, will import all sets from the service document."
),
] = None,
metadata_url: Annotated[
Optional[str],
typer.Option(
help="CSDL XML or JSON URL. Defaults to SERVICE_ROOT_URL/$metadata.",
),
] = None,
metadata_file: Annotated[
Optional[Path],
typer.Option(
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."""
enable_debug_logging(debug)
result = DataContract.import_from_source(
config=cli_config(),
format="odata",
source=service_root_url,
odata_service_document_file=service_document_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
Loading