Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SCODOC_R6A06
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Paul Milleville
SCODOC_R6A06
Commits
f7a8c1d2
Commit
f7a8c1d2
authored
1 year ago
by
Iziram
Browse files
Options
Downloads
Patches
Plain Diff
API Doc : lien query OK
parent
5cefe1a3
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/create_api_map.py
+21
-53
21 additions, 53 deletions
tools/create_api_map.py
with
21 additions
and
53 deletions
tools/create_api_map.py
+
21
−
53
View file @
f7a8c1d2
...
@@ -503,8 +503,6 @@ def analyze_api_routes(app, endpoint_start: str) -> tuple:
...
@@ -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:
...
@@ -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]:
...
@@ -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]:
...
@@ -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
Génère une ligne de tableau markdown
à 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
| nom de la route| methode HTTP| Permission |
---------
permissions: ScoView
href: une-fonction
"""
"""
doc_lines
:
list
[
str
]
=
_get_doc_lines
(
"
DOC-TABLE
"
,
doc_string
)
nom
,
method
,
permission
=
(
table
=
{}
doctable
.
get
(
"
nom
"
,
""
),
doctable
.
get
(
"
method
"
,
""
),
doctable
.
get
(
"
permission
"
,
""
),
)
# on parcourt les lignes de la doc
if
doctable
is
None
:
for
line
in
doc_lines
:
doctable
=
{}
# 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
lien
:
str
=
doctable
.
get
(
"
href
"
,
nom
)
doctable
[
"
query
"
]:
bool
if
doctable
.
get
(
"
query
"
)
and
not
lien
.
endswith
(
"
-query
"
):
lien
+=
"
-query
"
def
_gen_table_line
(
nom
=
""
,
href
=
""
,
method
=
""
,
permission
=
""
,
doctable
:
dict
=
None
,
**
kwargs
):
"""
Génère une ligne de tableau markdown
| nom de la route| methode HTTP| Permission |
"""
lien
:
str
=
href
if
"
href
"
in
doctable
:
lien
:
str
=
doctable
.
get
(
"
href
"
)
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:
...
@@ -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:
...
@@ -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:
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment