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
9 changes: 7 additions & 2 deletions src/pydantic2linkml/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,18 @@ def apply_schema_overlay(schema_yml: str, overlay_file: FilePath) -> str:
:param overlay_file: Path to an existing overlay YAML file
:return: Canonical YAML string with the overlay applied, keys in
SchemaDefinition order
:raises ValueError: If ``schema_yml`` does not deserialize to a dict
:raises ValueError: If ``schema_yml`` does not contain valid YAML or
does not deserialize to a dict
:raises YAMLContentError: If the overlay file does not contain a YAML
mapping
:raises InvalidLinkMLSchemaError: If the result does not conform to
the LinkML meta schema
"""
schema_dict = yaml.safe_load(schema_yml)
try:
schema_dict = yaml.safe_load(schema_yml)
except yaml.YAMLError as e:
raise ValueError(f"schema_yml does not contain valid YAML: {e}") from e

if not isinstance(schema_dict, dict):
raise ValueError(
f"schema_yml did not deserialize to a dict: {type(schema_dict)}"
Expand Down
8 changes: 8 additions & 0 deletions tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ def test_schema_yml_not_dict_raises_value_error(self, tmp_path: Path):
schema_yml="- item1\n- item2\n", overlay_file=overlay_file
)

def test_schema_yml_invalid_yaml_raises_value_error(self, tmp_path: Path):
overlay_file = tmp_path / "overlay.yaml"
overlay_file.write_text("name: new-name\n")
with pytest.raises(ValueError):
apply_schema_overlay(
schema_yml="key: [unclosed\n", overlay_file=overlay_file
)

def test_unknown_field_raises_invalid_schema_error(self, tmp_path: Path):
overlay_file = tmp_path / "overlay.yaml"
overlay_file.write_text("not_a_field: some_value\n")
Expand Down
Loading