Skip to content

Commit b19c86c

Browse files
authored
Merge branch 'datacontract:main' into main
2 parents e94e6ec + e1c1015 commit b19c86c

19 files changed

Lines changed: 9328 additions & 17 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
datacontract.sh
55
/cli
66
tmp
7+
/venv
78
/contracts/
89
/quality/
910
db.duckdb

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## Unreleased
9+
### Added
10+
- `datacontract import --format json`: Import from JSON files
911

1012
### Added
1113

1214
### Changed
15+
- `datacontract api [OPTIONS]`: Added option to pass extra arguments for `uvicorn.run()`
1316

1417
### Fixed
18+
- `pytest tests\test_api.py`: Fixed an issue where special characters were not read correctly from file.
1519

1620
## [0.10.28] - 2025-06-05
1721

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,9 +1192,9 @@ FROM
11921192

11931193
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
11941194
│ * --format [sql|avro|dbt|dbml|glue|jsonsc The format of the source file. │
1195-
│ hema|bigquery|odcs|unity|spark [default: None]
1196-
│ |iceberg|parquet|csv|protobuf| [required]
1197-
│ excel]
1195+
│ hema|json|bigquery|odcs|unity| [default: None]
1196+
spark|iceberg|parquet|csv|prot [required]
1197+
obuf|excel]
11981198
│ --output PATH Specify the file path where │
11991199
│ the Data Contract will be │
12001200
│ saved. If no path is provided, │
@@ -1618,6 +1618,8 @@ datacontract catalog --files "*.odcs.yaml"
16181618
information.
16191619
To connect to servers (such as a Snowflake data source), set the credentials as environment
16201620
variables as documented in https://cli.datacontract.com/#test
1621+
It is possible to run the API with extra arguments for `uvicorn.run()` as keyword arguments, e.g.:
1622+
`datacontract api --port 1234 --root_path /datacontract`.
16211623
16221624
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
16231625
│ --port INTEGER Bind socket to this port. [default: 4242] │
@@ -2000,6 +2002,7 @@ We are happy to receive your contributions. Propose your change in an issue or d
20002002
- [INNOQ](https://innoq.com)
20012003
- [Data Catering](https://data.catering/)
20022004
- [Oliver Wyman](https://www.oliverwyman.com/)
2005+
- [dmTECH](https://www.dmtech.tech/de)
20032006
- And many more. To add your company, please create a pull request.
20042007
20052008
## Related Tools

datacontract/cli.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,26 @@ def diff(
469469
console.print(result.changelog_str())
470470

471471

472-
@app.command()
472+
def _get_uvicorn_arguments(port: int, host: str, context: typer.Context) -> dict:
473+
"""
474+
Take the default datacontract uvicorn arguments and merge them with the
475+
extra arguments passed to the command to start the API.
476+
"""
477+
default_args = {
478+
"app": "datacontract.api:app",
479+
"port": port,
480+
"host": host,
481+
"reload": True,
482+
}
483+
484+
# Create a list of the extra arguments, remove the leading -- from the cli arguments
485+
trimmed_keys = list(map(lambda x : str(x).replace("--", ""),context.args[::2]))
486+
# Merge the two dicts and return them as one dict
487+
return default_args | dict(zip(trimmed_keys, context.args[1::2]))
488+
489+
@app.command(context_settings={"allow_extra_args": True, "ignore_unknown_options": True})
473490
def api(
491+
ctx: Annotated[typer.Context, typer.Option(help="Extra arguments to pass to uvicorn.run().")],
474492
port: Annotated[int, typer.Option(help="Bind socket to this port.")] = 4242,
475493
host: Annotated[
476494
str, typer.Option(help="Bind socket to this host. Hint: For running in docker, set it to 0.0.0.0")
@@ -488,14 +506,21 @@ def api(
488506
489507
To connect to servers (such as a Snowflake data source), set the credentials as environment variables as documented in
490508
https://cli.datacontract.com/#test
509+
510+
It is possible to run the API with extra arguments for `uvicorn.run()` as keyword arguments, e.g.:
511+
`datacontract api --port 1234 --root_path /datacontract`.
491512
"""
492513
import uvicorn
493514
from uvicorn.config import LOGGING_CONFIG
494515

495516
log_config = LOGGING_CONFIG
496517
log_config["root"] = {"level": "INFO"}
497518

498-
uvicorn.run(app="datacontract.api:app", port=port, host=host, reload=True, log_config=LOGGING_CONFIG)
519+
uvicorn_args = _get_uvicorn_arguments(port, host, ctx)
520+
# Add the log config
521+
uvicorn_args["log_config"] = log_config
522+
# Run uvicorn
523+
uvicorn.run(**uvicorn_args)
499524

500525

501526
def _print_logs(run):

datacontract/export/sql_type_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def convert_to_databricks(field: Field) -> None | str:
194194
nested_fields = []
195195
for nested_field_name, nested_field in field.fields.items():
196196
nested_field_type = convert_to_databricks(nested_field)
197-
nested_fields.append(f"{nested_field_name} {nested_field_type}")
198-
return f"STRUCT<{', '.join(nested_fields)}>"
197+
nested_fields.append(f"{nested_field_name}:{nested_field_type}")
198+
return f"STRUCT<{','.join(nested_fields)}>"
199199
if type.lower() in ["bytes"]:
200200
return "BINARY"
201201
if type.lower() in ["array"]:

datacontract/imports/importer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ImportFormat(str, Enum):
2626
dbml = "dbml"
2727
glue = "glue"
2828
jsonschema = "jsonschema"
29+
json = "json"
2930
bigquery = "bigquery"
3031
odcs = "odcs"
3132
unity = "unity"

datacontract/imports/importer_factory.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,10 @@ def load_module_class(module_path, class_name):
119119
module_path="datacontract.imports.excel_importer",
120120
class_name="ExcelImporter",
121121
)
122+
123+
124+
importer_factory.register_lazy_importer(
125+
name=ImportFormat.json,
126+
module_path="datacontract.imports.json_importer",
127+
class_name="JsonImporter",
128+
)

0 commit comments

Comments
 (0)