Skip to content

Commit fe48b08

Browse files
author
Lingling Peng
committed
revert changes to the json schema type
1 parent b6a8340 commit fe48b08

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

synapseclient/extensions/curator/schema_generation.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ class ValidationRuleName(Enum):
9898
IN_RANGE = "inRange"
9999

100100

101+
class JSONSchemaType(Enum):
102+
"""This enum is the currently supported JSON Schema types"""
103+
104+
STRING = "string"
105+
NUMBER = "number"
106+
INTEGER = "integer"
107+
BOOLEAN = "boolean"
108+
109+
101110
class RegexModule(Enum):
102111
"""This enum are allowed modules for the regex validation rule"""
103112

@@ -1636,7 +1645,7 @@ def is_class_in_schema(self, node_label: str) -> bool:
16361645

16371646
def get_node_column_type(
16381647
self, node_label: Optional[str] = None, node_display_name: Optional[str] = None
1639-
) -> str:
1648+
) -> Optional[JSONSchemaType]:
16401649
"""Gets the column type of the node
16411650
16421651
Args:
@@ -1649,7 +1658,9 @@ def get_node_column_type(
16491658
node_label = self._get_node_label(node_label, node_display_name)
16501659
rel_node_label = self.dmr.get_relationship_value("columnType", "node_label")
16511660
type_string = self.graph.nodes[node_label][rel_node_label]
1652-
return type_string
1661+
if type_string is None:
1662+
return type_string
1663+
return JSONSchemaType(type_string)
16531664

16541665
def _get_node_label(
16551666
self, node_label: Optional[str] = None, node_display_name: Optional[str] = None
@@ -2767,7 +2778,7 @@ def define_data_model_relationships(self) -> dict:
27672778
"required_header": False,
27682779
"edge_rel": False,
27692780
"node_attr_dict": {"default": None},
2770-
"allowed_values": ["string", "number", "integer", "boolean"],
2781+
"allowed_values": [enum.value for enum in JSONSchemaType],
27712782
},
27722783
}
27732784

@@ -4349,7 +4360,7 @@ class TraversalNode: # pylint: disable=too-many-instance-attributes
43494360
dependencies: list[str] = field(init=False)
43504361
description: str = field(init=False)
43514362
is_array: bool = field(init=False)
4352-
type: str = field(init=False)
4363+
type: Optional[JSONSchemaType] = field(init=False)
43534364
format: Optional[JSONSchemaFormat] = field(init=False)
43544365
minimum: Optional[float] = field(init=False)
43554366
maximum: Optional[float] = field(init=False)
@@ -4835,7 +4846,7 @@ def _create_array_property(node: Node) -> Property:
48354846

48364847
items: Items = {}
48374848
if node.type:
4838-
items["type"] = node.type
4849+
items["type"] = node.type.value
48394850
_set_type_specific_keywords(items, node)
48404851

48414852
array_type_dict: TypeDict = {"type": "array", "title": "array"}
@@ -4908,10 +4919,10 @@ def _create_simple_property(node: Node) -> Property:
49084919

49094920
if node.type:
49104921
if node.is_required:
4911-
prop["type"] = node.type
4922+
prop["type"] = node.type.value
49124923
else:
49134924
prop["oneOf"] = [
4914-
{"type": node.type, "title": node.type},
4925+
{"type": node.type.value, "title": node.type.value},
49154926
{"type": "null", "title": "null"},
49164927
]
49174928
elif node.is_required:

tests/unit/synapseclient/extensions/unit_test_create_json_schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
GraphTraversalState,
2121
JSONSchema,
2222
JSONSchemaFormat,
23+
JSONSchemaType,
2324
TraversalNode,
2425
_create_array_property,
2526
_create_enum_array_property,
@@ -246,7 +247,7 @@ def test_update_property(self) -> None:
246247
)
247248
def test_node_init(
248249
node_name: str,
249-
expected_type: str,
250+
expected_type: Optional[JSONSchemaType],
250251
expected_is_array: bool,
251252
expected_min: Optional[float],
252253
expected_max: Optional[float],

0 commit comments

Comments
 (0)