1
0
forked from ScoDoc/ScoDoc

gen api doc : catégories

This commit is contained in:
Iziram 2024-07-24 17:50:16 +02:00
parent c12bc778bb
commit 0b7be5d08a
2 changed files with 37 additions and 6 deletions

View File

@ -341,6 +341,10 @@ def evaluation_assiduites(evaluation_id):
]
}
```
CATEGORY
--------
evaluations
"""
# Récupération de l'évaluation
try:

View File

@ -4,6 +4,7 @@ Script permettant de générer une carte SVG de l'API de ScoDoc
Écrit par Matthias HARTMANN
"""
import sys
import xml.etree.ElementTree as ET
import re
@ -508,6 +509,14 @@ def analyze_api_routes(app, endpoint_start: str) -> tuple:
if child.query and not href.endswith("-query"):
href += "-query"
# category
category: str = func.__module__.replace("app.api.", "")
mod_doc: str = sys.modules[func.__module__].__doc__ or ""
mod_doc_dict: dict = _parse_doc_string(mod_doc)
if mod_doc_dict.get("CATEGORY"):
category = mod_doc_dict["CATEGORY"][0].strip()
permissions: str
try:
permissions: str = ", ".join(
@ -525,6 +534,7 @@ def analyze_api_routes(app, endpoint_start: str) -> tuple:
"permission": permissions,
"description": doc_dict.get("", ""),
"params": doc_dict.get("PARAMS", ""),
"category": doc_dict.get("CATEGORY", [False])[0] or category,
}
# On met à jour le token courant pour le prochain segment
@ -544,8 +554,6 @@ def gen_api_map(app, endpoint_start="api."):
puis génère un fichier SVG à partir de cet arbre
"""
print("DEBUG", app.view_functions["apiweb.user_info"].scodoc_permission)
api_map, doctable_lines = analyze_api_routes(app, endpoint_start)
# On génère le SVG à partir de l'arbre de Token
@ -903,10 +911,29 @@ def doc_route(doctable: dict) -> str:
def gen_api_doc(app, endpoint_start="api."):
"commande gen-api-doc"
_, doctable_lines = analyze_api_routes(app, endpoint_start)
mddoc = "\n".join(
doc_route(doctable)
for doctable in sorted(doctable_lines.values(), key=lambda x: x["nom"])
)
mddoc: str = ""
categories: dict = {}
for value in doctable_lines.values():
category = value["category"]
if category not in categories:
categories[category] = []
categories[category].append(value)
# sort categories by name
categories: dict = dict(sorted(categories.items(), key=lambda x: x[0]))
category: str
routes: list[dict]
for category, routes in categories.items():
# sort routes by name
routes.sort(key=lambda x: x["nom"])
mddoc += f"### API {category.capitalize()}\n\n"
for route in routes:
mddoc += doc_route(route)
mddoc += "\n\n"
fname = "/tmp/apidoc.md"
with open(fname, "w", encoding="utf-8") as f: