Skip to content

Commit 0407653

Browse files
committed
Send back some actual info about the endpoint.
This is roughly the same as what is available in the HTML template.
1 parent 4aa2975 commit 0407653

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

flask_selfdoc/autodoc.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,24 @@ def html(self, groups='all', template=None, **context):
199199
def json(self, groups='all'):
200200
"""Return a json object with documentation for all the routes specified
201201
by the doc() method.
202-
202+
203203
By specifiying the groups argument, only routes belonging to those groups
204204
will be returned.
205205
"""
206206
autodoc = self.generate(groups=groups)
207+
208+
def endpoint_info(doc):
209+
args = doc['args']
210+
if args == ['None']:
211+
args = []
212+
return {
213+
"args": [(arg, doc['defaults'][arg]) for arg in args],
214+
"docstring": doc['docstring'],
215+
"methods": sorted(list(doc['methods'])),
216+
"rule": doc['rule']
217+
}
207218
data = {
208219
'endpoints':
209-
[ "doc" for doc in autodoc ]
220+
[endpoint_info(doc) for doc in autodoc]
210221
}
211222
return jsonify(data)

tests/test_flask_get.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,13 @@ def json_docs():
3636

3737
data = json.loads(response.data)
3838
self.assertIn('endpoints', data)
39+
self.assertEqual(len(data['endpoints']), 1)
40+
41+
endpoint = data['endpoints'][0]
42+
expected = {
43+
"args": [],
44+
"docstring": "Returns a hello world message",
45+
"methods": ["GET", "HEAD", "OPTIONS"],
46+
"rule": "/"
47+
}
48+
self.assertEqual(endpoint, expected)

0 commit comments

Comments
 (0)