Skip to content

Commit

Permalink
Fixed: HTML Export needs updating to support V1.1.0 of the Data Contr…
Browse files Browse the repository at this point in the history
…act Spec

resolves #497
  • Loading branch information
jochenchrist committed Jan 19, 2025
1 parent 246aa40 commit dc3ad62
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- publish command also supports publishing ODCS format

### Changed

- JSON Schemas are now bundled with the application (#598)
- datacontract export --format html: The model title is now shown if it is different to the model
name (#585)
- datacontract export --format html: Custom model attributes are now shown (#585)
- datacontract export --format html: The composite primary key is now shown. (#591)
- datacontract export --format html: now examples are rendered in the model and definition (#497)

### Fixed

- datacontract lint: Linter 'Field references existing field' too many values to unpack (expected
2) (#586)

## [0.10.18] - 2024-01-18

### Fixed

- Fixed an issue when resolving project's dependencies when all extras are installed.
- Definitions referenced by nested fields are not validated correctly (#595)
- Replaced deprecated `primary` field with `primaryKey` in exporters, importers, examples, and Jinja templates for backward compatibility. Fixes [#518](https://github.com/your-repo/your-project/issues/518).
Expand Down
4 changes: 1 addition & 3 deletions datacontract/integration/datamesh_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ def publish_test_results_to_datamesh_manager(run: Run, publish_url: str, ssl_ver
run.log_error(f"Failed publishing test results. Error: {str(e)}")


def publish_data_contract_to_datamesh_manager(
data_contract_dict: dict, ssl_verification: bool
):
def publish_data_contract_to_datamesh_manager(data_contract_dict: dict, ssl_verification: bool):
try:
api_key = os.getenv("DATAMESH_MANAGER_API_KEY")
host = "https://api.datamesh-manager.com"
Expand Down
1 change: 1 addition & 0 deletions datacontract/lint/resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def resolve_data_contract(
engine="datacontract",
)


def resolve_data_contract_dict(
data_contract_location: str = None,
data_contract_str: str = None,
Expand Down
1 change: 1 addition & 0 deletions datacontract/model/data_contract_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Definition(pyd.BaseModel):
tags: List[str] = []
links: Dict[str, str] = {}
example: str = None
examples: List[Any] | None = None

model_config = pyd.ConfigDict(
extra="allow",
Expand Down
20 changes: 15 additions & 5 deletions datacontract/templates/partials/definition.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% if definition.title %}
<div>{{ definition.title }}</div>
{% endif %}
<div class="font-mono">{{ definition.name }}</div>
<div class="font-mono">{{ definition_name }}</div>
</div>
</td>
<td class="whitespace-nowrap px-1 py-2 text-sm text-gray-500 w-1/12">
Expand All @@ -33,21 +33,31 @@
</td>
<td class="px-3 py-2 text-sm text-gray-500 w-9/12">
{% if definition.example %}
<div class="mt-1">
<span class="text-gray-600 font-medium">Example:</span> <span class="font-mono">{{ definition.example }}</span>
<div class="mt-1 italic">
<span class="text-gray-600">Example:</span> <span class="font-mono">{{ definition.example }}</span>
</div>
{% endif %}

{% if definition.examples %}
<div class="mt-1 italic">
<span class="text-gray-600">Examples:</span>
{% for example in definition.examples %}
<span class="font-mono">{{ example }}</span>{% if not loop.last %}, {% endif %}
{% endfor %}
</div>
{% endif %}

{% if definition.tags %}
<div>
<span class="text-gray-600 font-medium">Tags:</span>
<span class="text-gray-600 italic">Tags:</span>
{% for tag in definition.tags %}
<span class="inline-flex items-center rounded-md bg-gray-50 px-1 py-1 text-xs font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10 mr-1 mt-1">{{ tag }}</span>
{% endfor %}
</div>
{% endif %}
{% if definition.enum %}
<div class="py-2 text-sm">
<span class="text-gray-600 font-medium">Enum:</span>
<span class="text-gray-600 italic">Enum:</span>
{% for value in definition.enum %}
<span class="inline-flex items-center rounded-md bg-gray-50 px-1 py-1 text-xs font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10 mr-1 mt-1">{{ value }}</span>
{% endfor %}
Expand Down
9 changes: 9 additions & 0 deletions datacontract/templates/partials/model_field.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
</div>
{% endif %}

{% if field.examples %}
<div class="mt-1 italic">
Examples:
{% for example in field.examples %}
<span class="font-mono">{{ example }}</span>{% if not loop.last %}, {% endif %}
{% endfor %}
</div>
{% endif %}

<div>
{% if field.primaryKey or field.primary %}
<span class="inline-flex items-center rounded-md bg-gray-50 px-1 py-1 text-xs font-medium text-gray-600 ring-1 ring-inset ring-gray-500/10 mr-1 mt-1">primary</span>
Expand Down
14 changes: 13 additions & 1 deletion tests/fixtures/export/datacontract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,16 @@ models:
query: |
SELECT COUNT(*) AS row_count
FROM orders
mustBeGreaterThan: 1000
mustBeGreaterThan: 1000
definitions:
customer_id:
title: Customer ID
type: string
format: uuid
description: Unique identifier for the customer.
examples:
- acbd1a47-9dca-4cb8-893e-87aa0aa0f243
- 5742637f-bb8b-4f0c-8ed1-afb1a91300a9
tags:
- features
- pii

0 comments on commit dc3ad62

Please sign in to comment.