Skip to content

Commit 09aed31

Browse files
committed
update docstring to ensure return type gets shown up correctly; fix problem in tutorial; add more dataclasses
1 parent 6ac7d0e commit 09aed31

File tree

5 files changed

+42
-29
lines changed

5 files changed

+42
-29
lines changed

docs/reference/experimental/mixins/base_json_schema.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
::: synapseclient.models.mixins.JSONSchemaValidation
66
::: synapseclient.models.mixins.InvalidJSONSchemaValidation
77
::: synapseclient.models.mixins.JSONSchemaDerivedKeys
8+
::: synapseclient.models.mixins.ValidationException
9+
::: synapseclient.models.mixins.CausingException

docs/tutorials/python/json_schema.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ By the end of this tutorial, you will:
1515
6. View schema validation statistics and results
1616

1717
## Prerequisites
18-
* You have a working [installation](../installation.md)of the Synapse Python Client.
18+
* You have a working [installation](../installation.md) of the Synapse Python Client.
1919
* Make sure that you have completed the [Project](./project.md) tutorial, which covers creating and managing projects in Synapse. This is a prerequisite because you need a project to organize and store the folder used in this tutorial.
2020
* You are familiar with Synapse concepts: [Project](./project.md), [Folder](./folder.md), [File](./file.md).
2121
* You are familiar with [adding annotations](./annotation.md) to synapse entity.
@@ -42,13 +42,13 @@ Next, try creating a test organization and register a schema if they do not alre
4242
{!docs/tutorials/python/tutorial_scripts/json_schema.py!lines=51-65}
4343
```
4444

45-
Note: If you make an update to your schema, you can re-register your schema with the organization and give it a new version number:
45+
Note: If you update your schema, you can re-register it with the organization and assign a new version number to reflect the changes:
4646
```python
4747
{!docs/tutorials/python/tutorial_scripts/json_schema.py!lines=67-90}
4848
```
4949

5050
## 4. Bind the JSON Schema to the Folder
51-
After creating the organization, you can now bind your json schema to a test folder. When you bind a JSON Schema to a project or folder, then all items inside of the project or folder will inherit the schema binding, unless the item has a schema bound to itself.
51+
After creating the organization, you can now bind your json schema to a test folder. When you bind a JSON Schema to a container entity such as a project or folder, then all items inside of the project or folder will inherit the schema binding, unless the item has a schema bound to itself.
5252

5353
When you bind the schema, you may also include the boolean property `enable_derived_annos` to have Synapse automatically calculate derived annotations based on the schema:
5454

@@ -144,7 +144,7 @@ In the synapse web UI, you could also see your invalid annotations being marked
144144

145145
This step is only relevant for container entities, such as a folder or a project.
146146

147-
Try creating a test file locally and store the file in the folder that we created earlier. Then, try adding invalid annotations to a file. This step demonstrates how the files inside a folder also inherit the schema from the parent entity.
147+
Try creating a test file locally and store the file in the folder that we created earlier. Then, try adding invalid annotations to that file. This step demonstrates how the files inside a folder also inherit the schema from the parent entity.
148148
```python
149149
{!docs/tutorials/python/tutorial_scripts/json_schema.py!lines=121-146}
150150
```

docs/tutorials/python/tutorial_scripts/json_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# Retrieve test project
1414
PROJECT_ID = syn.findEntityId(
15-
name="My uniquely named project about Alzheimer's Disease 2"
15+
name="My uniquely named project about Alzheimer's Disease"
1616
)
1717

1818
# Create a test folder for JSON schema experiments

synapseclient/models/mixins/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
from synapseclient.models.mixins.asynchronous_job import AsynchronousCommunicator
55
from synapseclient.models.mixins.json_schema import (
66
BaseJSONSchema,
7+
CausingException,
78
ContainerEntityJSONSchema,
89
InvalidJSONSchemaValidation,
910
JSONSchemaBinding,
1011
JSONSchemaDerivedKeys,
1112
JSONSchemaValidation,
1213
JSONSchemaValidationStatistics,
14+
ValidationException,
1315
)
1416
from synapseclient.models.mixins.storable_container import StorableContainer
1517

@@ -24,4 +26,6 @@
2426
"InvalidJSONSchemaValidation",
2527
"JSONSchemaDerivedKeys",
2628
"JSONSchemaValidationStatistics",
29+
"ValidationException",
30+
"CausingException",
2731
]

synapseclient/models/mixins/json_schema.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,14 @@ async def bind_schema_async(
203203
Bind a JSON schema to the entity.
204204
205205
Arguments:
206-
json_schema_uri (str): The URI of the JSON schema to bind to the entity.
207-
enable_derived_annos (bool, optional): If true, enable derived annotations. Defaults to False.
208-
synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided,
206+
json_schema_uri: The URI of the JSON schema to bind to the entity.
207+
enable_derived_annos: If true, enable derived annotations. Defaults to False.
208+
synapse_client: The Synapse client instance. If not provided,
209209
the last created instance from the Synapse class constructor will be used.
210210
211+
Returns:
212+
An object containing details about the JSON schema binding.
213+
211214
Example: Using this function
212215
Binding JSON schema to a folder or a file
213216
@@ -280,8 +283,6 @@ async def bind_schema_to_file():
280283
return bound_schema_file
281284
asyncio.run(bind_schema_to_file())
282285
```
283-
Returns:
284-
JSONSchemaBinding: An object containing details about the JSON schema binding.
285286
"""
286287
response = await bind_json_schema_to_entity(
287288
synapse_id=self.id,
@@ -315,10 +316,14 @@ async def get_schema_async(
315316
) -> JSONSchemaBinding:
316317
"""
317318
Get the JSON schema bound to the entity.
319+
318320
Arguments:
319-
synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided,
321+
synapse_client: The Synapse client instance. If not provided,
320322
the last created instance from the Synapse class constructor will be used.
321323
324+
Returns:
325+
An object containing details about the bound JSON schema.
326+
322327
Example: Using this function
323328
Retrieving the bound JSON schema from a folder or file
324329
@@ -332,7 +337,8 @@ async def get_schema_async(
332337
333338
# Define Project and JSON schema info
334339
PROJECT_ID = syn.findEntityId(name="test_json_schema_project") #replace with your project name
335-
ORG_NAME = "UniqueOrg" # replace with your organization name SCHEMA_NAME = "myTestSchema" # replace with your schema name
340+
ORG_NAME = "UniqueOrg" # replace with your organization name
341+
SCHEMA_NAME = "myTestSchema" # replace with your schema name
336342
VERSION = "0.0.1"
337343
SCHEMA_URI = f"{ORG_NAME}-{SCHEMA_NAME}-{VERSION}"
338344
@@ -404,8 +410,6 @@ async def get_bound_schema_from_file():
404410
bound_schema_file = asyncio.run(get_bound_schema_from_file())
405411
print("Bound schema from file retrieved:", bound_schema_file)
406412
```
407-
Returns:
408-
JSONSchemaBinding: An object containing details about the bound JSON schema.
409413
"""
410414
response = await get_json_schema_from_entity(
411415
synapse_id=self.id, synapse_client=synapse_client
@@ -440,7 +444,7 @@ async def unbind_schema_async(
440444
Unbind the JSON schema bound to the entity.
441445
442446
Arguments:
443-
synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided,
447+
synapse_client: The Synapse client instance. If not provided,
444448
the last created instance from the Synapse class constructor will be used.
445449
446450
Example: Using this function
@@ -542,6 +546,9 @@ async def validate_schema_async(
542546
synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided,
543547
the last created instance from the Synapse class constructor will be used.
544548
549+
Returns:
550+
The validation results.
551+
545552
Example: Using this function
546553
Validating a folder or file against the bound JSON schema
547554
@@ -635,8 +642,6 @@ async def validate_file_with_json_schema():
635642
validation_response_file = asyncio.run(validate_file_with_json_schema())
636643
print('validation response:', validation_response_file)
637644
```
638-
Returns:
639-
Union[JSONSchemaValidation, InvalidJSONSchemaValidation]: The validation results.
640645
"""
641646
response = await validate_entity_with_json_schema(
642647
synapse_id=self.id, synapse_client=synapse_client
@@ -706,6 +711,9 @@ async def get_schema_derived_keys_async(
706711
synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided,
707712
the last created instance from the Synapse class constructor will be used.
708713
714+
Returns:
715+
An object containing the derived keys for the entity.
716+
709717
Example: Using this function
710718
Retrieving derived keys from a folder or file
711719
@@ -797,8 +805,6 @@ async def get_schema_derived_keys_from_file():
797805
return derived_keys_file
798806
print('Derived keys from file:', asyncio.run(get_schema_derived_keys_from_file()))
799807
```
800-
Returns:
801-
JSONSchemaDerivedKeys: An object containing the derived keys for the entity.
802808
"""
803809
response = await get_json_schema_derived_keys(
804810
synapse_id=self.id, synapse_client=synapse_client
@@ -824,6 +830,9 @@ async def get_schema_validation_statistics_async(
824830
synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided,
825831
the last created instance from the Synapse class constructor will be used.
826832
833+
Returns:
834+
The validation statistics.
835+
827836
Example: Using this function
828837
Retrieving validation statistics for a folder
829838
@@ -894,8 +903,6 @@ async def get_validation_statistics():
894903
stats = asyncio.run(get_validation_statistics())
895904
print('Validation statistics:', stats)
896905
```
897-
Returns:
898-
JSONSchemaValidationStatistics: The validation statistics.
899906
"""
900907
response = await get_json_schema_validation_statistics(
901908
synapse_id=self.id, synapse_client=synapse_client
@@ -919,6 +926,10 @@ async def get_invalid_validation_async(
919926
synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided,
920927
the last created instance from the Synapse class constructor will be used.
921928
929+
Yields:
930+
An object containing the validation response, all validation messages,
931+
and the validation exception details.
932+
922933
Example: Using this function
923934
Retrieving invalid validation results for a folder
924935
@@ -987,10 +998,6 @@ async def get_invalid_validation_async():
987998
async for child in gen:
988999
print(child)
9891000
```
990-
991-
Yields:
992-
InvalidJSONSchemaValidation: An object containing the validation response, all validation messages,
993-
and the validation exception details.
9941001
"""
9951002
gen = get_invalid_json_schema_validation(
9961003
synapse_client=synapse_client, synapse_id=self.id
@@ -1050,6 +1057,10 @@ def get_invalid_validation(
10501057
synapse_client (Optional[Synapse], optional): The Synapse client instance. If not provided,
10511058
the last created instance from the Synapse class constructor will be used.
10521059
1060+
Yields:
1061+
An object containing the validation response, all validation messages,
1062+
and the validation exception details.
1063+
10531064
Example: Using this function
10541065
Retrieving invalid validation results for a folder
10551066
@@ -1117,10 +1128,6 @@ async def bind_json_schema():
11171128
for child in invalid_results:
11181129
print(child)
11191130
```
1120-
1121-
Yields:
1122-
InvalidJSONSchemaValidation: An object containing the validation response, all validation messages,
1123-
and the validation exception details.
11241131
"""
11251132
gen = get_invalid_json_schema_validation_sync(
11261133
synapse_client=synapse_client, synapse_id=self.id

0 commit comments

Comments
 (0)