forked from ScoDoc/ScoDoc
API Doc : lien query OK
This commit is contained in:
parent
5cefe1a337
commit
f7a8c1d2db
@ -503,8 +503,6 @@ def analyze_api_routes(app, endpoint_start: str) -> tuple:
|
|||||||
child.method = method
|
child.method = method
|
||||||
current_token.add_child(child)
|
current_token.add_child(child)
|
||||||
|
|
||||||
# Gestion de doctable
|
|
||||||
doctable = parse_doctable_doc(func.__doc__ or "")
|
|
||||||
href = func_name
|
href = func_name
|
||||||
if child.query and not href.endswith("-query"):
|
if child.query and not href.endswith("-query"):
|
||||||
href += "-query"
|
href += "-query"
|
||||||
@ -527,10 +525,10 @@ def analyze_api_routes(app, endpoint_start: str) -> tuple:
|
|||||||
|
|
||||||
if func_name not in doctable_lines:
|
if func_name not in doctable_lines:
|
||||||
doctable_lines[func_name] = {
|
doctable_lines[func_name] = {
|
||||||
"doctable": doctable,
|
|
||||||
"method": method,
|
"method": method,
|
||||||
"nom": func_name,
|
"nom": func_name,
|
||||||
"href": href,
|
"href": href,
|
||||||
|
"query": doc_dict.get("QUERY", "") != "",
|
||||||
"permission": permissions,
|
"permission": permissions,
|
||||||
"description": doc_dict.get("", ""),
|
"description": doc_dict.get("", ""),
|
||||||
"params": doc_dict.get("PARAMS", ""),
|
"params": doc_dict.get("PARAMS", ""),
|
||||||
@ -745,23 +743,6 @@ def _get_doc_lines(keyword, doc_string: str) -> list[str]:
|
|||||||
return kw_lines
|
return kw_lines
|
||||||
|
|
||||||
|
|
||||||
def parse_doc_name(doc_string: str) -> str:
|
|
||||||
"""
|
|
||||||
renvoie le nom de la route à partir de la docstring
|
|
||||||
|
|
||||||
La doc doit contenir des lignes de la forme:
|
|
||||||
|
|
||||||
DOC_ANCHOR
|
|
||||||
----------
|
|
||||||
nom_de_la_route
|
|
||||||
|
|
||||||
Il ne peut y avoir qu'une seule ligne suivant -----
|
|
||||||
|
|
||||||
"""
|
|
||||||
name_lines: list[str] = _get_doc_lines("DOC_ANCHOR", doc_string)
|
|
||||||
return name_lines[0] if name_lines else None
|
|
||||||
|
|
||||||
|
|
||||||
def parse_query_doc(doc_string: str) -> dict[str, str]:
|
def parse_query_doc(doc_string: str) -> dict[str, str]:
|
||||||
"""
|
"""
|
||||||
renvoie un dictionnaire {param: <type:nom_param>} (ex: {assiduite_id : <int:assiduite_id>})
|
renvoie un dictionnaire {param: <type:nom_param>} (ex: {assiduite_id : <int:assiduite_id>})
|
||||||
@ -795,45 +776,28 @@ def parse_query_doc(doc_string: str) -> dict[str, str]:
|
|||||||
return query
|
return query
|
||||||
|
|
||||||
|
|
||||||
def parse_doctable_doc(doc_string: str) -> dict[str, str]:
|
def _gen_table_line(doctable: dict = None):
|
||||||
"""
|
|
||||||
Retourne un dictionnaire représentant les informations du tableau d'api
|
|
||||||
à partir de la doc (DOC-TABLE)
|
|
||||||
|
|
||||||
éléments optionnels:
|
|
||||||
- `permissions` permissions nécessaires pour accéder à la route (ScoView, AbsChange, ...)
|
|
||||||
- `href` nom (sans #) de l'ancre dans la page ScoDoc9API
|
|
||||||
|
|
||||||
DOC-TABLE
|
|
||||||
---------
|
|
||||||
permissions: ScoView
|
|
||||||
href: une-fonction
|
|
||||||
"""
|
|
||||||
|
|
||||||
doc_lines: list[str] = _get_doc_lines("DOC-TABLE", doc_string)
|
|
||||||
table = {}
|
|
||||||
|
|
||||||
# on parcourt les lignes de la doc
|
|
||||||
for line in doc_lines:
|
|
||||||
# On sépare le paramètre et sa valeur
|
|
||||||
param, value = line.split(":")
|
|
||||||
# On met à jour le dictionnaire
|
|
||||||
table[param.strip()] = value.strip()
|
|
||||||
|
|
||||||
return table
|
|
||||||
|
|
||||||
|
|
||||||
def _gen_table_line(
|
|
||||||
nom="", href="", method="", permission="", doctable: dict = None, **kwargs
|
|
||||||
):
|
|
||||||
"""
|
"""
|
||||||
Génère une ligne de tableau markdown
|
Génère une ligne de tableau markdown
|
||||||
|
|
||||||
| nom de la route| methode HTTP| Permission |
|
| nom de la route| methode HTTP| Permission |
|
||||||
"""
|
"""
|
||||||
lien: str = href
|
|
||||||
if "href" in doctable:
|
nom, method, permission = (
|
||||||
lien: str = doctable.get("href")
|
doctable.get("nom", ""),
|
||||||
|
doctable.get("method", ""),
|
||||||
|
doctable.get("permission", ""),
|
||||||
|
)
|
||||||
|
|
||||||
|
if doctable is None:
|
||||||
|
doctable = {}
|
||||||
|
|
||||||
|
lien: str = doctable.get("href", nom)
|
||||||
|
|
||||||
|
doctable["query"]: bool
|
||||||
|
if doctable.get("query") and not lien.endswith("-query"):
|
||||||
|
lien += "-query"
|
||||||
|
|
||||||
nav: str = f"[{nom}]({'#'+lien})"
|
nav: str = f"[{nom}]({'#'+lien})"
|
||||||
|
|
||||||
table: str = "|"
|
table: str = "|"
|
||||||
@ -867,7 +831,7 @@ def _gen_table(lines: list[dict]) -> str:
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
table = _gen_table_head()
|
table = _gen_table_head()
|
||||||
table += "\n".join([_gen_table_line(**line) for line in lines])
|
table += "\n".join([_gen_table_line(line) for line in lines])
|
||||||
return table
|
return table
|
||||||
|
|
||||||
|
|
||||||
@ -886,6 +850,10 @@ def doc_route(doctable: dict) -> str:
|
|||||||
jinja_obj.update(doctable)
|
jinja_obj.update(doctable)
|
||||||
jinja_obj["nom"] = doctable["nom"].strip() # on retire les caractères blancs
|
jinja_obj["nom"] = doctable["nom"].strip() # on retire les caractères blancs
|
||||||
|
|
||||||
|
jinja_obj["query"]: bool
|
||||||
|
if jinja_obj["query"]:
|
||||||
|
jinja_obj["nom"] += "(-query)"
|
||||||
|
|
||||||
if doctable.get("params"):
|
if doctable.get("params"):
|
||||||
jinja_obj["params"] = []
|
jinja_obj["params"] = []
|
||||||
for param in doctable["params"]:
|
for param in doctable["params"]:
|
||||||
@ -903,7 +871,7 @@ def doc_route(doctable: dict) -> str:
|
|||||||
|
|
||||||
jinja_obj["sample"] = {
|
jinja_obj["sample"] = {
|
||||||
"nom": f"{jinja_obj['nom']}.json",
|
"nom": f"{jinja_obj['nom']}.json",
|
||||||
"href": f"{jinja_obj['nom'].replace('_', '-')}.json.md",
|
"href": f"{jinja_obj['nom']}.json.md",
|
||||||
}
|
}
|
||||||
|
|
||||||
return render_template("doc/apidoc.j2", doc=jinja_obj)
|
return render_template("doc/apidoc.j2", doc=jinja_obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user