Skip to content

Commit

Permalink
merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed May 29, 2024
2 parents 11caac8 + d2670cc commit f43932a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ dcicutils
Change Log
----------


8.8.6
=====
8.10.0
======

* Added merge capabilities to structured_data. (IN PROGRESS: 2025-05-25)
* Added Question class to command_utils (factored out of smaht-submitr).


8.9.0
=====

* Add more schema parsing functions to `schema_utils`.


8.8.6
=====

Expand Down
16 changes: 16 additions & 0 deletions dcicutils/schema_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class JsonSchemaConstants:


class EncodedSchemaConstants:
DESCRIPTION = "description"
IDENTIFYING_PROPERTIES = "identifyingProperties"
LINK_TO = "linkTo"
MERGE_REF = "$merge"
Expand Down Expand Up @@ -187,6 +188,21 @@ def get_one_of_formats(schema: Dict[str, Any]) -> List[str]:
]


def is_link(property_schema: Dict[str, Any]) -> bool:
"""Is property schema a link?"""
return bool(property_schema.get(SchemaConstants.LINK_TO))


def get_enum(property_schema: Dict[str, Any]) -> List[str]:
"""Return the enum of a property schema."""
return property_schema.get(SchemaConstants.ENUM, [])


def get_description(schema: Dict[str, Any]) -> str:
"""Return the description of a schema."""
return schema.get(SchemaConstants.DESCRIPTION, "")


class Schema:

def __init__(self, schema: dict, type: Optional[str] = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.8.6.1b14"
version = "8.9.0.1b1" # TODO: To become 8.10.0
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down
47 changes: 45 additions & 2 deletions test/test_schema_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any, Dict, List

import pytest
from dcicutils import schema_utils
Expand Down Expand Up @@ -41,7 +41,16 @@
}
FORMAT = "email"
PATTERN = "some_regex"
STRING_SCHEMA = {"type": "string", "format": FORMAT, "pattern": PATTERN}
ENUM = ["foo", "bar"]
DESCRIPTION = "foo"
STRING_SCHEMA = {
"type": "string",
"format": FORMAT,
"pattern": PATTERN,
"linkTo": "foo",
"enum": ENUM,
"description": DESCRIPTION,
}
ARRAY_SCHEMA = {"type": "array", "items": [STRING_SCHEMA]}
OBJECT_SCHEMA = {"type": "object", "properties": {"foo": STRING_SCHEMA}}
NUMBER_SCHEMA = {"type": "number"}
Expand Down Expand Up @@ -320,3 +329,37 @@ def test_get_conditional_formats(
schema: Dict[str, Any], expected: Dict[str, Any]
) -> None:
assert schema_utils.get_conditional_formats(schema) == expected


@pytest.mark.parametrize(
"schema,expected",
[
({}, False),
(STRING_SCHEMA, True),
(FORMAT_SCHEMA, False),
],
)
def test_is_link(schema: Dict[str, Any], expected: bool) -> None:
assert schema_utils.is_link(schema) == expected


@pytest.mark.parametrize(
"schema,expected",
[
({}, []),
(STRING_SCHEMA, ENUM),
],
)
def test_get_enum(schema: Dict[str, Any], expected: List[str]) -> None:
assert schema_utils.get_enum(schema) == expected


@pytest.mark.parametrize(
"schema,expected",
[
({}, ""),
(STRING_SCHEMA, DESCRIPTION),
],
)
def test_get_description(schema: Dict[str, Any], expected: str) -> None:
assert schema_utils.get_description(schema) == expected

0 comments on commit f43932a

Please sign in to comment.