|
| 1 | +******************** |
| 2 | +Validate Annotations |
| 3 | +******************** |
| 4 | + |
| 5 | +Validate annotations on your Synapse entities by leveraging the JSON schema services. |
| 6 | +Here are the steps you must take to set up the JSON Schema service. |
| 7 | + |
| 8 | +Create a JSON Schema organization |
| 9 | +================================= |
| 10 | + |
| 11 | +Set up Synapse client and JSON Schema service:: |
| 12 | + |
| 13 | + import synapseclient |
| 14 | + syn = synapseclient.login() |
| 15 | + syn.get_available_services() # Output: ['json_schema'] |
| 16 | + js = syn.service("json_schema") |
| 17 | + |
| 18 | +Create, manage, and delete a JSON Schema organization:: |
| 19 | + |
| 20 | + my_org = js.JsonSchemaOrganization("test.new") |
| 21 | + my_org # Output: JsonSchemaOrganization(name='test.new') |
| 22 | + my_org.create() |
| 23 | + my_org.get_acl() |
| 24 | + my_org.set_acl([3413689]) |
| 25 | + my_org.update_acl([3324230]) |
| 26 | + my_org.delete() |
| 27 | + |
| 28 | +Retrieve existing organization and associated JSON schemas:: |
| 29 | + |
| 30 | + orgs = js.list_organizations() |
| 31 | + sage_org = js.JsonSchemaOrganization("sage.annotations") |
| 32 | + schemas = sage_org.list_json_schemas() |
| 33 | + schema1 = next(schemas) |
| 34 | + schema2 = sage_org.get_json_schema(schema1.name) |
| 35 | + assert schema1 is schema2 # True |
| 36 | + schema1 # Output: JsonSchema(org='sage.annotations', name='analysis.alignmentMethod') |
| 37 | + |
| 38 | +Manage a specific version of a JSON schema:: |
| 39 | + |
| 40 | + versions = schema1.list_versions() |
| 41 | + version1 = next(versions) |
| 42 | + raw_body = version1.body |
| 43 | + full_body = version1.expand() |
| 44 | + version1 # Output: JsonSchemaVersion(org='sage.annotations', name='analysis.alignmentMethod', version='0.0.2') |
| 45 | + |
| 46 | + |
| 47 | +Create a new JSON schema version for an existing organization:: |
| 48 | + from random import randint |
| 49 | + rint = randint(0, 100000) |
| 50 | + org_name = "bgrande.test" |
| 51 | + schema_name = "my.schema" |
| 52 | + |
| 53 | + # Method 1 |
| 54 | + my_org = js.JsonSchemaOrganization(org_name) |
| 55 | + new_version1 = my_org.create_json_schema(raw_body, schema_name, f"0.{rint}.1") |
| 56 | + |
| 57 | + # Method 2 |
| 58 | + my_schema = js.JsonSchema(my_org, schema_name) |
| 59 | + new_version2 = my_schema.create(raw_body, f"0.{rint}.2") |
| 60 | + |
| 61 | + # Method 3 |
| 62 | + my_version = js.JsonSchemaVersion(my_org, schema_name, f"0.{rint}.3") |
| 63 | + new_version3 = my_version.create(raw_body) |
| 64 | + |
| 65 | +Test validation on a Synapse entity:: |
| 66 | + |
| 67 | + from time import sleep |
| 68 | + synapse_id = "syn25922647" |
| 69 | + js.bind_json_schema(new_version1.uri, synapse_id) |
| 70 | + js.get_json_schema(synapse_id) |
| 71 | + sleep(3) |
| 72 | + js.validate(synapse_id) |
| 73 | + js.validate_children(synapse_id) |
| 74 | + js.validation_stats(synapse_id) |
| 75 | + js.unbind_json_schema(synapse_id) |
| 76 | + |
| 77 | +# Access to low-level API functions |
| 78 | +# js.create_organization(organization_name) |
| 79 | +# js.get_organization(organization_name) |
| 80 | +# js.list_organizations() |
| 81 | +# js.delete_organization(organization_id) |
| 82 | +# js.get_organization_acl(organization_id) |
| 83 | +# js.update_organization_acl(organization_id, resource_access, etag) |
| 84 | +# js.list_json_schemas(organization_name) |
| 85 | +# js.list_json_schema_versions(organization_name, json_schema_name) |
| 86 | +# js.create_json_schema(json_schema_body, dry_run) |
| 87 | +# js.get_json_schema_body(json_schema_uri) |
| 88 | +# js.delete_json_schema(json_schema_uri) |
| 89 | +# js.json_schema_validation(json_schema_uri) |
| 90 | +# js.bind_json_schema_to_entity(synapse_id, json_schema_uri) |
| 91 | +# js.get_json_schema_from_entity(synapse_id) |
| 92 | +# js.delete_json_schema_from_entity(synapse_id) |
| 93 | +# js.validate_entity_with_json_schema(synapse_id) |
| 94 | +# js.get_json_schema_validation_statistics(synapse_id) |
| 95 | +# js.get_invalid_json_schema_validation(synapse_id) |
0 commit comments