Skip to content

Commit

Permalink
fix(json-schema): added default mode as serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
shinybrar committed Jun 18, 2024
1 parent 3681bd1 commit 5587cf7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions workflow/definitions/jsonschema.md
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
```
1 change: 1 addition & 0 deletions workflow/definitions/work.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Work(BaseSettings):
env_prefix="WORKFLOW_",
secrets_dir="/run/secrets",
extra="ignore",
json_schema_mode_override="serialization",
)
# * Runtime configurations for the Work Object, these are not part of the payload.
# * and describe the behavior of the work object in the current instantiation.
Expand Down

0 comments on commit 5587cf7

Please sign in to comment.