-
Notifications
You must be signed in to change notification settings - Fork 73
[SYNPY-1696] Add create JSON Schema CLI command #1294
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
base: develop
Are you sure you want to change the base?
Changes from 7 commits
59a0455
671bf21
2b8ee3f
bfd1711
0b97f3b
2d5a882
78b7d14
369ffcf
81e5156
9f17ecc
a25ec2e
a6de851
7b6b7d1
15ba0d3
44e58e2
8caa98f
04336df
e0294c6
076e521
2158fdb
0d7725b
0988bbe
37c9bec
4311284
3b49b10
f1667e0
3857b74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| SynapseHTTPError, | ||
| SynapseNoCredentialsError, | ||
| ) | ||
| from synapseclient.extensions.curator.schema_generation import generate_jsonschema | ||
|
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. What happens when someone doesn't have the extension package installed?
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. It should be tested, however thinking about it I don't think that this would cause any runtime or static typing issues. What I believe to happen is that due to the static typing checks I put in place this would be fine. The optional install of the curation extension is only for a few library dependencies for the curator code to work at runtime. The code like this |
||
| from synapseclient.wiki import Wiki | ||
|
|
||
| tracer = trace.get_tracer("synapseclient") | ||
|
|
@@ -801,6 +802,17 @@ def migrate(args, syn): | |
| result.as_csv(args.csv_log_path) | ||
|
|
||
|
|
||
| def generate_json_schema(args, syn): | ||
| """Generate JSON schema for Synapse entity types""" | ||
| _, path = generate_jsonschema( | ||
| data_model_source=args.data_model_path, | ||
| output=args.output, | ||
| data_types=args.data_types, | ||
| data_model_labels=args.data_model_labels, | ||
| synapse_client=syn, | ||
| ) | ||
andrewelamb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def build_parser(): | ||
| """Builds the argument parser and returns the result.""" | ||
|
|
||
|
|
@@ -1793,6 +1805,45 @@ def build_parser(): | |
| help="Bypass interactive prompt confirming migration", | ||
| ) | ||
|
|
||
| parser_generate_json_schema = subparsers.add_parser( | ||
| "generate-json-schema", help="Generates a JSON Schema file from a data model." | ||
| ) | ||
| parser_generate_json_schema.add_argument( | ||
| "data_model_path", | ||
| type=str, | ||
| help="Required path to CSV or JSONLD data model. Must be a path to a local file, or a URL.", | ||
| ) | ||
| parser_generate_json_schema.add_argument( | ||
| "--data-types", | ||
| nargs="*", | ||
| type=str, | ||
| default=None, | ||
| help="Optional list of data types to generate schema for. If not provided, schema will be generated for all data types in the model.", | ||
| ) | ||
| parser_generate_json_schema.add_argument( | ||
| "--output", | ||
| type=str, | ||
| default=None, | ||
| help=( | ||
| "Optional path. " | ||
| "If None, output file(s) will be created in the current working directory as ./<data-type>.json. " | ||
| "If a directory path, output file(s) will be created in the specified directory as <data-type>.json. " | ||
| "If a file path, schema will be written to the specified file. " | ||
| ), | ||
| ) | ||
| parser_generate_json_schema.add_argument( | ||
| "--data-model-labels", | ||
| type=str, | ||
| default="class_label", | ||
| choices=["class_label", "display_label"], | ||
| help=( | ||
| "Optional Label format for properties in the generated schema. " | ||
| "'class_label' uses standard attribute names (default). " | ||
| "'display_label' uses display names when valid" | ||
| ), | ||
| ) | ||
| parser_generate_json_schema.set_defaults(func=generate_json_schema) | ||
|
|
||
| parser_migrate.set_defaults(func=migrate) | ||
|
|
||
| return parser | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.