|
| 1 | +JSON Schema is a tool used to validate data. In Synapse, JSON Schemas can be used to validate the metadata applied to an entity such as project, file, folder, table, or view, including the [annotations](https://help.synapse.org/docs/Annotating-Data-With-Metadata.2667708522.html) applied to it. To learn more about JSON Schemas, check out [JSON-Schema.org](https://json-schema.org/). |
| 2 | + |
| 3 | +Synapse supports a subset of features from [json-schema-draft-07](https://json-schema.org/draft-07). To see the list of features currently supported, see the [JSON Schema object definition](https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/schema/JsonSchema.html) from Synapse's REST API Documentation. |
| 4 | + |
| 5 | +In this tutorial, you will learn how to create these JSON Schema using an existing data model. |
| 6 | + |
| 7 | +## Tutorial Purpose |
| 8 | +You will create a JSON schema using your data model. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | +* You have a working [installation](../installation.md) of the Synapse Python Client. |
| 12 | +* You have a data model, see this [example data model](https://github.com/Sage-Bionetworks/schematic/blob/develop/tests/data/example.model.column_type_component.csv). |
| 13 | + |
| 14 | +## 1. Imports |
| 15 | + |
| 16 | +```python |
| 17 | +{!docs/tutorials/python/tutorial_scripts/schema_operations.py!lines=1-2} |
| 18 | +``` |
| 19 | + |
| 20 | +## 2. Set up your variables |
| 21 | + |
| 22 | +```python |
| 23 | +{!docs/tutorials/python/tutorial_scripts/schema_operations.py!lines=4-10} |
| 24 | +``` |
| 25 | + |
| 26 | +To create a JSON Schema you need a data model, and the data types you want to create. |
| 27 | +The data model must be in either CSV or JSON-LD form. The data model may be a local path or a URL. |
| 28 | +[Example data model](https://github.com/Sage-Bionetworks/schematic/blob/develop/tests/data/example.model.column_type_component.csv). |
| 29 | + |
| 30 | +The data types must exist in your data model. This can be a list of data types, or `None` to create all data types in the data model. |
| 31 | + |
| 32 | +## 3. Log into Synapse |
| 33 | +```python |
| 34 | +{!docs/tutorials/python/tutorial_scripts/schema_operations.py!lines=12-13} |
| 35 | +``` |
| 36 | + |
| 37 | + |
| 38 | +## 4. Create the JSON Schema |
| 39 | +Create the JSON Schema(s) |
| 40 | +```python |
| 41 | +{!docs/tutorials/python/tutorial_scripts/schema_operations.py!lines=15-23} |
| 42 | +``` |
| 43 | +You should see the first JSON Schema for the datatype(s) you selected printed. |
| 44 | +It will look like [this schema](https://repo-prod.prod.sagebase.org/repo/v1/schema/type/registered/dpetest-test.schematic.Patient). |
| 45 | + |
| 46 | + |
| 47 | +## Source Code for this Tutorial |
| 48 | + |
| 49 | +<details class="quote"> |
| 50 | + <summary>Click to show me</summary> |
| 51 | + |
| 52 | +```python |
| 53 | +{!docs/tutorials/python/tutorial_scripts/schema_operations.py!} |
| 54 | +``` |
| 55 | +</details> |
| 56 | + |
| 57 | + |
| 58 | +## Reference |
| 59 | +- [JSON Schema Object Definition](https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/schema/JsonSchema.html) |
| 60 | +- [JSON Schema Draft 7](https://json-schema.org/draft-07) |
| 61 | +- [JSON-Schema.org](https://json-schema.org/) |
0 commit comments