-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(json-schema): added default mode as serialization
- Loading branch information
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,28 @@ | ||
# JSON Schema | ||
|
||
## Overview | ||
|
||
JSON schema is the standard for defining the structure of JSON data. It is used to validate the structure of JSON data or by extension any system that accepts JSON Schema. For our usecase, we use JSON Schema derived from Pydantic Models in Python to generate a JSON Schema file. This, schema is then used by IDE's to provide autocompletion and validation for YAML files that are used to define the workflow workspaces and pipelines. | ||
|
||
## Translate Pydanitc Models to JSON Schema | ||
|
||
```python | ||
from workflow.definitions.work import Work | ||
|
||
schema = Work.model_json_schema(mode="serialization") | ||
``` | ||
|
||
## Translate JSON Schema to Python Dataclasses | ||
|
||
- Go to [JSON Schema Store](https://www.schemastore.org/json/) and download a JSON schema file, using | ||
|
||
```bash | ||
curl -O https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json | ||
``` | ||
|
||
- Follow the Code Generation instructions in the Pydantic documentation to create Python Code from the JSON schema file. | ||
|
||
```bash | ||
pip install datamodel-code-generator | ||
datamodel-codegen --input compose-spec.json --input-file-type jsonschema --output compose.py | ||
``` |
This file contains 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