Merge pull request #9 from zdunecki/chore/json-schema-generator

chore(json-schema-generator): `generate_json_schema.py` script helpful for generating schemas for pydantic models
This commit is contained in:
Kohaku-Blueleaf
2026-02-12 14:44:19 +08:00
committed by GitHub
3 changed files with 46 additions and 0 deletions

1
.gitignore vendored
View File

@@ -22,6 +22,7 @@ lint-reports/
/logs
data/
**/public/docs
__generated__
# Byte-compiled / optimized / DLL files
__pycache__/

View File

@@ -539,6 +539,21 @@ export KOHAKU_HUB_BASE_URL=http://localhost:28080
---
## JSON Schema Generator
### Generate JSON Schema
```bash
python scripts/generate_json_schema.py
```
This script will generate a JSON schema for the KohakuHub types in `__generated__/schemas/<filename>.json`.
Currently supported files:
- `config.json`
---
## Tips for Demo Deployments
### CloudFlare R2 Free Tier

View File

@@ -0,0 +1,30 @@
import sys
import json
from pathlib import Path
# Add src to path so we can import kohakuhub
src_path = Path(__file__).parent.parent / "src"
sys.path.append(str(src_path))
from kohakuhub.config import Config
schema = Config.model_json_schema()
# Write to file
output_dir = Path(__file__).parent.parent / "__generated__" / "schemas"
output_dir.mkdir(parents=True, exist_ok=True)
output_file = output_dir / "config.json"
def move_defs_to_end(schema: dict) -> dict:
"""Move $defs to the end of the schema."""
if '$defs' in schema:
defs = schema.pop('$defs')
schema['$defs'] = defs
return schema
schema = move_defs_to_end(schema)
with open(output_file, "w") as f:
json.dump(schema, f, indent=2)
print(f"Schema written to {output_file}")