mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
generate API docs with make file
This commit is contained in:
parent
ab60306335
commit
db8ac250cd
3 changed files with 44 additions and 37 deletions
File diff suppressed because one or more lines are too long
1
makefile
1
makefile
|
@ -14,6 +14,7 @@ frontend:
|
||||||
|
|
||||||
.PHONY: docs
|
.PHONY: docs
|
||||||
docs:
|
docs:
|
||||||
|
poetry run python mealie/utils/api_docs.py && \
|
||||||
cd docs && poetry run python -m mkdocs serve
|
cd docs && poetry run python -m mkdocs serve
|
||||||
|
|
||||||
docker-dev:
|
docker-dev:
|
||||||
|
|
|
@ -1,39 +1,44 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
from mealie.app import app
|
||||||
from mealie.core.config import DATA_DIR
|
from mealie.core.config import DATA_DIR
|
||||||
|
|
||||||
"""Script to export the ReDoc documentation page into a standalone HTML file."""
|
"""Script to export the ReDoc documentation page into a standalone HTML file."""
|
||||||
|
|
||||||
HTML_TEMPLATE = """<!DOCTYPE html>
|
HTML_TEMPLATE = """<!-- Custom HTML site displayed as the Home chapter -->
|
||||||
<html>
|
{% extends "main.html" %}
|
||||||
<head>
|
{% block tabs %}
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
{{ super() }}
|
||||||
<title>My Project - ReDoc</title>
|
|
||||||
<meta charset="utf-8">
|
<style>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
body {
|
||||||
<link rel="shortcut icon" href="https://fastapi.tiangolo.com/img/favicon.png">
|
margin: 0;
|
||||||
<style>
|
padding: 0;
|
||||||
body {
|
}
|
||||||
margin: 0;
|
</style>
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
</style>
|
<div id="redoc-container"></div>
|
||||||
<style data-styled="" data-styled-version="4.4.1"></style>
|
<script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
|
||||||
</head>
|
<script>
|
||||||
<body>
|
var spec = MY_SPECIFIC_TEXT;
|
||||||
<div id="redoc-container"></div>
|
Redoc.init(spec, {}, document.getElementById("redoc-container"));
|
||||||
<script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
|
</script>
|
||||||
<script>
|
|
||||||
var spec = %s;
|
|
||||||
Redoc.init(spec, {}, document.getElementById("redoc-container"));
|
{% endblock %}
|
||||||
</script>
|
{% block content %}{% endblock %}
|
||||||
</body>
|
{% block footer %}{% endblock %}
|
||||||
</html>
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
HTML_PATH = DATA_DIR.parent.joinpath("docs/docs/html/api.html")
|
HTML_PATH = DATA_DIR.parent.parent.joinpath("docs/docs/overrides/api.html")
|
||||||
|
|
||||||
|
|
||||||
def generate_api_docs(app):
|
def generate_api_docs(my_app):
|
||||||
with open(HTML_PATH, "w") as fd:
|
with open(HTML_PATH, "w") as fd:
|
||||||
print(HTML_TEMPLATE % json.dumps(app.openapi()), file=fd)
|
text = HTML_TEMPLATE.replace("MY_SPECIFIC_TEXT", json.dumps(my_app.openapi()))
|
||||||
|
fd.write(text)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
generate_api_docs(app)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue