Skip to content

Commit a162e7d

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 454028b commit a162e7d

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

flask_autodoc/autodoc.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,24 @@ def html(self, groups='all', template=None, **context):
196196
def json(self, groups='all'):
197197
"""Return a json object with documentation for all the routes specified
198198
by the doc() method.
199-
199+
200200
By specifiying the groups argument, only routes belonging to those groups
201201
will be returned.
202202
"""
203203
autodoc = self.generate(groups=groups)
204+
205+
def endpoint_info(doc):
206+
args = doc['args']
207+
if args == ['None']:
208+
args = []
209+
return {
210+
"args": [(arg, doc['defaults'][arg]) for arg in args],
211+
"docstring": doc['docstring'],
212+
"methods": sorted(list(doc['methods'])),
213+
"rule": doc['rule']
214+
}
204215
data = {
205216
'endpoints':
206-
[ "doc" for doc in autodoc ]
217+
[endpoint_info(doc) for doc in autodoc]
207218
}
208219
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)