okami.mom/albedo
git clone https://git.nkp.pet/okami.mom/albedo
bd84040
main
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 (): 10root = Path (__file__ ).resolve ().parent .parent 11parser = argparse .ArgumentParser (description = __doc__ ) 12parser .add_argument ( 13"--output" ,type = Path ,default = root / "docs" / "api-reference.html" 14 ) 15output = parser .parse_args ().output .resolve () 16configuration = { 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. 24encoded = json .dumps (configuration ).replace ("<" ,"\\u003c" ) 25document = 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"> 36import {{ createApiReference }} from 37'https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.73.1/esm.js'; 38createApiReference('#app', { encoded } ); 39</script> 40</body> 41</html> 42""" 43output .parent .mkdir (parents = True ,exist_ok = True ) 44output .write_text (document ) 45output ) 46 47 48if __name__ == "__main__" : 49main ()