mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-23 16:23:11 -05:00
docs: Remove redoc API generation (#7109)
This commit is contained in:
@@ -25,16 +25,9 @@ dotenv:
|
|||||||
- .env
|
- .env
|
||||||
- .dev.env
|
- .dev.env
|
||||||
tasks:
|
tasks:
|
||||||
docs:gen:
|
|
||||||
desc: runs the API documentation generator
|
|
||||||
cmds:
|
|
||||||
- uv run python dev/code-generation/gen_docs_api.py
|
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
desc: runs the documentation server
|
desc: runs the documentation server
|
||||||
dir: docs
|
dir: docs
|
||||||
deps:
|
|
||||||
- docs:gen
|
|
||||||
cmds:
|
cmds:
|
||||||
- uv run python -m mkdocs serve
|
- uv run python -m mkdocs serve
|
||||||
|
|
||||||
@@ -81,7 +74,6 @@ tasks:
|
|||||||
desc: run code generators
|
desc: run code generators
|
||||||
cmds:
|
cmds:
|
||||||
- uv run python dev/code-generation/main.py {{ .CLI_ARGS }}
|
- uv run python dev/code-generation/main.py {{ .CLI_ARGS }}
|
||||||
- task: docs:gen
|
|
||||||
- task: py:format
|
- task: py:format
|
||||||
|
|
||||||
dev:services:
|
dev:services:
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
import json
|
|
||||||
from datetime import UTC, datetime
|
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
|
|
||||||
from mealie.app import app
|
|
||||||
from mealie.core.config import determine_data_dir
|
|
||||||
|
|
||||||
DATA_DIR = determine_data_dir()
|
|
||||||
|
|
||||||
"""Script to export the ReDoc documentation page into a standalone HTML file."""
|
|
||||||
|
|
||||||
HTML_TEMPLATE = """<!-- Custom HTML site displayed as the Home chapter -->
|
|
||||||
{% extends "main.html" %}
|
|
||||||
{% block tabs %}
|
|
||||||
{{ super() }}
|
|
||||||
|
|
||||||
<style>
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
|
|
||||||
<div id="redoc-container"></div>
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
|
|
||||||
<script>
|
|
||||||
var spec = MY_SPECIFIC_TEXT;
|
|
||||||
Redoc.init(spec, {}, document.getElementById("redoc-container"));
|
|
||||||
</script>
|
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
{% block content %}{% endblock %}
|
|
||||||
{% block footer %}{% endblock %}
|
|
||||||
"""
|
|
||||||
|
|
||||||
HTML_PATH = DATA_DIR.parent.parent.joinpath("docs/docs/overrides/api.html")
|
|
||||||
CONSTANT_DT = datetime(2025, 10, 24, 15, 53, 0, 0, tzinfo=UTC)
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_timestamps(s: dict[str, Any]) -> dict[str, Any]:
|
|
||||||
field_format = s.get("format")
|
|
||||||
is_timestamp = field_format in ["date-time", "date", "time"]
|
|
||||||
has_default = s.get("default")
|
|
||||||
|
|
||||||
if not is_timestamp:
|
|
||||||
for k, v in s.items():
|
|
||||||
if isinstance(v, dict):
|
|
||||||
s[k] = normalize_timestamps(v)
|
|
||||||
elif isinstance(v, list):
|
|
||||||
s[k] = [normalize_timestamps(i) if isinstance(i, dict) else i for i in v]
|
|
||||||
|
|
||||||
return s
|
|
||||||
elif not has_default:
|
|
||||||
return s
|
|
||||||
|
|
||||||
if field_format == "date-time":
|
|
||||||
s["default"] = CONSTANT_DT.isoformat()
|
|
||||||
elif field_format == "date":
|
|
||||||
s["default"] = CONSTANT_DT.date().isoformat()
|
|
||||||
elif field_format == "time":
|
|
||||||
s["default"] = CONSTANT_DT.time().isoformat()
|
|
||||||
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def generate_api_docs(my_app: FastAPI):
|
|
||||||
openapi_schema = my_app.openapi()
|
|
||||||
openapi_schema = normalize_timestamps(openapi_schema)
|
|
||||||
|
|
||||||
with open(HTML_PATH, "w") as fd:
|
|
||||||
text = HTML_TEMPLATE.replace("MY_SPECIFIC_TEXT", json.dumps(openapi_schema))
|
|
||||||
fd.write(text)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
generate_api_docs(app)
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
---
|
|
||||||
title: API
|
|
||||||
template: api.html
|
|
||||||
---
|
|
||||||
File diff suppressed because one or more lines are too long
@@ -93,7 +93,7 @@ nav:
|
|||||||
- iOS Shortcut: "documentation/community-guide/ios-shortcut.md"
|
- iOS Shortcut: "documentation/community-guide/ios-shortcut.md"
|
||||||
- Reverse Proxy (SWAG): "documentation/community-guide/swag.md"
|
- Reverse Proxy (SWAG): "documentation/community-guide/swag.md"
|
||||||
|
|
||||||
- API Reference: "api/redoc.md"
|
- API Reference: "https://demo.mealie.io/docs"
|
||||||
|
|
||||||
- Contributors Guide:
|
- Contributors Guide:
|
||||||
- Non-Code: "contributors/non-coders.md"
|
- Non-Code: "contributors/non-coders.md"
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ export default defineNuxtConfig({
|
|||||||
},
|
},
|
||||||
workbox: {
|
workbox: {
|
||||||
navigateFallback: "/",
|
navigateFallback: "/",
|
||||||
navigateFallbackAllowlist: [/^(?!\/api|\/docs|\/redoc)/],
|
navigateFallbackAllowlist: [/^(?!\/api|\/docs)/],
|
||||||
globPatterns: ["**/*.{js,css,html,png,svg,ico}"],
|
globPatterns: ["**/*.{js,css,html,png,svg,ico}"],
|
||||||
globIgnores: ["404.html", "200.html"],
|
globIgnores: ["404.html", "200.html"],
|
||||||
cleanupOutdatedCaches: true,
|
cleanupOutdatedCaches: true,
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ app = FastAPI(
|
|||||||
description=description,
|
description=description,
|
||||||
version=APP_VERSION,
|
version=APP_VERSION,
|
||||||
docs_url=settings.DOCS_URL,
|
docs_url=settings.DOCS_URL,
|
||||||
redoc_url=settings.REDOC_URL,
|
|
||||||
lifespan=lifespan_fn,
|
lifespan=lifespan_fn,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -199,10 +199,6 @@ class AppSettings(AppLoggingSettings):
|
|||||||
def DOCS_URL(self) -> str | None:
|
def DOCS_URL(self) -> str | None:
|
||||||
return "/docs" if self.API_DOCS else None
|
return "/docs" if self.API_DOCS else None
|
||||||
|
|
||||||
@property
|
|
||||||
def REDOC_URL(self) -> str | None:
|
|
||||||
return "/redoc" if self.API_DOCS else None
|
|
||||||
|
|
||||||
# ===============================================
|
# ===============================================
|
||||||
# Database Configuration
|
# Database Configuration
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ def test_non_default_settings(monkeypatch):
|
|||||||
assert app_settings.API_PORT == 8000
|
assert app_settings.API_PORT == 8000
|
||||||
assert app_settings.API_DOCS is False
|
assert app_settings.API_DOCS is False
|
||||||
|
|
||||||
assert app_settings.REDOC_URL is None
|
|
||||||
assert app_settings.DOCS_URL is None
|
assert app_settings.DOCS_URL is None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user