-
Notifications
You must be signed in to change notification settings - Fork 73
[SYNPY-1697] Add Create JSON Schema tutorial #1271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrewelamb
wants to merge
11
commits into
develop
Choose a base branch
from
new_tutorial
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6238fb9
added new tutorial
andrewelamb 340eec0
rename file
andrewelamb 5d6c107
fixes to tutorial
andrewelamb a27e7eb
fixes to tutorial
andrewelamb 8d1bea5
renamed files
andrewelamb 8557276
added tutorial to yaml file
andrewelamb e338c9f
add data model assumption
andrewelamb 745976e
used different function for tutorial
andrewelamb 9b7bd9d
remove links
andrewelamb 8bc8ee1
Update docs/tutorials/python/tutorial_scripts/schema_operations.py
andrewelamb d0d9c0d
Update docs/tutorials/python/schema_operations.md
andrewelamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| 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/). | ||
|
|
||
| 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. | ||
|
|
||
| In this tutorial, you will learn how to create these JSON Schema using an existing data-model. | ||
|
|
||
| ## Tutorial Purpose | ||
| You will create a JSON schema using your data model. | ||
|
|
||
| ## Prerequisites | ||
| * You have a working [installation](../installation.md) of the Synapse Python Client. | ||
andrewelamb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * You have a data-model, see [here](https://sagebionetworks.jira.com/wiki/spaces/SCHEM/pages/2473623559/The+Data+Model+Schema) | ||
|
|
||
| ## 1. Imports | ||
|
|
||
| ```python | ||
| {!docs/tutorials/python/tutorial_scripts/schema_operations.py!lines=1-2} | ||
| ``` | ||
|
|
||
| ## 2. Set up your variables | ||
|
|
||
| ```python | ||
| {!docs/tutorials/python/tutorial_scripts/schema_operations.py!lines=4-10} | ||
| ``` | ||
|
|
||
| To create a JSON Schema you need a data-model, and the data-types you want to create. | ||
| The data-model must be in either CSV or JSON-LD form. The data model may be a local path or a URL. | ||
|
|
||
| The data-types must exist in your data-model. This cna be a list of data-types, or `None` to create all datatatypes in the data-model. | ||
|
|
||
| ## 3. Log into Synapse | ||
| ```python | ||
| {!docs/tutorials/python/tutorial_scripts/schema_operations.py!lines=12-13} | ||
| ``` | ||
|
|
||
|
|
||
| ## 4. Create the JSON Schema | ||
| Create the JSON Schema(s) | ||
| ```python | ||
| {!docs/tutorials/python/tutorial_scripts/schema_operations.py!lines=15-23} | ||
| ``` | ||
| You should see the first JSON Schema for the datatype(s) you selected printed. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you include the example output of what would be printed here given the example URL data model that we will use? That way folks have a bit of context of what to expect. |
||
|
|
||
|
|
||
| ## Source Code for this Tutorial | ||
|
|
||
| <details class="quote"> | ||
| <summary>Click to show me</summary> | ||
|
|
||
| ```python | ||
| {!docs/tutorials/python/tutorial_scripts/schema_operations.py!} | ||
| ``` | ||
| </details> | ||
|
|
||
|
|
||
| ## Reference | ||
| - [JSON Schema Object Definition](https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/schema/JsonSchema.html) | ||
| - [JSON Schema Draft 7](https://json-schema.org/draft-07) | ||
| - [JSON-Schema.org](https://json-schema.org./) | ||
23 changes: 23 additions & 0 deletions
23
docs/tutorials/python/tutorial_scripts/schema_operations.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from synapseclient import Synapse | ||
| from synapseclient.extensions.curator import generate_jsonschema | ||
|
|
||
| # Put the path/url of your data model here, either CSV or JSONLD format | ||
| DATA_MODEL_SOURCE = "tests/unit/synapseclient/extensions/schema_files/example.model.csv" | ||
| # Put the names of the datatypes in your data-model you want to create here | ||
| # or None to create them all | ||
| DATA_TYPE = ["Patient"] | ||
| # Put the directory where you want the JSONSchema to generated at here | ||
| OUTPUT_DIRECTORY = "./" | ||
|
|
||
| syn = Synapse() | ||
| syn.login() | ||
|
|
||
| schemas, file_paths = generate_jsonschema( | ||
| data_model_source=DATA_MODEL_SOURCE, | ||
| output_directory=OUTPUT_DIRECTORY, | ||
| data_type=DATA_TYPE, | ||
| data_model_labels="class_label", | ||
| synapse_client=syn, | ||
| ) | ||
|
|
||
| print(schemas[0]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.