Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
119 lines
3.7 KiB
Python
119 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Export ReelForge's public FastAPI schema deterministically.
|
|
|
|
The committed artifact is the review boundary shared by first-party clients and
|
|
SDKs. The script deliberately imports the real application/router rather than
|
|
reconstructing routes from documentation.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
PACKAGE_ROOT = Path(__file__).resolve().parents[1]
|
|
REPOSITORY_ROOT = PACKAGE_ROOT.parents[1]
|
|
API_ROOT = REPOSITORY_ROOT / "apps" / "api"
|
|
ENGINE_ROOT = API_ROOT / "engine"
|
|
OUTPUT_PATH = PACKAGE_ROOT / "openapi" / "reelforge-v1.json"
|
|
|
|
REQUIRED_PATHS = frozenset(
|
|
{
|
|
"/api/v1/jobs",
|
|
"/api/v1/jobs/{job_id}",
|
|
"/api/v1/jobs/{job_id}/exports",
|
|
"/api/v1/uploads/presign",
|
|
"/api/v1/uploads/register",
|
|
"/api/v1/pilot/capabilities",
|
|
"/api/v1/generation/broll/generate",
|
|
"/api/v1/generation/broll/generations/{generation_id}",
|
|
# Unified media gateway (OpenRouter-style), namespaced under /media.
|
|
"/api/v1/media/models",
|
|
"/api/v1/media/images",
|
|
"/api/v1/media/videos",
|
|
"/api/v1/media/videos/{job_id}",
|
|
"/api/v1/media/audio",
|
|
"/api/v1/media/audio/{job_id}",
|
|
"/api/v1/media/credits",
|
|
"/api/v1/media/usage",
|
|
"/api/v1/media/generation/{job_id}",
|
|
"/api/v1/media/generation/{job_id}/provenance",
|
|
"/api/v1/media/generation/{job_id}/evidence",
|
|
"/api/v1/media/identities",
|
|
}
|
|
)
|
|
FORBIDDEN_PATH_PREFIXES = ("/generation/api/",)
|
|
|
|
|
|
def _load_schema() -> dict[str, Any]:
|
|
os.environ.setdefault("REELFORGE_BACKEND_ROOT", str(API_ROOT))
|
|
for path in (str(API_ROOT), str(ENGINE_ROOT), str(REPOSITORY_ROOT)):
|
|
if path not in sys.path:
|
|
sys.path.insert(0, path)
|
|
|
|
from app.asgi import app
|
|
|
|
schema = app.openapi()
|
|
schema["info"] = {
|
|
"title": "ReelForge API",
|
|
"version": "1.0.0",
|
|
"description": "Authoritative public ReelForge /api/v1 contract.",
|
|
}
|
|
schema.pop("servers", None)
|
|
return schema
|
|
|
|
|
|
def _validate_contract(schema: dict[str, Any]) -> None:
|
|
paths = set(schema.get("paths", {}))
|
|
missing = sorted(REQUIRED_PATHS - paths)
|
|
forbidden = sorted(
|
|
path for path in paths if path.startswith(FORBIDDEN_PATH_PREFIXES)
|
|
)
|
|
if missing or forbidden:
|
|
details = []
|
|
if missing:
|
|
details.append(f"missing canonical paths: {', '.join(missing)}")
|
|
if forbidden:
|
|
details.append(f"mis-prefixed paths: {', '.join(forbidden)}")
|
|
raise SystemExit("OpenAPI contract validation failed: " + "; ".join(details))
|
|
|
|
|
|
def _render(schema: dict[str, Any]) -> str:
|
|
return json.dumps(schema, indent=2, sort_keys=True, ensure_ascii=False) + "\n"
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
"--check",
|
|
action="store_true",
|
|
help="fail when the committed artifact differs from the API schema",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
schema = _load_schema()
|
|
_validate_contract(schema)
|
|
rendered = _render(schema)
|
|
|
|
if args.check:
|
|
if not OUTPUT_PATH.exists() or OUTPUT_PATH.read_text(encoding="utf-8") != rendered:
|
|
raise SystemExit(
|
|
"OpenAPI artifact is stale; run the api-contract contract:export script"
|
|
)
|
|
print(f"OpenAPI contract is current: {OUTPUT_PATH.relative_to(REPOSITORY_ROOT)}")
|
|
return 0
|
|
|
|
OUTPUT_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
OUTPUT_PATH.write_text(rendered, encoding="utf-8")
|
|
print(f"Wrote {OUTPUT_PATH.relative_to(REPOSITORY_ROOT)}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|