Skip to content

Commit 5a2a88b

Browse files
author
Arnaud Coomans
committed
Updated README
1 parent c3e69c9 commit 5a2a88b

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

README.md

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
Flask-Autodoc
22
=============
33

4-
Flask Autodoc is a Flask extension that automatically creates documentation for your endpoints based on the routes,
5-
function arguments and docstring.
4+
Flask-Autodoc is a Flask extension that automatically creates documentation for your endpoints based on the routes, function arguments and docstrings.
65

76
[![Build](https://api.travis-ci.org/acoomans/flask-autodoc.png)](https://travis-ci.org/acoomans/flask-autodoc)
87
[![Pypi version](http://img.shields.io/pypi/v/flask-autodoc.svg)](https://pypi.python.org/pypi/Flask-Autodoc)
@@ -13,7 +12,7 @@ function arguments and docstring.
1312

1413
## Requirements
1514

16-
Flask Autodoc is compatible with Python versions 2 and 3; and depends only on Flask.
15+
Flask-Autodoc is compatible with Python versions 2 and 3; and it depends only on Flask.
1716

1817
## Install
1918

@@ -35,28 +34,28 @@ Start using Flask-Autodoc by importing it and initializing it:
3534
app = Flask(__name__)
3635
auto = Autodoc(app)
3736

38-
by default, Flask-Autodoc will only document the routes you explicitly tell him to with the _doc_ decorator,
39-
like this:
37+
by default, Flask-Autodoc will only document the routes explicitly decorated with _doc_:
4038

4139
@app.route('/user/<int:id>')
4240
@auto.doc()
4341
def show_user(id):
44-
"""This returns a user with a given id."""
4542
return user_from_database(id)
4643

47-
to generate the documentation from an endpoint, use the _html()_ method:
44+
to generate the documentation, use the _html()_ method:
4845

4946
@app.route('/documentation')
5047
def documentation():
5148
return auto.html()
5249

53-
if you to access the documentation without it being rendered in html:
50+
## Custom documentation
51+
52+
To access the documentation without rendering html:
5453

5554
@app.route('/documentation')
5655
def documentation():
5756
return auto.generate()
5857

59-
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:
6059

6160
- methods: the set of allowed methods (ie ['GET', 'POST'])
6261
- rule: relative url (ie '/user/<int:id>')
@@ -65,34 +64,55 @@ the documentation will then be returned as a list of rules, where each rule is a
6564
- args: function arguments
6665
- defaults: defaults values for the arguments
6766

68-
## 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+
81+
82+
_title_ and _author_ will be available in the template:
6983

70-
You may want to group endpoints together, to have different documentation sets. With this you can for example, only
71-
show some endpoints to third party developer and have full documentation for your own.
84+
<!-- templates/custom_documentation.html -->
85+
...
86+
{% if title is defined %}
87+
{{title}}
88+
{% endif %}
89+
...
7290

73-
to assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
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:
7496

7597
@app.route('/user/<int:id>')
76-
@auto.doc("public")
98+
@auto.doc('public')
7799
def show_user(id):
78100

79101
to assign an endpoint to multiple groups, pass a list of group names as the _groups_ argument to _doc_:
80102

81103
@app.route('/user/<int:id>')
82-
@auto.doc(groups=["public","private"])
104+
@auto.doc(groups=['public','private'])
83105
def show_user(id):
84106

85-
to generate the documentation for a specific group, pass the name of the group to the _generate_ or _html_ methods:
86-
87-
auto.generate("public")
88-
89-
or
90-
91-
auto.html("public")
107+
to generate the documentation for a specific group, pass the name of the group to the _html_ or _generate_ methods:
92108

109+
auto.html('public')
110+
auto.html(groups=['public','private'])
111+
auto.generate('public')
112+
93113
## Examples
94114

95-
Apps in the _examples_ directory mock a blog.
115+
Apps in the _examples_ directory are an api for a blog:
96116

97117
- _simple_ is a simple app
98118
- _factory_ uses blueprints

0 commit comments

Comments
 (0)