-
-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathgen_rest_plugin_spec_reference.py
More file actions
32 lines (27 loc) · 1013 Bytes
/
gen_rest_plugin_spec_reference.py
File metadata and controls
32 lines (27 loc) · 1013 Bytes
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
"""
Generates OpenAPI schema from an example REST plugin.
"""
import json
import logging
from pathlib import Path
from dstack._internal.settings import DSTACK_VERSION
logger = logging.getLogger("mkdocs.plugins.dstack.rest_plugin_schema")
try:
from example_plugin_server.main import app
except ImportError:
logger.warning(
"No module named 'example_plugin_server'."
" The REST Plugin API won't be generated."
" Run 'uv pip install examples/plugins/example_plugin_server' to install 'example_plugin_server'."
)
exit(0)
app.title = "REST Plugin OpenAPI Spec"
app.servers = [
{"url": "http://localhost:8000", "description": "Local server"},
]
app.version = DSTACK_VERSION or "0.0.0"
output_path = Path("docs/docs/reference/plugins/rest/rest_plugin_openapi.json")
output_path.parent.mkdir(parents=True, exist_ok=True)
new_content = json.dumps(app.openapi())
if not output_path.exists() or output_path.read_text() != new_content:
output_path.write_text(new_content)