Skip to content

Commit b5ada1e

Browse files
jahlenjschoedl
andauthored
Add OData import support (#1649)
* Added support for OData * Simplified OData tests and added changelog entry * Minor text updates. * Updated documentation and tests. * test: remove duplicate OData test fixtures * docs: add OData logo icon and update import pages to use it * Updated after review. --------- Co-authored-by: Jakob Schödl <jakob.schoedl@entropy-data.com>
1 parent c8b8e40 commit b5ada1e

26 files changed

Lines changed: 2057 additions & 12 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

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

1415
### Changed

‎datacontract/command_import.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,3 +909,52 @@ def import_athena(
909909
id=id,
910910
)
911911
_write_result(result, output)
912+
913+
914+
@import_app.command(
915+
name="odata",
916+
epilog="Example: datacontract import odata --service-root-url https://example.com/odata/ --entity-set Products --output datacontract.yaml",
917+
)
918+
def import_odata(
919+
service_root_url: Annotated[str, typer.Option(help="HTTP(S) root URL of the OData service.")],
920+
service_document_file: Annotated[
921+
Optional[Path],
922+
typer.Option(help="Local JSON service document. Ignored when --entity-set is supplied."),
923+
] = None,
924+
entity_set: Annotated[
925+
Optional[List[str]],
926+
typer.Option(
927+
help="EntitySet to import (repeat for multiple sets). If omitted, will import all sets from the service document."
928+
),
929+
] = None,
930+
metadata_url: Annotated[
931+
Optional[str],
932+
typer.Option(
933+
help="CSDL XML or JSON URL. Defaults to SERVICE_ROOT_URL/$metadata.",
934+
),
935+
] = None,
936+
metadata_file: Annotated[
937+
Optional[Path],
938+
typer.Option(
939+
help="Path to a local OData CSDL XML or JSON file. Use either --metadata-file or --metadata-url.",
940+
),
941+
] = None,
942+
output: output_option = None,
943+
owner: owner_option = None,
944+
id: id_option = None,
945+
debug: debug_option = None,
946+
):
947+
"""Import a data contract from OData 4.x CSDL XML or JSON metadata, using a URL or local file."""
948+
enable_debug_logging(debug)
949+
result = DataContract.import_from_source(
950+
config=cli_config(),
951+
format="odata",
952+
source=service_root_url,
953+
odata_service_document_file=service_document_file,
954+
odata_entity_set=entity_set,
955+
odata_metadata_url=metadata_url,
956+
odata_metadata_file=metadata_file,
957+
owner=owner,
958+
id=id,
959+
)
960+
_write_result(result, output)

‎datacontract/imports/importer.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ImportFormat(str, Enum):
4040
json = "json"
4141
bigquery = "bigquery"
4242
odcs = "odcs"
43+
odata = "odata"
4344
unity = "unity"
4445
databricks = "databricks"
4546
spark = "spark"

‎datacontract/imports/importer_factory.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,8 @@ def load_module_class(module_path, class_name):
187187
module_path="datacontract.imports.json_importer",
188188
class_name="JsonImporter",
189189
)
190+
importer_factory.register_lazy_importer(
191+
name=ImportFormat.odata,
192+
module_path="datacontract.imports.odata_importer",
193+
class_name="ODataImporter",
194+
)

0 commit comments

Comments
 (0)