okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

nekomimi.petupdate dependencies across cli, renderer and toolingbd84040

main
1.5 KiB49 linesraw
1#!/usr/bin/env python3
2"""Generate a browsable reference from docs/openapi.yaml using Scalar."""
3
4import argparse
5import json
6from pathlib import Path
7
8
9def main():
10    root = Path(__file__).resolve().parent.parent
11    parser = argparse.ArgumentParser(description=__doc__)
12    parser.add_argument(
13        "--output", type=Path, default=root / "docs" / "api-reference.html"
14    )
15    output = parser.parse_args().output.resolve()
16    configuration = {
17        "content": (root / "docs" / "openapi.yaml").read_text(),
18        "modelsSectionLabel": "Schemas",
19        "hideClientButton": True,
20        "hideTestRequestButton": True,
21        "defaultHttpClient": {"targetKey": "shell", "clientKey": "curl"},
22    }
23    # A schema description can contain HTML, including a closing script tag.
24    encoded = json.dumps(configuration).replace("<", "\\u003c")
25    document = f"""<!doctype html>
26<html lang="en">
27<head>
28  <meta charset="utf-8">
29  <meta name="viewport" content="width=device-width, initial-scale=1">
30  <title>Albedo daemon API reference</title>
31</head>
32<body>
33  <noscript>Enable JavaScript to read this API reference.</noscript>
34  <div id="app"></div>
35  <script type="module">
36    import {{ createApiReference }} from
37      'https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.73.1/esm.js';
38    createApiReference('#app', {encoded});
39  </script>
40</body>
41</html>
42"""
43    output.parent.mkdir(parents=True, exist_ok=True)
44    output.write_text(document)
45    print(output)
46
47
48if __name__ == "__main__":
49    main()