-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_openapi.py
More file actions
80 lines (60 loc) · 2.21 KB
/
export_openapi.py
File metadata and controls
80 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# export_openapi.py
import asyncio
import json
from pathlib import Path
from fastapi.openapi.utils import get_openapi
from fastapi import FastAPI
# Ensure src/ is in path
import sys
SRC_ROOT = Path(__file__).parents[1] / "src"
if str(SRC_ROOT) not in sys.path:
sys.path.insert(0, str(SRC_ROOT))
# --- Minimal dummy SocketIO just to allow controller registration ---
class DummySocketIO:
def on(self, *args, **kwargs):
return lambda f: f
def emit(self, *args, **kwargs):
# Dummy implementation for OpenAPI schema generation - no actual emission needed
pass
def create_api_app() -> FastAPI:
# Local imports to comply with flake8 E402 (imports after non-import code)
from openscada_lite.modules.registry import MODULES
from openscada_lite.modules.loader import module_loader
from openscada_lite.common.bus.event_bus import EventBus # real EventBus
from openscada_lite.web.config_editor.routes import config_router
from openscada_lite.web.security_editor.routes import security_router
from openscada_lite.web.scada.routes import scada_router
from openscada_lite.web.mounter import mount_enpoints
# --- Fake config generated from registry ---
fake_config = {"modules": [{"name": name} for name in MODULES]}
app = FastAPI(title="OpenSCADA-Lite", version="0.0.1", debug=False)
# Static routers
app.include_router(config_router)
app.include_router(security_router)
app.include_router(scada_router)
mount_enpoints(app)
# Use real EventBus singleton
event_bus = EventBus.get_instance()
# Load modules exactly like the real app
asyncio.run(
module_loader(
config=fake_config,
socketio_obj=DummySocketIO(),
event_bus=event_bus,
app=app,
)
)
return app
def export_openapi():
app = create_api_app()
schema = get_openapi(
title=app.title,
version=app.version,
routes=app.routes,
)
output_path = Path(__file__).parent / "openapi.json"
with open(output_path, "w", encoding="utf-8") as f:
json.dump(schema, f, indent=2)
print(f"[OpenAPI] Schema exported to {output_path}")
if __name__ == "__main__":
export_openapi()