You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Flask-Autodoc is compatible with Python versions 2 and 3; and it depends only on Flask.
8
16
9
17
## Install
10
18
11
-
To install Flask-Autodoc:
19
+
To install Flask-Autodoc, run pip:
20
+
21
+
pip install flask-autodoc
22
+
23
+
or clone this directory and run setup:
12
24
13
25
python setup.py install
14
26
@@ -22,28 +34,28 @@ Start using Flask-Autodoc by importing it and initializing it:
22
34
app = Flask(__name__)
23
35
auto = Autodoc(app)
24
36
25
-
by default, Flask-Autodoc will only document the routes you explicitly tell him to with the _doc_ decorator,
26
-
like this:
37
+
by default, Flask-Autodoc will only document the routes explicitly decorated with _doc_:
27
38
28
39
@app.route('/user/<int:id>')
29
40
@auto.doc()
30
41
def show_user(id):
31
-
"""This returns a user with a given id."""
32
42
return user_from_database(id)
33
43
34
-
to generate the documentation from an endpoint, use the _html()_ method:
44
+
to generate the documentation, use the _html()_ method:
35
45
36
46
@app.route('/documentation')
37
47
def documentation():
38
48
return auto.html()
39
49
40
-
if you to access the documentation without it being rendered in html:
50
+
## Custom documentation
51
+
52
+
To access the documentation without rendering html:
41
53
42
54
@app.route('/documentation')
43
55
def documentation():
44
56
return auto.generate()
45
57
46
-
the documentation will then be returned as a list of rules, where each rule is a dictionary containing:
58
+
the documentation will be returned as a list of rules, where each rule is a dictionary containing:
47
59
48
60
- methods: the set of allowed methods (ie ['GET', 'POST'])
49
61
- rule: relative url (ie '/user/<int:id>')
@@ -52,27 +64,67 @@ the documentation will then be returned as a list of rules, where each rule is a
52
64
- args: function arguments
53
65
- defaults: defaults values for the arguments
54
66
55
-
## Groups
67
+
## Custom template
68
+
69
+
To use a custom template for your documentation, give a _template_ argument to the _html_ method. This will use a template from the flask _templates_ directory.
70
+
71
+
Additionnal arguments (other than _group_, _groups_, and _template_) will be passed down to the template:
72
+
73
+
auto.html(
74
+
75
+
template='custom_documentation.html'
76
+
77
+
title='My Documentation',
78
+
author='John Doe',
79
+
)
80
+
56
81
57
-
You may want to group endpoints together, to have different documentation sets. With this you can for example, only
58
-
show some endpoints to third party developer and have full documentation for your own.
82
+
_title_ and _author_ will be available in the template:
59
83
60
-
to assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
84
+
<!-- templates/custom_documentation.html -->
85
+
...
86
+
{% if title is defined %}
87
+
{{title}}
88
+
{% endif %}
89
+
...
90
+
91
+
## Documentation sets
92
+
93
+
Endpoints can be grouped together in different documentation sets. It is possible for instance to show some endpoints to third party developers and have full documentation for primary developers.
94
+
95
+
To assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
61
96
62
97
@app.route('/user/<int:id>')
63
-
@auto.doc("public")
98
+
@auto.doc('public')
64
99
def show_user(id):
65
100
66
101
to assign an endpoint to multiple groups, pass a list of group names as the _groups_ argument to _doc_:
67
102
68
103
@app.route('/user/<int:id>')
69
-
@auto.doc(groups=["public","private"])
104
+
@auto.doc(groups=['public','private'])
70
105
def show_user(id):
71
106
72
-
to generate the documentation for a specific group, pass the name of the group to the _generate_ or _html_ methods:
107
+
to generate the documentation for a specific group, pass the name of the group to the _html_ or _generate_ methods:
108
+
109
+
auto.html('public')
110
+
auto.html(groups=['public','private'])
111
+
auto.generate('public')
112
+
113
+
## Examples
114
+
115
+
Apps in the _examples_ directory are an api for a blog:
116
+
117
+
-_simple_ is a simple app
118
+
-_factory_ uses blueprints
119
+
120
+
Run with
121
+
122
+
python simple/blog.py
123
+
124
+
and connect to [/doc/public](http://127.0.0.1:5000/doc/public) and [/doc/private](http://127.0.0.1:5000/doc/private) to see public and private documentations.
0 commit comments