Skip to content

Commit d33b44e

Browse files
Example improved
1 parent 2fc3ee4 commit d33b44e

File tree

7 files changed

+97
-145
lines changed

7 files changed

+97
-145
lines changed

example/apidoc.json

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
{
2-
"name": "apidoc-example",
3-
"version": "0.3.0",
4-
"description": "apidoc example project",
5-
"title": "Custom apiDoc browser title",
6-
"url" : "https://api.github.com/v1",
7-
"sampleUrl": "https://api.github.com/v1",
8-
"header": {
9-
"title": "My own header title",
10-
"filename": "header.md"
11-
},
12-
"footer": {
13-
"title": "My own footer title",
14-
"filename": "footer.md"
15-
},
16-
"template": {
17-
"withCompare": true,
18-
"withGenerator": true
19-
}
2+
"name": "Flask REST API",
3+
"version": "1.0.0",
4+
"description": "A Flask REST API example",
5+
"title": "A Flask REST API example",
6+
"url" : "http://localhost:5000"
207
}

example/example.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

example/footer.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

example/header.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

example/main.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

example/readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
You need to generate the ApiDoc files before running it.
22

3-
apidoc -o static/apidoc
3+
python manage.py apidoc

example/views.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from flask import Flask
2+
from flask_apidoc import ApiDoc
3+
4+
app = Flask(__name__)
5+
doc = ApiDoc(app=app)
6+
7+
8+
@app.route('/users', methods=['POST'])
9+
def add_user():
10+
"""
11+
@api {post} /user Adds a new User
12+
@apiVersion 1.0.0
13+
@apiName add_user
14+
@apiGroup User
15+
16+
@apiParam {String} username The user's username.
17+
@apiParam {String} first_name The first name of the User.
18+
@apiParam {String} last_name the last name of the User.
19+
@apiParam {Object} profile The profile data
20+
@apiParam {Number} profile.age The user's age.
21+
@apiParam {String} profile.image The user's avatar-image.
22+
23+
@apiSuccess {Number} id The new user id.
24+
"""
25+
return
26+
27+
28+
@app.route('/users/<id>')
29+
def get_user(id):
30+
"""
31+
@api {get} /users/:id Gets an user
32+
@apiVersion 1.0.0
33+
@apiName get_user
34+
@apiGroup User
35+
36+
@apiDescription Gets an user for the given id.
37+
38+
@apiExample Example usage:
39+
curl -i http://localhost/users/4711
40+
41+
@apiParam {Number} id The user's i
42+
43+
@apiSuccess {Number} id The user's id.
44+
@apiSuccess {String} username The user's username.
45+
@apiSuccess {String} first_name The first name of the User.
46+
@apiSuccess {String} last_name The last name of the User.
47+
@apiSuccess {Object} profile The profile data
48+
@apiSuccess {Number} profile.age The user's age.
49+
@apiSuccess {String} profile.image The user's avatar-image.
50+
51+
@apiError UserNotFound The <code>id</code> of the User was not found.
52+
"""
53+
return
54+
55+
56+
@app.route('/users')
57+
def get_users():
58+
"""
59+
@api {get} /users/:id Gets all the users
60+
@apiVersion 1.0.0
61+
@apiName get_users
62+
@apiGroup User
63+
64+
@apiExample Example usage:
65+
curl -i http://localhost/users
66+
67+
@apiSuccess {Object} users The user data
68+
@apiSuccess {Number} users.id The user's id.
69+
@apiSuccess {String} users.username The user's username.
70+
@apiSuccess {String} users.first_name The first name of the User.
71+
@apiSuccess {String} users.last_name The last name of the User.
72+
@apiSuccess {Object} users.profile The profile data
73+
@apiSuccess {Number} users.profile.age The user's age.
74+
@apiSuccess {String} users.profile.image The user's avatar-image.
75+
"""
76+
return
77+
78+
79+
@app.route('/users/<id>', methods=['POST'])
80+
def update_user():
81+
"""
82+
@api {post} /users/:id Updates a user
83+
@apiVersion 1.0.0
84+
@apiName update_user
85+
@apiGroup User
86+
87+
@apiParam {Number} id The user's id
88+
@apiParam {String} first_name The first name of the User.
89+
@apiParam {String} last_name The last name of the User.
90+
"""
91+
return

0 commit comments

Comments
 (0)